Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create a Humidity Sensor System with Arduino

Humidity sensors are essential components in many applications, from weather monitoring systems to smart home devices. In the Arduino environment, you can easily integrate a humidity sensor to measure the moisture in the air. This article will guide you through setting up a humidity sensor using Arduino, specifically utilizing the DHT11 or DHT22 sensor, which are commonly used for such projects.

Examples:

Components Required:

  1. Arduino Uno (or any compatible Arduino board)
  2. DHT11 or DHT22 Humidity and Temperature Sensor
  3. Jumper wires
  4. Breadboard
  5. Resistor (4.7k ohm for DHT22, not needed for DHT11)

Wiring Diagram:

  • Connect the VCC pin of the DHT sensor to the 5V pin on the Arduino.
  • Connect the GND pin of the DHT sensor to the GND pin on the Arduino.
  • Connect the data pin of the DHT sensor to a digital pin on the Arduino (e.g., pin 2).
  • If using DHT22, place a 4.7k ohm resistor between the VCC and data pin.

Arduino Code: To read data from the DHT sensor, you will need to install the DHT sensor library. You can do this via the Arduino IDE by going to Sketch -> Include Library -> Manage Libraries, and then searching for "DHT sensor library" by Adafruit.

#include <DHT.h>

#define DHTPIN 2     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11   // DHT 11 (change to DHT22 if using DHT22)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  delay(2000);  // Wait a few seconds between measurements

  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" *C");
}

Explanation:

  • The DHT library is used to interface with the DHT sensor.
  • The dht.readHumidity() and dht.readTemperature() functions are used to read the humidity and temperature values from the sensor.
  • The results are printed to the Serial Monitor, which can be accessed via the Arduino IDE by going to Tools -> Serial Monitor.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.