Quick summary
The DHT11 is fine for a simple first test indoors, when modest accuracy is enough. The DHT22, also known as AM2302 in some versions, offers a wider range and better temperature and humidity specifications, although it is still a relatively slow sensor.
If all you want to know is which one to buy for a home project, I would choose the DHT22 unless the lowest price and the simplicity are the absolute priority. If you need a fast response, professional-grade measurement or a sensor for a damp environment, it’s worth looking at other sensors.
DHT11 vs DHT22
| DHT11 | DHT22 | |
|---|---|---|
| Temperature | 0–50 °C | −40–80 °C |
| Humidity | 20–80 % | 0–100 % |
| Typical accuracy | ±2 °C / ±5 % RH | ±0.5 °C / ±2–5 % RH |
| Resolution | 1 °C / 1 % RH | 0.1 °C / 0.1 % RH |
| Recommended max read rate | 1 reading per second | 1 reading every 2 seconds |
| Communication | Own digital protocol | Own digital protocol |
These are indicative values for the sensor families. Before publishing a buying comparison, check the manufacturer’s datasheet and the quality of the specific module: compatible boards exist with different resistors, connectors and silkscreen labels.
Which one should you pick?
Choose the DHT11 when:
- You are learning the protocol and already have one available.
- You only need a rough indication of temperature and humidity indoors.
- Speed, resolution and range don’t matter for the result.
Choose the DHT22 when:
- You want a finer reading to observe a room or a DIY project.
- You need to measure temperatures outside the DHT11’s usual range.
- You are going to keep history and want small changes to be more useful.
Neither is the best choice for everything. To measure only temperature over a long cable, a DS18B20 may fit better. For temperature, humidity and pressure over an I2C bus, a BME280 offers a different approach. The decision depends on the environment, the distance, the speed and the maintenance, not just on the price.
Wiring with the ESP32
Both sensors come in two common formats: the bare four-pin sensor and a three-pin module with the pull-up resistor already fitted. On the four-pin version the unconnected pin is normally left alone. Always check the silkscreen on your module, because the pin order shouldn’t be taken for granted.
For a typical test with the ESP32:
- Connect VCC to a supply compatible with the sensor. With the ESP32 it is usually better to work at 3.3 V if the module allows it.
- Connect GND to the board’s ground.
- Connect DATA to a free GPIO, for example GPIO4, as long as it doesn’t interfere with booting or with another peripheral.
- If you use the bare sensor, add the pull-up resistor specified by its documentation between VCC and DATA. Many modules already include it.
Never connect a 5 V signal straight to an ESP32 GPIO. The supply voltage the module accepts doesn’t mean its signals tolerate 5 V.
Reading with ESPHome
ESPHome includes the dht component. This example shows a DHT22 reading on
GPIO4; for a DHT11 you change the model. The 30-second interval avoids querying
too often and lets the sensor settle.
sensor:
- platform: dht
pin: GPIO4
model: DHT22
temperature:
name: "Living room temperature"
humidity:
name: "Living room humidity"
update_interval: 30s
The DHT22 name must match the installed sensor. If the device compiles but
the values are impossible, check the model, the pin, the power and the ground
first. Then check the pull-up resistor and the cable length. Keep your WiFi
credentials in ESPHome secrets, not in an article or a public repository.
How to interpret erratic readings
A NaN, frozen or clearly impossible reading doesn’t by itself prove the
sensor is broken. Work through the problem in this order:
- Power and ground: measure the voltage at the module itself, not only at the supply.
- Pin and model: the declared GPIO must be the one you wired, and the model must match the sensor.
- Pull-up: the bare sensor needs the right resistor; a module usually includes it, but you have to check.
- Interval: don’t request readings faster than the sensor allows.
- Wiring: shorten the cable for the test and avoid running it next to loads or cables that introduce noise.
- Condensation: neither sensor is designed to sit exposed to water or constant condensation without proper protection.
To compare two sensors, place them together over a stable period and don’t expect them to match to the last decimal. What matters is whether they respond consistently to known changes, such as ventilating the room or bringing a source of humidity closer without wetting the sensor.
Conclusion
The DHT11 is valid for learning and for simple indications. The DHT22 is the more balanced option if you want more range and resolution without moving to a sensor from another family. In both cases, the wiring, the reading interval and the power supply matter as much as the specification table.
If you still haven’t chosen the board, check ESP32: what it is, what it’s for and how to get started. To see how this setup fits into a complete automation, go back to the home automation for beginners guide.
External sources
- Adafruit: DHT11, DHT22 and AM2302 — datasheet, wiring, pull-up, examples, limitations.
- DHT22: datasheet — range, accuracy, resolution, response, power, wiring, pull-up.
- DHT11: datasheet — range, accuracy, resolution, response, power, wiring, pull-up.
- AM2302: datasheet — DHT22 variant, encapsulated, specifications.
- ESPHome: DHT sensor — platform, model, pin, update, calibration, pull-up, filtering.
- ESPHome: temperature sensor — platforms, units, filters, calibration, offset, update.
- Espressif: ESP32 documentation — pins, memory, WiFi, Bluetooth, security, ADC, DHT protocol.
- Adafruit: DHT11, DHT22 and AM2302 — datasheet, wiring, pull-up, examples, limitations.
- Adafruit: DHT sensor library — C++ library, timing, checksum, timeout, examples.
- Adafruit: DHT sensor tutorial — wiring, pull-up, model, interval, limitations, examples.