DHT22, Better Accuracy Than the DHT11
| Difficulty | Beginner |
|---|---|
| Category | Sensors |
| Supported boards | Arduino Uno R3 and compatible ATmega328P boards |
| Time needed | 35 minutes |
| Prerequisites | Read Temperature and Humidity with DHT11 |
| Tested board | Not yet verified |
| Tested on | Not yet verified |
| Arduino IDE version | Not yet verified |
| Library | Not yet verified |
What it does
The same job as the DHT11, done properly. Temperature and humidity, read over one wire, in a white plastic housing that is noticeably larger than its blue cousin.
If you have done the DHT11 tutorial, this page is short by design: the wiring is the same, the library is the same, and the code is one word different. What is worth your time is when the extra cost is justified, because for a lot of projects it is not.
Before you begin
Required parts and tools
- An Arduino Uno or compatible board.
- One DHT22 module. This is Siratek product 2870.
- Three jumper wires. The Siratek part is supplied with a three-wire lead.
What you are holding
The Siratek part is a module, not a bare sensor: an ASAIR AM2302 in the white housing, mounted on a small black PCB with a three-pin header marked
+ out -
AM2302 is the same sensor as a DHT22 in a module package, which is why datasheets and libraries use both names for it.
As with the DHT11 module, the board carries the pull-up resistor, so no external resistor is needed. A bare four-pin DHT22 without a board does need one, typically 10 kilohms between data and power.
Where it is better
| DHT11 | DHT22 | |
|---|---|---|
| Temperature range | 0 to 50 C | -40 to 80 C |
| Temperature accuracy | about 2 C | about 0.5 C |
| Temperature resolution | 1 C, whole numbers only | 0.1 C |
| Humidity range | 20 to 80 % | 0 to 100 % |
| Humidity accuracy | about 5 % | about 2 to 5 % |
| Reading interval | 1 second | 2 seconds |
The resolution line is the one that usually decides it. A DHT11 reports temperature as whole degrees, so a room drifting from 24.2 to 24.8 shows no change at all, then jumps a degree. For anything you intend to graph, that alone is worth the upgrade.
The range line matters outdoors or in a fridge, where the DHT11 simply stops being valid.
Where it is not worth it
If the project asks “is it hot?” or “is it humid?”, the DHT11 answers just as well for less money. Neither sensor is a laboratory instrument, and the DHT22’s humidity accuracy is only modestly better than the DHT11’s.
And neither is the right choice for temperature alone. A DS18B20 is more accurate than both, reads faster, is waterproof, and several can share one pin. Buy a DHT for humidity; buy a DS18B20 for temperature.
Two seconds, not one
The DHT22 needs two seconds between readings, where the DHT11 needs one. Ask more often and you get the previous reading again, or a nan.
This catches people moving a working DHT11 sketch across. The symptom is intermittent failed reads that look like a wiring fault.
Pin reference
| Pin or label | Connect to | Purpose | Notes |
|---|---|---|---|
+ |
Uno 5V |
Power | 3.3 to 6 V |
out |
Uno D2 |
Data | Pull-up already fitted on the module |
- |
Uno GND |
Ground |
Wiring steps
- Unplug the USB cable.
+to5V.outtoD2.-toGND.- Plug the USB cable back in.
The supplied lead has three separate female ends, so check each against the silkscreen rather than assuming the colours. Orange, yellow and green here are just wire, not a convention.
Software and libraries
The same DHT sensor library by Adafruit used in the DHT11 tutorial, with Adafruit Unified Sensor alongside it. If you have already done that tutorial, nothing new to install.
Minimal working example
// Siratek: temperature and humidity from a DHT22.
#include <DHT.h>
const int dhtPin = 2;
// The only change from the DHT11 sketch is this one word.
DHT dht(dhtPin, DHT22);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println("Siratek: DHT22 starting.");
}
void loop() {
// Two seconds minimum for a DHT22.
delay(2000);
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("read failed. Check the wiring, and wait two seconds between reads.");
return;
}
Serial.print("temperature = ");
Serial.print(temperature, 1);
Serial.print(" C humidity = ");
Serial.print(humidity, 1);
Serial.println(" %");
}
The DHT22 in the constructor is genuinely the whole difference. Leave it as DHT11 with a DHT22 connected and you get nonsense rather than an error, because the library decodes the same bits a different way.
Printing with , 1 shows one decimal place, which is the point of this sensor. With a DHT11 that digit is always zero.
Checking for a failed read, every time
nan means “not a number”, and it is what the library returns when a reading did not arrive cleanly. Occasional failures are normal with these sensors, especially on a longer wire.
The guard above prints a message. In a logger you would rather keep the previous value:
float lastGood = NAN;
void loop() {
delay(2000);
float t = dht.readTemperature();
if (!isnan(t)) {
lastGood = t;
}
if (!isnan(lastGood)) {
Serial.println(lastGood, 1);
}
}
A sketch that writes nan into a log file produces a spreadsheet column that will not plot. Filtering at the source is less work than cleaning it afterwards.
Expected result
A reading every two seconds, with one decimal place on both figures.
Breathe gently on the sensor: humidity should climb several percent within a second or two and fall back over the next half minute. That is the fastest way to prove it is really measuring rather than reporting a constant.
Expect the temperature to read a little above the room. The sensor warms itself slightly, and the effect is more noticeable in still air.
Troubleshooting
| Symptom | Likely cause | Check or fix |
|---|---|---|
Always nan |
Wiring, or DHT11 in the constructor |
Check both |
Intermittent nan |
Reading faster than every two seconds | Slow down |
| Readings plausible but odd | Wrong sensor type in the constructor | DHT22, not DHT11 |
| Decimal place always zero | That is a DHT11 | Check which part you have |
| Humidity stuck at 99 | Condensation on the sensor | Let it dry; it recovers |
| Temperature reads high | Self-heating, still air | Normal; allow some airflow |
| Fails on a long cable | Signal degraded | Keep it under a metre, or add a 10 k pull-up |
| Works, then stops after months | Humidity sensors age | Expected; they drift over years |
| Compile error about Adafruit_Sensor | Unified Sensor library missing | Install it as well |
| Want a tenth of a degree outdoors | This is the right sensor | Or a DS18B20 for temperature alone |
Next steps
- Easier first: Read Temperature and Humidity with DHT11, which this page assumes.
- Related products: the DS18B20 for temperature alone, or the BMP280 for pressure.
- Next project: a mini weather station, logging temperature and humidity to an SD card with a real timestamp.
Sources and attribution
All text, wiring guidance and code in this tutorial are original Siratek work.
- DHT22 and DHT11 datasheets for the ranges, accuracies, resolutions and minimum reading intervals in the comparison table.
- The ASAIR
AM2302marking, the+ out -header and the supplied three-wire lead were read from the Siratek product photographs for item 2870, which is what establishes that no external pull-up is needed.
Accuracy figures are the manufacturer’s typical values and are given as such. No third-party tutorial text, diagrams, photographs or code has been reproduced here.

