The DHT11 and DHT22 temperature and humidity sensors are popular sensors used in components for many projects, including weather stations and smart home automation. While they share some similarities, there are significant differences that make each suitable for specific applications. In this blog, we'll explore the features of both sensors and help you decide which one is best for your project.
What Are DHT Sensors?
DHT sensors are digital temperature and humidity sensors designed to measure environmental conditions. They have built-in capacitive humidity sensors and thermistors to measure humidity and temperature, respectively, and they output these readings as digital signals.
DHT11 Sensor: Basic and Cost-Effective
The DHT11 temperature and humidity sensor is known for its simplicity and low cost. Here are some of its key features:
- Temperature Range: 0°C to 50°C (32°F to 122°F)
- Temperature Accuracy: ±2°C
- Humidity Range: 20% to 80%
- Humidity Accuracy: ±5%
- Sampling Rate: 1 Hz (one reading per second)
- Applications: Simple weather stations or indoor environmental monitoring

DHT22 Sensor: Enhanced Accuracy and Range
The DHT22 temperature and humidity sensor, based on the AM2302, is a more advanced sensor with improved accuracy and a broader range of measurement:
- Temperature Range: -40°C to 80°C (-40°F to 176°F)
- Temperature Accuracy: ±0.5°C
- Humidity Range: 0% to 100%
- Humidity Accuracy: ±2%
- Sampling Rate: 0.5 Hz (one reading every two seconds)
- Applications: Sophisticated weather stations or environmental control systems

Key Differences Between DHT11 and DHT22
- Temperature Range and Accuracy: DHT11 is limited and less accurate; DHT22 is wider and more precise
- Humidity Range and Accuracy: DHT11: 20–80%, ±5%; DHT22: 0–100%, ±2%
- Sampling Rate: DHT11: 1 reading/sec; DHT22: 1 reading/2 sec
- Cost: DHT11 is cheaper; DHT22 costs more due to improved specs
Applications
- Use DHT11 for simple projects or tight budgets
- Use DHT22 for precise measurements or wider range requirements
Sensor Comparison Table
For a full comparison including BME280 and DS18B20 sensors, see our Arduino Digital Temperature Sensor Comparison Guide.
| Spec / Sensor | DHT11 | DHT22 (AM2302) |
|---|---|---|
| Interface / Communication | Single-wire digital (DHT protocol) | Single-wire digital (DHT protocol) |
| Features | Humidity sensing | Humidity sensing |
| Library / Compatibility | Arduino, Raspberry Pi | Arduino, Raspberry Pi |
| Operating Voltage | 3–5.5V | 3.3–5.5V |
| Temperature Accuracy | ±2°C | ±0.5°C |
| Humidity Accuracy | ±5% | ±2% |
| Precision / Resolution | 1°C | 0.1°C |
| Measurement Range | 0–50°C | -40–80°C |
| Response Time | 6–15s | ~2s |
| Current Draw | ~0.5mA | ~1mA |
| Sensor Type | Temp & humidity | Temp & humidity |
| Physical Form / Durability | Plastic, small | Plastic, small |
| Multiple Sensors on Bus | No | No |
| Cost / Availability | Low | Low |
| Environmental Limitations | Indoor use | Outdoor ok, avoid condensation |
Example Arduino Code for DHT11 and DHT22
This example demonstrates how to read temperature data from DHT11 and DHT22 sensors using an Arduino. The temperature values are printed to the Serial Monitor every 10 seconds. We're using an Arduino Uno, but this example can work on any C++ compatible microcontroller. The positive pin (+) connects to a power supply between 3V and 5.5V and the ground pin (-) to the GND pin on the microcontroller. We're using Digital pin 11 for the DHT11 and pin 12 for the DHT22. The pin assignment can be changed in the code.
Wiring Diagram

Make sure the Serial Monitor baud rate is set to 9600.
/* * Ethan Zaitchik * Full guide: * https://zaitronics.com.au/blogs/guides/dht11-vs-dht22-sensors
*/ #include "DHT.h" // Pin definitions const int DHT11_PIN = 11; const int DHT22_PIN = 12; // Create DHT sensor objects DHT dht11(DHT11_PIN, DHT11); DHT dht22(DHT22_PIN, DHT22); void setup() { Serial.begin(9600); // Initialize sensors dht11.begin(); delay(2000); // Required delay between DHT sensor initializations dht22.begin(); } void loop() { // Read DHT11 temperature float tempDHT11 = dht11.readTemperature(); if (isnan(tempDHT11)) { Serial.println("Failed to read from DHT11 sensor"); } else { Serial.print("DHT11 Temperature (°C): "); Serial.println(tempDHT11); } // Read DHT22 temperature float tempDHT22 = dht22.readTemperature(); if (isnan(tempDHT22)) { Serial.println("Failed to read from DHT22 sensor"); } else { Serial.print("DHT22 Temperature (°C): "); Serial.println(tempDHT22); } Serial.println(); delay(10000); // Wait 10 seconds }
Expected Output
The Serial Monitor should display output similar to the following (values will vary):
DHT11 Temperature (°C): 23.00 DHT22 Temperature (°C): 22.80 DHT11 Temperature (°C): 23.10 DHT22 Temperature (°C): 22.90 DHT11 Temperature (°C): 23.00 DHT22 Temperature (°C): 22.85
Troubleshooting
- NaN or failed readings: Ensure the correct sensor type (DHT11 or DHT22) is selected in the code.
- Wiring issues: Check that VCC, GND, and DATA pins are correctly connected.
- Missing pull-up resistor: Use a 4.7k–10kΩ resistor between VCC and DATA if your module does not include one.
- Incorrect pin number: Confirm the data pin number matches your wiring.
- Reading too frequently: DHT sensors require at least a 2-second interval between readings.