The DHT22 (AM2302) is the most popular maker-grade temperature + humidity sensor. ±0.5 °C accuracy, ±2 % humidity, single-wire digital interface. Perfect first sensor project, especially for Zimbabwean greenhouse / weather-station builds.
Parts list
- Arduino UNO (or any 5 V Arduino)
- DHT22 sensor (BlitzTech: SEN-DHT22)
- 10 kΩ pull-up resistor
- Breadboard + 3 jumper wires
- The DHT22 comes in two flavours: bare sensor (3 pins) and module-on-a-PCB (3 pins, pull-up already on board). If you have the module, you can skip the external resistor.
Wiring
Looking at the DHT22 with the grille facing you, pins from left to right:
1. VCC → Arduino 5 V
2. DATA → Arduino digital pin 2 (also connect via 10 kΩ pull-up resistor to 5 V)
3. (skip, not used on 3-pin variant)
4. GND → Arduino GND
If your DHT22 is a 4-pin bare-sensor, pin 3 is unused.
Install the library
In Arduino IDE: Tools → Manage Libraries → search 'DHT sensor library' by Adafruit. Install both 'DHT sensor library' and its dependency 'Adafruit Unified Sensor'.
The sketch
Paste this into a new sketch, save it, upload, then open Tools → Serial Monitor (set baud rate to 9600). You should see a fresh reading every two seconds. DHT22 can't be polled faster than every 2 seconds, that's a hardware limit, not the code.
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Sensor read failed!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C"));
}
Troubleshooting
- All NaN readings → pull-up resistor is missing or the data pin is wrong
- Frozen at one reading → wiring is loose or the DHT22 is faulty (try a second one)
- Wildly wrong humidity → the sensor was stored in a humid box; let it acclimatise for 30 min