DHT sensors/Two sensors, one wire/01. Two numbers, one pin
Two sensors, one wire · 01 of 12

Two numbers, one pin

Behind the plastic grille are a humidity element, a temperature element and a small microcontroller that reads both for you. That last part is why one ordinary digital pin is enough, and why the number arrives already calibrated and already rounded.

What is behind the grille

Hold either board up and the part on top is a cage with square vents in it. Air gets in; the two things measuring it do not get touched.

Inside the cage
DHT22 · TK39
Which sensor
Temperature
-40 to 80 °C
Give or take
±0.5 °C
Humidity
0–100 % RH
Give or take
±2 %
You are not reading a sensor, you are asking a chip. The measuring, the calibration and the arithmetic all happen inside the cage before anything reaches your board, which is why one ordinary digital pin is enough and why there is no resistor to choose and no analog reading to convert. It is also why the number arrives in fixed steps: the DHT22 rounds to 0.1 °C · 0.1 % and there is nothing you can do about it from outside.

The humidity element is a capacitor with a plastic film between its plates. The film soaks up water from the air and lets it go again, and its capacitance rises and falls with how much it is holding. The temperature element is a resistor whose resistance changes as it warms.

Neither of those is a number yet. Both are physical quantities that would need a reference, an amplifier and a calibration table to turn into anything you could print — which is the third thing in the cage.

Why the third part matters

The little microcontroller does all of that before anything reaches your board. It measures both elements, applies the calibration burned into it at the factory, and hands out a fixed pattern of forty bits.

That is the whole reason this sensor is a beginner's part. There is no analog wiring to get wrong, no reference voltage to supply, no resistor to work out, and nothing to calibrate. Three wires, one of which carries the answer.

It also decides what you cannot do. You do not get the raw capacitance, you cannot ask it to average, and you cannot ask for more precision than it offers: the DHT11 rounds to whole degrees and whole per cent, the DHT22 to tenths of both, and there is no setting anywhere that changes either.

What "humidity" means here

Both sensors report relative humidity — how close the air is to holding as much water as it can at its current temperature. It is a percentage of a limit that itself moves with temperature, which is why the same air can read 40 % in a warm room and 80 % in a cold one without a drop of water having gone anywhere.

That makes relative humidity hard to compare between rooms, and it is why a comfort reading turns it into a dew point before putting it on a display.

What comes out

One call to the library gives you two floating-point numbers. What varies between the two sensors in the box is how much of each number is real:

DHT11DHT22
Temperaturewhole degrees, ±2 °Ctenths, ±0.5 °C
Humiditywhole per cent, ±5 %tenths, ±2 %
A new reading every1 second2 seconds

Neither is fast. Both take a handful of milliseconds to answer and then refuse to answer again for a second or two, which is far more often than a room changes and is discussed properly in how often you may ask.

When it does not work

Can I read it with an analog pin instead?

No, and there is nothing analog to read. The elements inside are wired to the sensor's own microcontroller, not to the header. What comes out of the DATA pin is a digital pattern, so an analogRead on it returns whatever the line happened to be sitting at.

Do I need to calibrate it?

No. Each part is calibrated at the factory and the coefficients are burned into memory inside the cage, which the sensor applies before it sends anything. You cannot adjust them, and a sensor reading consistently wrong is a placement problem rather than a calibration one.

Why does the temperature only move in whole degrees?

That is a DHT11. Its resolution is one degree and one per cent, so a room warming slowly shows nothing at all and then jumps. A DHT22 reports tenths. Neither is a fault; both are the number the sensor is capable of producing.

Is a humidity percentage the same as how much water is in the air?

No. Relative humidity is how full the air is compared with how much it could hold at its current temperature, so the same air reads differently as it warms and cools. Both sensors report the relative figure, which is why the dew point is often the more useful number to compute from it.

Where this goes next

Three of each in the box, and a straightforward rule for which project gets which.

DHT11 or DHT22

Edit this page — content/books/dht22/two-numbers-one-pin.mdx

Community

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.

Browse Modules and blocks on the forum