

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 high precision and reliability, making it a popular choice for both hobbyists and professionals.








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 pin (3.3V to 6V). Connect to the positive rail of the power source. |
| 2 | DATA | Digital data output. Connect to a microcontroller GPIO pin with a pull-up resistor. |
| 3 | NC (Not Connected) | Not used. Leave this pin unconnected. |
| 4 | GND | Ground pin. Connect to the ground rail of the power source. |
Below is an example of how to connect and use the DHT22 with an Arduino UNO:
#include "DHT.h" // Include the DHT library
#define DHTPIN 2 // Pin connected to the DATA pin of the DHT22
#define DHTTYPE DHT22 // Specify the sensor type (DHT22)
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
dht.begin(); // Initialize the DHT sensor
Serial.println("DHT22 Sensor Initialized");
}
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 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("% Temperature: ");
Serial.print(temperature);
Serial.println("°C");
}
No Data or Incorrect Readings
Frequent Communication Errors
Sensor Not Responding
Slow Response Time
Q1: Can the DHT22 measure negative temperatures?
Yes, the DHT22 can measure temperatures as low as -40°C.
Q2: Can I use the DHT22 with a 3.3V microcontroller?
Yes, the DHT22 operates within a voltage range of 3.3V to 6V, making it compatible with 3.3V systems.
Q3: What is the difference between the DHT11 and DHT22?
The DHT22 offers higher accuracy and a wider range for both temperature and humidity measurements compared to the DHT11.
Q4: How do I know if my DHT22 is faulty?
If the sensor consistently returns NaN (Not a Number) for readings despite correct wiring and code, it may be faulty.