Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...

The DHT22 sensor is used to measure the temperature and humidity. It is also known as the AM2302. This sensor is cheap and also has better accuracy. So in this tutorial, we are going to interface the DHT22 temperature and humidity sensor with Arduino and also we will display the data on the LCD.

Specifications of DHT22

The specifications of the temperature and humidity sensor DHT22 are as follows.

• Temperature range is from -40 to 125 degree Centigrade with accuracy of ±0.5 ͦ C.
• Humidity range is from 0 to 100% with accuracy of ± 2-5%.
• Sampling rate is 0.5 Hz.
• Operating Voltage is 3-5V.
• Maximum Current while measuring is 2.5mA.

Pin out of DHT22

The Pin out of the temperature and humidity sensor DHT22 is as follows.

• The first pin is the VCC pin which requires 3-5V to operate.
• The second pin is the data pin which will be connected to the digital pin of the Arduino.
• The third pin is not used.
• The last pin is the ground pin.

DHT22 Pin out

DHT22 Pin out

Working of Temperature and Humidity Sensor DHT22

DHT22 sensor consists of two components for measuring; Humidity sensing component and the NTC temperature sensor (or a thermistor). There is a IC on the back side which makes the readings to be able to read by the Arduino.

While measuring the humidity, the humidity sensor comes into play. The humidity sensor consists of two electrodes with moisture holding substrate between them. So when the humidity changes, the conductivity of substrate changes or you can say that the resistance between the electrodes changes. This change in resistance is then given to IC which makes it to read by the Arduino.

While measuring the temperature, the NTC temperature sensor or thermistor comes into play. The resistance of the thermistor changes with change in the temperature. These are negative temperature coefficient (NTC) which means that their resistance decreases with the increase in temperature.

 inside DHT22

Inside DHT22

Required Components for Tutorial

The components required for Temperature and humidity sensor DHT22 Arduino interfacing are as follows
• DHT22
• Arduino Uno
• LCD
• 10k resistor
• 10k potentiometer
• 220 ohm resistor
• Bread board
• Connecting wires

Circuit Diagram and Explanation

The connections of the DHT22 temperature and humidity sensor with Arduino are as follows.

DHT22 Arduino Uno
VCC 5v
Data pin Connect to pin 9 and also connect to 5V through 10K resistor
GND GND
Temperature and humidity sensor dht22 arduino circuit diagram

DHT22 interfacing with Arduino

Code

Before uploading the code to the Arduino, you will have to download the DHT22 library.

Download the DHT22 Library from here.

#include "DHT.h" //including the dht22 library
#define DHTPIN 8 //Declaring pin 9 of arduino for the dht22
#define DHTTYPE DHT22 //Defining which type of dht22 we are using (DHT22 or DHT11)
DHT dht(DHTPIN, DHTTYPE); //Declaring a variable named dht
void setup() { //Data written in it will only run once
Serial.begin(9600); //setting the baud rate at 9600
dht.begin(); //This command will start to receive the values from dht22
}
void loop() { //Data written in it will run again and again
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
float fah = dht.readTemperature(true);
if (isnan(hum) || isnan(temp) || isnan(fah)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
}
 float heat_index = dht.computeHeatIndex(fah, hum);
 float heat_indexC = dht.convertFtoC(heat_index);
Serial.print("Humidity: "); //Writing the humidity on the serial monitor
Serial.print(hum); //Writing the humidity value stored in hum on the Serial monitor
Serial.print(" %\t");
Serial.print("Temperature: "); //Writing the temperature on the serial monitor
Serial.print(temp); //Writing the value of temperature on the serial monitor
Serial.print(" *C ");
Serial.print(fah);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(heat_indexC);
Serial.print(" *C ");
Serial.print(heat_index);
Serial.println(" *F ");
delay(2000); //Giving a delay of 2 seconds
}

To Display DHT22 data on LCD

If you want to display the temperature and humidity on the LCD, then connect the LCD to the Arduino as shown in the figure below. If you are want to read more about connecting the LCD with the Arduino then follow this tutorial Interfacing LCD with Arduino.

DHT22 16X2 LCD Arduino 
VCC 5v
Data pin Connect to pin 9 and also connect to 5V through 10K resistor
GND GND
VSS GND
VDD 5V
V0 Middle of 10K potentiometer
Connect the two ends of potentiometer to GND and 5V
RS Pin 7
R/W GND
E Pin 6
D4 Pin 5
D5 Pin 4
D6 Pin 3
D7 Pin 2
A To 5V through 220 ohm resistor
K GND
dht22 arduino lcd circuit diagram

Circuit diagram for displaying data on lcd

Code to display data on LCD Display

Before uploading this code, you will have to download the DHT22 and liquid crystal library. The DHT22 library is given before the above code and download the LCD library from here.

#include "DHT.h" //including the dht22 library
#include "LiquidCrystal.h"
#define DHTPIN 6 //Declaring pin 9 of arduino for the dht22
#define DHTTYPE DHT22 //Defining which type of dht22 we are using (DHT22 or DHT11)
DHT dht(DHTPIN, DHTTYPE); //Declaring a variable named dht
LiquidCrystal lcd(12,11,10,9,8,7); // Initializing the LCD pins.
void setup() { //Data written in it will only run once
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
dht.begin(); //This command will start to receive the values from dht22
}
void loop() { //Data written in it will run again and again
lcd.clear();
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
// Check if any reads failed and exit early (to try again).
if (isnan(hum) || isnan(temp)) {
lcd.print("Failed to read");
delay(1000);
return;
}
lcd.setCursor(0,0); //Setting the cursor at the start of the LCD
lcd.print("Temp.: "); //Writing the temperature on the LCD
lcd.print(temp); //Writing the value of temperature on the LCD
lcd.print(" C");
lcd.setCursor(0,1); //setting the cursor at next line
lcd.print("Humi.: "); //Writing the humidity on the LCD display
lcd.print(hum); //Writing the humidity value stored in hum on the LCD display
lcd.print(" %");
delay(2000);
}

Videos


If you have any questions, feel free to ask us in the comment section.

JOIN OUR NEWSLETTER
We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
We hate spam. Your email address will not be sold or shared with anyone else.

Leave a Reply

Your email address will not be published.

Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...
Skip to toolbar