

The DHT22 is a digital temperature and humidity sensor that provides accurate readings of temperature in Celsius and humidity in percentage. It is a highly reliable and cost-effective solution for environmental monitoring. The sensor uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on a single data pin, making it easy to interface with microcontrollers.








The DHT22 offers precise measurements and is designed for long-term stability. Below are its key technical details:
| Parameter | Value |
|---|---|
| Supply Voltage | 3.3V to 6V |
| Operating Current | 0.3mA (measuring), 60µA (standby) |
| 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 signal |
The DHT22 has four pins, but only three are typically used in most applications. Below is the pinout:
| Pin Number | Name | Description |
|---|---|---|
| 1 | VCC | Power supply (3.3V to 6V) |
| 2 | DATA | Digital data output (requires a pull-up resistor) |
| 3 | NC (Not Connected) | No connection (leave unconnected) |
| 4 | GND | Ground |
Below is an example of how to use the DHT22 with an Arduino UNO:
#include "DHT.h" // Include the DHT library
#define DHTPIN 2 // Pin connected to the DATA pin of DHT22
#define DHTTYPE DHT22 // Define the sensor type (DHT22)
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
void setup() {
Serial.begin(9600); // Start serial communication
Serial.println("DHT22 Sensor Test");
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait 2 seconds between readings
float humidity = dht.readHumidity(); // Read humidity
float temperature = dht.readTemperature(); // Read temperature in Celsius
// Check if any readings failed and print an error message
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}
No Data Output:
Incorrect or NaN Readings:
Intermittent Communication Failures:
Q: Can the DHT22 measure negative temperatures?
A: Yes, the DHT22 can measure temperatures as low as -40°C.
Q: What is the maximum cable length for the DHT22?
A: The recommended maximum cable length is about 20 meters, but this depends on the quality of the cable and the pull-up resistor value.
Q: Can I use the DHT22 with a 3.3V microcontroller?
A: Yes, the DHT22 operates within a voltage range of 3.3V to 6V, making it compatible with 3.3V systems.
Q: How do I protect the sensor in high-humidity environments?
A: Use a protective enclosure or conformal coating to shield the sensor from condensation and water exposure.