

The DHT22 is a digital temperature and humidity sensor that provides accurate readings of temperature in Celsius and humidity in percentage. It is widely used in applications requiring environmental monitoring, such as weather stations, HVAC systems, greenhouses, and IoT projects. The DHT22 is known for its reliability, ease of use, and ability to provide precise measurements over a wide range of conditions.








The DHT22 sensor has the following key technical specifications:
| 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 Rate | 0.5 Hz (1 reading every 2 seconds) |
| Communication Protocol | Single-wire digital signal |
| Dimensions | 15.1mm x 25mm x 7.7mm |
The DHT22 has four pins, as described in the table below:
| Pin Number | Name | Description |
|---|---|---|
| 1 | VCC | Power supply pin. Connect to 3.3V or 5V. |
| 2 | DATA | Digital data output. Connect to a microcontroller GPIO pin with a pull-up resistor. |
| 3 | NC (Not Connected) | No connection. Leave this pin unconnected. |
| 4 | GND | Ground pin. Connect to the ground of the circuit. |
Below is an example of how to use the DHT22 with an Arduino UNO. This code uses the popular DHT library.
#include "DHT.h"
// Define the pin where the DHT22 is connected
#define DHTPIN 2 // Connect DATA pin of DHT22 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 at 9600 baud
Serial.println("DHT22 Sensor Initialization");
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait 2 seconds between readings
// Read temperature in Celsius
float temperature = dht.readTemperature();
// Read humidity in percentage
float humidity = dht.readHumidity();
// Check if the 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:
Frequent Communication Errors:
Slow Response Time:
Q: Can I use the DHT22 with a 3.3V microcontroller?
A: Yes, the DHT22 works with both 3.3V and 5V microcontrollers. Ensure the pull-up resistor is connected to the same voltage level as the microcontroller.
Q: What is the maximum cable length for the DHT22?
A: The recommended maximum cable length is 20cm. For longer distances, use shielded cables and reduce the pull-up resistor value to 4.7kΩ.
Q: How do I protect the sensor in outdoor environments?
A: Use a weatherproof enclosure with ventilation to protect the sensor from rain and direct sunlight while allowing air circulation.
Q: Why does the sensor occasionally return NaN values?
A: This can happen due to timing issues or electrical noise. Double-check your wiring, ensure proper pull-up resistance, and avoid polling the sensor too frequently.