part · Level 8 · Environment · input
How the DHT11 sensor works
Temperature + humidity sensor (DHT11) — Reads the room: how warm, how humid.
What it is
The DHT11 is a blue plastic block with a grille on the front and three or four pins. Inside are a humidity sensor (a film whose electrical properties change with moisture), a thermistor, and a small chip that reads both and sends the results as numbers. Where a bare thermistor gives you a resistance you must convert, the DHT11 gives you "23 °C, 45 %" ready-made.
It is slow, it is not very precise, and it costs almost nothing — which makes it the perfect first environment sensor. Your microcontroller asks; about a quarter of a second later the sensor replies with a 40-bit message on its single data wire.
The four-pin version: VCC (+), Data, no-connect, GND (−). Three-pin modules on a little board already include the resistor you would otherwise add.
How it works
The data line is shared both ways. Your code pulls it low for at least 18 ms to say "measure"; the sensor then sends 40 bits — 8 for humidity whole part, 8 for its fraction, 8 for temperature whole, 8 fraction, and 8 checksum — by the length of each high pulse (about 26 µs = 0, 70 µs = 1). A library does this timing for you; the reason to know it is that the line needs a 10 kΩ pull-up resistor to + so it rests high when nobody is driving it.
Accuracy: ±2 °C and ±5 % relative humidity. Resolution is 1 °C and 1 % — it will not show 22.5. Range: 0–50 °C and 20–90 % RH. Outside that it clips or returns garbage, so it is a room sensor, not a freezer or a sauna sensor.
Read it at most once every 2 seconds; faster and it returns the previous reading or a checksum error. Power is 3–5.5 V and the current is tiny (about 2.5 mA while measuring), so a 3×AA pack or the microcontroller's 5 V pin is fine.
The numbers
| Temperature | 0–50 °C, ±2 °C — 1 °C steps |
|---|---|
| Humidity | 20–90 % RH, ±5 % — 1 % steps |
| Supply | 3–5.5 V — ≈ 2.5 mA while measuring |
| Sample rate | once per 2 s max — faster reads fail |
| Data line | 1 wire + 10 kΩ pull-up — modules include it |
Mistakes everyone makes
- Reads fail or NaN. Reading faster than every 2 s, or no pull-up on the data line. Fix: delay(2000) and 10 kΩ to +.
- Off by a couple of degrees. That is the spec, not a fault. Fix: compare with a thermometer and subtract the offset in code if you care.
- Wrong pin order. The four-pin part is VCC, Data, NC, GND left to right with the grille facing you. Fix: check before power.
- Breathing on it and expecting instant change. Humidity response takes several seconds. Fix: wait.
Questions people ask
- How accurate is a DHT11?
- About ±2 °C and ±5 % relative humidity, in whole-number steps. The DHT22 is the same idea with ±0.5 °C and decimals, for a bit more money.
- Why does my DHT11 return NaN or a checksum error?
- Usually the sensor was read again within 2 seconds, the data pin has no pull-up resistor, or the wiring is loose. Space reads 2 seconds apart and add 10 kΩ from Data to +.
- What is the difference between a DHT11 and a thermistor?
- A thermistor is a resistor that changes with temperature — you measure it with a voltage divider and convert. A DHT11 contains a thermistor plus a chip that does the conversion and adds humidity, sending numbers over one wire.
Projects that use this part
No project uses it yet — it arrives at Level 8, and the projects for that level are still being written and verified.
verified against: Adafruit — DHT11, DHT22 and AM2302 Sensors · Arduino docs — DHT sensor library