

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 HVAC control applications 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.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 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.
Below is an example code to interface the DHT22 with an Arduino UNO:
#include "DHT.h"
// Define the DHT sensor type and pin
#define DHTTYPE DHT22 // DHT22 sensor
#define DHTPIN 2 // Connect DATA pin to digital pin 2
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Start serial communication
dht.begin(); // Initialize the DHT sensor
Serial.println("DHT22 Sensor Initialized");
}
void loop() {
delay(2000); // Wait 2 seconds between readings
// Read temperature and humidity
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if readings are valid
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");
}
Note: Ensure the DHT sensor library is installed in your Arduino IDE before uploading the code.
No Data or Incorrect Readings:
"Failed to Read from DHT Sensor" Error:
Slow or Inconsistent Readings:
Q: Can the DHT22 measure negative temperatures?
A: Yes, the DHT22 can measure temperatures as low as -40°C.
Q: Can I use the DHT22 with a 3.3V microcontroller?
A: Yes, the DHT22 operates with a supply voltage range of 3.3V to 6V, making it compatible with 3.3V systems.
Q: How long is the maximum cable length for the DHT22?
A: The maximum cable length depends on the pull-up resistor value and environmental noise. Typically, it works reliably up to 20 meters with a 10kΩ resistor.
Q: Is the DHT22 waterproof?
A: No, the DHT22 is not waterproof. For outdoor or high-humidity applications, use a protective enclosure.