DHT22 Temperature Humidity Sensor Features
The DHT22 Temperature Humidity Sensor is a great choice for measuring ambient temperature and humidity. This sensor consists of a capacitive humidity sensor and a heat resistor. The DHT22 sensor has a wide range of temperature and humidity measurement. It can measure temperature in range of -40 to +125 degrees Celsius with 0.5 degrees Celsius accuracy. Humidity is measured in range of 0 to 100% with 2.5% accuracy. This sensor transmits data through a single digital pin, which makes it easy to communicate with various microcontrollers. The sampling frequency is also 0.5Hz. This means that it updates the temperature and humidity data every two seconds.
DHT22 Temperature Humidity Sensor Pinout
This Module has 4 pins:
- VCC: Module power supply – 5V
- DATA: Data pin
- NC: Not connected
- GND: Ground
You can see the pinout of this module in the image below.
Required Materials
Hardware Components
Software Apps
Interfacing DHT22 Temperature Humidity Sensor with Arduino
Step 1: Circuit
The following circuit show how you should connect Arduino to DHT22 sensor. Connect wires accordingly.
Step 2: Library
Go to Library manager and install DHT sensor library.
Tip
If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library
Step 3: Code
Upload the following code to Arduino. After that, open Serial Monitor.
/*
modified on Dec 28, 2020
Modified by MehranMaleki from Arduino Examples
Home
*/
//Libraries
#include <DHT.h>;
//Constants
#define DHTPIN 2 //what pin we're connected to
#define DHTTYPE DHT22 //DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //Initialize DHT sensor for normal 16mhz Arduino
//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.
}
In this code, the humidity and temperature data are received from the sensor every 2 seconds and displayed on the Serial Monitor.
The output is as follows: