TK39ONEWIREbeginner

DHT22 and DHT11 Temperature and Humidity Sensors

Two sensors on one board design, one data wire, one library. What each is worth, why the same forty bits decode two ways, and the six-pack that holds three of each.

DHT Sensor Kit: 3 × DHT22 and 3 × DHT11

Specifications

TypeSingle-wire temperature and humidity sensor on a breakout board
DHT22 · TK39-40 to 80 °C at ±0.5 °C, 0–100 % RH at ±2 %, tenths of a degree and tenths of a per cent, one reading every 2 s
DHT11 · TK380 to 50 °C at ±2 °C, 20–80 % RH at ±5 %, whole degrees and whole per cent, one reading every 1 s
Wires to your board3 — GND, VCC, and the 1 signal wire DATA. The fourth pin, NC, is connected to nothing
ProtocolSingle-wire, Aosong's own. No addresses, so it is neither I2C nor Dallas 1-Wire, and every sensor needs a pin of its own
Supply voltage3.3 V or 5 V — the DHT11 takes 3–5.5 V, the DHT22 takes 3.3–6 V. Whatever you feed VCC is what the data line idles at
Pull-up resistor10 kΩ from VCC to DATA, already fitted on both boards
BoardsTK38 22.4 × 33.9 mm, TK39 22.4 × 42.9 mm, both with a 2.54 mm 4-pin header and two mounting cut-outs
Current1 to 2.5 mA while measuring, under 200 µA between readings
In the boxThe DHT sensor kit holds 6 boards — 3 × DHT22 on the TK39 and 3 × DHT11 on the TK38 — plus a storage case. The TK38 and TK39 also ship singly and in the TinkerBlock kits

What it does

Two numbers — temperature and relative humidity — down one ordinary digital pin. Behind the plastic grille are a capacitive humidity element, a temperature element and a small microcontroller that reads both and applies its own factory calibration before sending anything, so there is no resistor to choose, no reference voltage to supply and nothing to calibrate.

It is not I²C and it is not Dallas 1-Wire, despite the single wire. There is no address in the protocol at all, so an I²C scan will never find one, and each sensor needs a data pin of its own.

The two boards

Three of each in the kit, and they are the same PCB with a different sensor on top: the same three nets, the same four pads, the same 10 kΩ pull-up already fitted.

The DHT sensor kit: three white DHT22 boards along the top, each with a large white sensor cage marked LONELY BINARY AM2302 DHT22 over a black gold-edged PCB, and three smaller boards below with blue DHT11 cages, beside a teal card box printed DHT SENSORS KIT.
Three DHT22s, three DHT11s and a case. The white cages are the DHT22s.
The TK39 DHT22 board and the TK38 DHT11 board rendered to the same scale from the sensor side: both are black PCBs with a gold immersion-plated border, two large mounting cut-outs and a four-pin header labelled GND, VCC, NC and DATA, with SINGLE WIRE printed up the right-hand edge. The DHT22 board is 9 mm the taller.
TK39 and TK38 to scale. Only the cage differs; the circuit underneath is identical.

Which one

DHT11 · TK38DHT22 · TK39
Temperature0 to 50 °C, ±2 °C−40 to 80 °C, ±0.5 °C
Humidity20–80 % RH, ±5 %0–100 % RH, ±2 %
Steps1 °C, 1 %0.1 °C, 0.1 %
A reading every1 s2 s
Supply3–5.5 V3.3–6 V
Use it forlearning, a display you glance atlogging, outdoors, anything that switches

The range is the hard limit: below 0 °C the DHT11 is outside its specification and does not warn you about it, so an outdoor logger built on one goes blind on the coldest night of the year. The accuracy is the soft one, and it matters exactly when something downstream acts on the number.

Wiring, in four lines

  1. GND to the board's GND. It is pin 1, on the square pad.
  2. VCC to 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico.
  3. NC to nothing. It is connected to nothing on the board either.
  4. DATA to any free digital pin — D2 on an Uno, GPIO 18 on an ESP32.

VCC is the one that is not free choice. The board's 10 kΩ pull-up ties DATA to it, so from 5 V beside a 3.3 V processor the data line idles 1.7 V over the pin's rating.

Example

