

The DHT22 is a digital temperature and humidity sensor that provides accurate readings of temperature in Celsius and humidity in percentage. It features a single-wire digital interface, making it easy to connect to microcontrollers like Arduino and Raspberry Pi. The DHT22 is widely used in weather stations, environmental monitoring systems, and home automation projects due to its reliability and ease of use.








The DHT22 sensor is designed for precision and ease of integration. Below are its key technical details:
| Parameter | Value |
|---|---|
| Supply Voltage | 3.3V to 6V |
| Operating Current | 0.5mA (measuring) |
| Standby Current | < 60µA |
| Temperature Range | -40°C to +80°C |
| Temperature Accuracy | ±0.5°C |
| Humidity Range | 0% to 100% RH |
| Humidity Accuracy | ±2% RH |
| Sampling Period | 2 seconds |
| Communication Protocol | Single-wire digital interface |
The DHT22 has four pins, as described in the table below:
| Pin Number | Name | Description |
|---|---|---|
| 1 | VCC | Power supply (3.3V to 6V) |
| 2 | DATA | Digital data output (connect to microcontroller) |
| 3 | NC | Not connected (leave unconnected) |
| 4 | GND | Ground (0V reference) |
Note: A pull-up resistor (typically 10kΩ) is required between the DATA pin and VCC for proper communication.
The DHT22 is simple to use in a circuit, thanks to its single-wire communication protocol. Below are the steps to integrate and use the DHT22 sensor:
Below is an example Arduino sketch to read temperature and humidity data from the DHT22 sensor using the popular DHT library.
#include <DHT.h>
// Define the pin where the DHT22 is connected
#define DHTPIN 2 // Connect DATA pin to digital pin 2
// Define the type of DHT sensor
#define DHTTYPE DHT22 // DHT22 (AM2302)
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Start serial communication
Serial.println("DHT22 Sensor Initialization...");
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // DHT22 requires a 2-second delay between readings
// Read temperature in Celsius
float temperature = dht.readTemperature();
// Read humidity in percentage
float humidity = dht.readHumidity();
// Check if readings are valid
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the readings to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
No Data or Incorrect Readings:
Sensor Fails to Initialize:
Readings are NaN (Not a Number):
Inconsistent Readings:
Q1: Can the DHT22 be used outdoors?
A1: Yes, but it should be placed in a protective enclosure to shield it from rain and direct sunlight.
Q2: What is the maximum cable length for the DHT22?
A2: The maximum cable length depends on the pull-up resistor value and the environment. Typically, it works reliably up to 20 meters with a 10kΩ resistor.
Q3: Can I use the DHT22 with a 3.3V microcontroller?
A3: Yes, the DHT22 operates within a voltage range of 3.3V to 6V, making it compatible with 3.3V systems.
Q4: How does the DHT22 differ from the DHT11?
A4: The DHT22 offers higher accuracy, a wider temperature range, and better humidity precision compared to the DHT11.
By following this documentation, you can effectively integrate and troubleshoot the DHT22 sensor in your projects.