

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.3mA (measuring), 1.5mA (max) | 
| Temperature Range | -40°C to +80°C | 
| Temperature Accuracy | ±0.5°C | 
| Humidity Range | 0% to 100% RH | 
| Humidity Accuracy | ±2% RH | 
| Communication Interface | Single-wire digital | 
| Sampling Rate | 0.5 Hz (1 reading every 2 seconds) | 
| 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 (3.3V to 6V) | 
| 2 | DATA | Digital data output pin | 
| 3 | NC | Not connected (leave unconnected) | 
| 4 | GND | Ground pin | 
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 of how to use the DHT22 with an Arduino UNO. This code reads temperature and humidity data and displays it on the Serial Monitor.
#include "DHT.h"  // Include the DHT library
#define DHTPIN 2   // Define the pin connected to the DATA pin of DHT22
#define DHTTYPE DHT22  // Specify the sensor type (DHT22)
DHT dht(DHTPIN, DHTTYPE);  // Initialize the DHT sensor
void setup() {
  Serial.begin(9600);  // Start the Serial Monitor at 9600 baud
  Serial.println("DHT22 Sensor Initialization...");
  dht.begin();  // Start the DHT sensor
}
void loop() {
  delay(2000);  // Wait 2 seconds between readings (DHT22 sampling rate)
  float humidity = dht.readHumidity();  // Read humidity
  float temperature = dht.readTemperature();  // Read temperature in Celsius
  // Check if the readings are valid
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // Print the readings to the Serial Monitor
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");
}
No Data or Incorrect Readings
"Failed to read from DHT sensor!" Error
Inconsistent Readings
Slow Response Time
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 microcontrollers.
Q: What is the difference between the DHT11 and DHT22?
A: The DHT22 offers higher accuracy, a wider temperature and humidity range, and better resolution compared to the DHT11.
Q: How do I extend the cable length for the DHT22?
A: Use shielded cables and keep the length under 20 meters to minimize signal degradation.