Part

Temperature and humidity, DHT22

One wire, forty bits and a checksum. Drag the two sliders for the weather it reads.

See every part
  • 3 pins
  • 5 settings
  • In 4 projects
  • In 8 lessons
Drawn live by the editor's own code, at the size you see it.
At a glance

The Temperature and humidity, DHT22 in brief

What it is, and every setting the properties panel gives it.

The DHT22 and its cheaper sibling the DHT11 measure temperature and humidity and report both over one data wire, with no bus standard behind it at all. The board pulls the line low to ask, lets go, and the sensor answers with forty pulses whose widths are the bits, ending in a checksum. Mokxi decodes nothing on the sensor’s behalf: the part drives the pin with the datasheet’s timing and the sketch has to measure it, exactly as on a desk. It also keeps the two habits that confuse people most. A request in the first second after power-up is ignored, so the first reading fails; and the DHT22 only measures every two seconds, handing back its last reading in between, so a sketch that polls faster sees a number that seems stuck. The model property switches between the DHT22 and the DHT11, whose bytes mean different things on the same wire.

Family
Sensors
Pins
3
model
dht22 (or dht11)
temperature
22
humidity
50
pullup
true
pullup_ohms
5100

A circuit built around it, running and explained: the DHT11 simulator.

Pins

3 pins

Named as the editor names them, so a wire lands where you expect it.

  • VCC
  • DATA
  • GND
How to use it

How to use the DHT11 or DHT22 with an Arduino

Wire VCC to 5 V, GND to GND and DATA to any digital pin; a three-pin module has its pull-up on board, and a bare four-pin sensor needs a 10 k resistor from DATA to VCC. Then ask for a reading no more than once every two seconds, and check every reading before you use it, because a failed one comes back as nan.

The Adafruit DHT library’s calls compile here as they stand. The floats it returns print normally and take arithmetic of your own; the built-in weather station works in whole tenths only to stay small on the Uno.

A DHT11 wires the same way. Change DHT22 to DHT11 in the constructor and set the part’s model property to DHT11: the two send their bytes differently, so code for one reads the other wrong. The DHT11 reads whole degrees from 0 to 50 and whole percent from 20 to 90.

Part pin
Board pin
VCC
5 V
DATA
Pin 2
GND
GND

The DHT library compiles on every board here, the ESP32 and the Pico included, and the sensor is happy on 3.3 V.

Arduino Uno: DHT22 weather stationlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Reading a DHT22 with the DHT library
#include "DHT.h"

DHT dht(2, DHT22);

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

void loop() {
  delay(2000);
  float t = dht.readTemperature();
  if (isnan(t)) return;
  Serial.println(t);
}
How it is modeled

What is true about the Temperature and humidity, DHT22, here

In its help article’s own words: what the simulation gets right, and where it stops.

The DHT11 and the DHT22

One wire, three pins, forty bits. The blue brick is the DHT11 and the white one is the DHT22 (also sold as the AM2302); the wire is identical and only the five bytes differ.

Not modeled

The accuracy: +/-2 %RH and +/-0.5 C on a DHT22, +/-5 and +/-2 on a DHT11. The number the slider says is the number that goes on the wire. Nor the seconds the capacitive element takes to follow a change in the air, nor self-heating.

From Signals you time, not read, in full.

Projects

See the Temperature and humidity, DHT22 in a project

4 built-in projects use it. Each opens in the editor, already wired.

Boards

The boards it is shown on

Each of these 3 boards has a built-in project with the Temperature and humidity, DHT22 in it.

Boards

The Temperature and humidity, DHT22 on each board

The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.

Libraries

Arduino libraries for the Temperature and humidity, DHT22

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the Temperature and humidity, DHT22

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.