Install DHT sensor library by Adafruit from the Library Manager, and accept Adafruit Unified Sensor when it offers it.

#include <DHT.h>

#define DHT_PIN  2      // Uno D2.  ESP32: 18.  ESP32-S3: 4.
#define DHT_TYPE DHT22  // DHT22 for the white cage, DHT11 for the blue one.

DHT dht(DHT_PIN, DHT_TYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
}

void loop() {
  // Two calls, one exchange: the library caches for two seconds, so the
  // second reads the bytes the first fetched.
  float humidity = dht.readHumidity();
  float celsius  = dht.readTemperature();

  // A failed read returns nan rather than throwing, and one failure in a
  // hundred is normal for this protocol. Checking is not optional.
  if (isnan(humidity) || isnan(celsius)) {
    Serial.println("read failed");
  } else {
    Serial.print(celsius);  Serial.print(" C  ");
    Serial.print(humidity); Serial.println(" %");
  }

  delay(2000);   // the floor is 2 s, for both sensors, in this library
}

Where to start

The handbook below is twelve short articles with a working figure in each. If you only read one, read forty bits and a checksum — it is why declaring the wrong sensor prints a confident wrong number instead of an error. If you want a reading now, the first reading is the whole build, and DHT11 or DHT22 decides which of the six boards to reach for.

Wiring diagram

Full board reference: ESP32-S3 pinout.

When it doesn’t work

Every reading comes back as nan.
Nothing answered on the wire — that is the only error this protocol can produce. Check GND, then that VCC is on a powered rail, then that DATA is on the pin your sketch names, counting from the square pad: GND, VCC, NC, DATA. Then check the sensor type in the sketch: a DHT11 declared as a DHT22 gets a start pulse eighteen times too short and usually never wakes.
It prints numbers, but silly ones — 2 % and 0 °C, or a humidity in the hundreds.
The wiring is right and the type is wrong. Both sensors send forty bits with a valid checksum; a DHT22 packs tenths into two bytes and a DHT11 puts whole units in one, so decoding either as the other succeeds and produces nonsense. Blue cage is DHT11, white cage is DHT22, and the back of the board says which.
The reading never changes.
You are reading faster than two seconds. Adafruit's library caches for 2000 ms — for the DHT11 as well, whose own datasheet allows one second — and inside that window it returns the previous value without touching the wire. Put the read on a millis() timer.
Can I power it from 5 V next to an ESP32?
No. The board's 10 kΩ pull-up ties DATA to VCC, so from 5 V the data line idles at 5 V against a pin rated for 3.3 V. It will appear to work, which is the problem — the damage is cumulative. Feed it 3V3; both sensors are specified there.
It reads two or three degrees higher than my thermometer.
Self-heating. The sensor is measuring the board it is plugged into, not the room. Move it off the breadboard on three long jumper wires, away from the regulator and the USB socket, and give it a few minutes. The humidity improves with it: a sensor that reads warm also reads dry.
Can I put two sensors on one pin?
No. There is no address anywhere in the protocol, so both would answer at once and neither reading would survive. Sensors share power and ground and need a data pin each — six sensors is six pins.
Is the DHT22 the same as the AM2302?
The same sensing part, and the cage on these boards is printed AM2302 DHT22. The name AM2302 usually refers to Aosong's version with a cable and the pull-up already attached; the bare four-pin part is normally sold as DHT22. Either way the library type is DHT22.

The DHT sensors handbook

12 articles · about 55 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

Two sensors, one wire

2 articles

What is actually inside the little plastic cage, and how to decide which of the two boards in the box a project should get.

What is in the box

2 articles

Six boards that are the same board with two different sensors on them, and the three wires that get the first reading out.

How the one wire works

2 articles

The start pulse that is eighteen times longer on one sensor than the other, and the forty bits that mean two different things depending on which sent them.

The three limits

3 articles

How often you may ask, how long the sensor takes to catch up with the room, and what the supply pin decides about the data pin.

Two builds and a check

3 articles

Both sensors on one board so you can watch them disagree, a dew point that means more than a humidity percentage, and what to look at when every reading is nan.

Lessons using TK39

Each one is a working build, not a snippet.

Edit this page — content/modules/dht22.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