Categories

Arduino and DHT22 temperature and humidity sensor

The Arduino and sensor maintenance-temperature and humidity DHT22

 

Module DHT22 is used to measure temperature and humidity. The following example shows how to use its capabilities with Arduino.

In the example, we used the following elements:

Connect DHT22 to Arduino:

In order to read the values of temperature and humidity sensor connect the circuit with the Arduino in the following way:

 

Pin DHT22Pin Arduino
VCC5 V
DATE2
GNDGND

 

 

In the case of the sensor without the module, it is necessary to pull up the data line to Vcc via a resistor; in this case a 4.7 kOhm (as in the following figure).

 

 

 

The scheme of connection sensor DHT22 to Arduino Uno.

 

 

The scheme of connection sensor DHT22 (the version with the module) with the Arduino Uno.

Program for Arduino

At the beginning of the library you want to add to the environment of the Arduino (Sketch -> Include Library -> Add .ZIP Library...).

In the example, we used the following code:

 

#include  

dht DHT22; 

#define DHT22PIN 2 //assigning Arduino pin 2 as the reading from the sensor 

void setup() 
{ 
 Serial.begin(115200); //initialize serial monitor 
 Serial.println("DHT22 test Program"); 
 Serial.println(); 
} 

void loop() 
{ 
 int chk = DHT22.read(DHT22PIN); //check status of the sensor, and then a message appears on the serial monitor 

 Serial.print("sensor Status: "); 
 switch (chk) 
 { 
 case DHTLIB_OK: 
 Serial.print("Oct"); 
 break; 
 case DHTLIB_ERROR_CHECKSUM: 
 Serial.println("checksum Error"); 
 break; 
 case DHTLIB_ERROR_TIMEOUT: 
 Serial.println("End time out - no response"); 
 break; 
 default: 
 Serial.println("Unknown error"); 
 break; 
 } 
 Serial.print("Humidity (%): "); //output value humidity 
 Serial.print((float)DHT22.humidity, 2); 
 Serial.print("TT"); 
 Serial.print("Temperature (C): "); //display the temperature 
 Serial.println((float)DHT22.temperature, 2); 

 delay(1000); //delay between consecutive readings is 1 second. 
} 

The result of this program, we can see on the screenshot:

 

A screenshot of the serial monitor.