Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

DHT22 with Arduino Uno — wiring and code

Wire a DHT22 / AM2302 to an Arduino Uno R3 on pin D2 at 5 V with a pull-up, and print temperature and humidity to the Serial Monitor.

Arduino C++Verified — core avr 1.8.8, DHT sensor library 1.4.7, 3 Nov 2026Compile-only

Community draft — report a mistake

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 R3Only the pins used are shown · 5 V logicDHT22 (AM2302)10k → 5V5VGNDD21 VCC2 DATA3 NC (not connected)4 GND
Every connection
Arduino Uno R3DHT22 (AM2302)WireNotes
5V1 VCCred
D22 DATAyellow
5V2 DATAredVia 10 kΩ — Pull-up for the bare 4-pin sensor. 3-pin breakouts already have it — skip this wire.
GND4 GNDblack

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 printf can’t print floats, so the sketch prints values with Serial.print(value, 1).

Code

dht22-uno.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// 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

Serial Monitor · 9600Output
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.

↑↓ to move · Enter to open