This is the classic first sensor project on an Uno: a DHT22 on digital pin 2, a pull-up resistor, and the Adafruit DHT library.
Because the Uno is a 5 V board, power the sensor from 5V — its data line then matches the Uno’s logic level. The sketch keeps strings in flash with F("…") to save the Uno’s 2 KB of RAM.
Wiring
| Arduino Uno R3 | DHT22 (AM2302) | Wire | Notes |
|---|---|---|---|
| 5V | 1 VCC | red | |
| D2 | 2 DATA | yellow | |
| 5V | 2 DATA | red | Via 10 kΩ — Pull-up for the bare 4-pin sensor. 3-pin breakouts already have it — skip this wire. |
| GND | 4 GND | black |
3.3–6 V part, 5 V board. Works at 3.3 V and 5 V. Power it from the same voltage as your board (3.3 V on ESP32 and Pico, 5 V on Uno), so the data line never exceeds the GPIO limit.
Board quirks
- On the Uno both the sensor and the board run at 5 V, so no level shifting is needed.
- Set the Serial Monitor to 9600 baud to match the sketch.
- AVR
printfcan’t print floats, so the sketch prints values withSerial.print(value, 1).
Code
// DHT22 temperature + humidity on an Arduino Uno R3.
// DATA → D2, VCC → 5V, GND → GND, 10 kΩ pull-up DATA → 5V (breakouts have one).
#include <DHT.h>
const uint8_t DHT_PIN = 2;
DHT dht(DHT_PIN, DHT22);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println(F("DHT22 on D2 - first reading in 2 s"));
}
void loop() {
delay(2000); // the DHT22 can't be read faster than once every 2 s
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor - check wiring and pull-up"));
return;
}
// AVR printf has no %f, so print the parts separately.
Serial.print(F("Temp "));
Serial.print(t, 1);
Serial.print(F(" C Humidity "));
Serial.print(h, 1);
Serial.println(F(" %"));
}// DHT22 temperature + humidity on an Arduino Uno R3.
// DATA → D2, VCC → 5V, GND → GND, 10 kΩ pull-up DATA → 5V (breakouts have one).
#include <DHT.h>
const uint8_t DHT_PIN = 2;
DHT dht(DHT_PIN, DHT22);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println(F("DHT22 on D2 - first reading in 2 s"));
}
void loop() {
delay(2000); // the DHT22 can't be read faster than once every 2 s
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor - check wiring and pull-up"));
return;
}
// AVR printf has no %f, so print the parts separately.
Serial.print(F("Temp "));
Serial.print(t, 1);
Serial.print(F(" C Humidity "));
Serial.print(h, 1);
Serial.println(F(" %"));
}Library: DHT sensor library (Adafruit (also install Adafruit Unified Sensor)) — compiled with DHT sensor library 1.4.7.
Expected serial output
DHT22 on D2 - first reading in 2 s
Temp 28.4 C Humidity 58.9 %
Temp 28.4 C Humidity 59.1 %DHT22 on D2 - first reading in 2 s Temp 28.4 C Humidity 58.9 % Temp 28.4 C Humidity 59.1 %
Common errors
Failed to read from DHT sensor
Check the pull-up on a bare sensor, the pin (D2), and that you are not reading faster than every 2 seconds.
Garbage characters in the Serial Monitor
Set the baud rate in the Serial Monitor to 9600.