The start and the answer
One wire, two devices, and no clock to keep them together. Your board asks by holding the line down for milliseconds; the sensor answers by holding it down for microseconds. The length of that first pulse is the one thing that differs between the DHT11 and the DHT22 — 18 ms against 1 ms.
Watch the wire change hands
Press the button and follow the colour. Green is your board driving the line; orange is the sensor.
Idle. Nobody is driving the wire; the 10 kΩ resistor on the board holds it high on its own.
Four things happen, always in this order.
Your board pulls the line down and holds it. That is the entire request — there is no command byte, no register address, nothing to say what you want. Holding the wire down long enough is the question, and the answer is always the same forty bits.
Your board lets go. It switches the pin back to an input, and for twenty to forty microseconds neither device is driving the wire; the 10 kΩ resistor on the board holds it high on its own.
The sensor pulls it down for 80 µs, then lets it up for 80 µs. This is the
"I am here". If it never comes, the library gives up after a millisecond and
returns nan, which is the only error this sensor is capable of producing.
Then the bits start, and the sensor owns the wire until it has sent all forty.
The one number that differs
| DHT11 | DHT22 | |
|---|---|---|
| Datasheet asks for | at least 18 ms | at least 1 ms |
| The library sends | 20 ms | 1.1 ms |
| Everything after | identical | identical |
Both sensors sleep between readings and both wake on the line going down; the DHT11 just needs longer to notice. Everything after the start pulse — the 80 µs answer, the 50 µs that opens each bit, the whole forty-bit frame — is the same on both parts.
Which is why declaring the wrong type usually shows up here rather than in the
data. A DHT11 asked to wake in 1.1 ms often does not wake, so the symptom is a
sensor that returns nan on a perfectly good set of wires.
What it costs the sketch
The start pulse is not clever waiting. delay(20) is twenty milliseconds during
which the sketch does nothing at all, and the forty bits that follow are timed
by counting loop iterations, so the library switches interrupts off for the
duration.
That makes one DHT11 reading about 24 ms of stopped program and one DHT22 reading about 6 ms. For a room monitor it is invisible. It stops being invisible when it is inside something that also has to answer a network, which is where both sensors side by side puts real numbers on it.
Why this is not 1-Wire
The name is confusing and the resemblance is superficial. Dallas 1-Wire gives every device a unique 64-bit serial number so that a dozen of them can share one line; this protocol has no addresses at all, no device selection, and no way to ask a specific sensor anything.
So there is nothing to scan for, nothing to enumerate, and no bus to hang a second sensor off. Every DHT gets a pin of its own.
When it does not work
It is waking up. Both sensors sit in a low-power state until the line is held down, and the DHT11's datasheet asks for at least 18 ms to be sure it notices; the DHT22's asks for 1 ms. Adafruit's library sends 20 ms and 1.1 ms respectively, which is why a DHT11 declared as a DHT22 usually never answers at all.
Check the sensor type in the sketch before anything else. A DHT11 given a 1.1 ms start pulse frequently misses it, so the symptom is a sensor that works intermittently or not at all while every wire is correct.
No. There is no addressing in this protocol and no way to tell two sensors apart, so two DHTs on one wire both answer at once and neither reading survives. One sensor, one pin — see both sensors side by side.
The library handles it: it switches the pin between OUTPUT LOW and INPUT for you, which is open drain done by hand. What matters is that your sketch never drives the line high — the resistor does that — because a pin driving high while the sensor is pulling low is a short through both.
Five bytes, and why the same five mean two different readings.
Forty bits and a checksum →Edit this page — content/books/dht22/the-start-and-the-answer.mdx
Questions about this product
See what other owners have asked, and read their solutions.
This page covers several products. Choose yours to see the right discussions.
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.