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 Nano ESP32 — wiring and code

Wire a DHT22 to an Arduino Nano ESP32 on D2 at 3.3 V, and why writing D2 (not 2) keeps the sketch right under either Pin Numbering setting.

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

Community draft — report a mistake

The Arduino Nano ESP32 brings Wi-Fi and Bluetooth to the Nano footprint. A DHT22 wires up just like on a classic Nano — DATA to D2 — with one change: power it from 3V3, because this Nano is a 3.3 V board.

The sketch uses the Nano pin name D2, which the core translates to the right ESP32-S3 GPIO for you.

Wiring

Arduino Nano ESP32Only the pins used are shown · 3.3 V logicDHT22 (AM2302)10k → 3V33V3GNDD21 VCC2 DATA3 NC (not connected)4 GND
Also needed: 10 kΩ resistor (bare DHT22 only).
Every connection
Arduino Nano ESP32DHT22 (AM2302)WireNotes
3V31 VCCred3.3 V, not VBUS: the data line is pulled up to VCC.
D22 DATAyellow
3V32 DATAredVia 10 kΩ — Bare 4-pin sensor only.
GND4 GNDblack

3.3–6 V part, 3.3 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

  • The Nano ESP32 looks like a classic Nano but its pins are 3.3 V. Power the DHT22 from 3V3 so its pulled-up DATA line never reaches 5 V.
  • Tools → Pin Numbering defaults to “By Arduino pin”: the core maps D2 to the S3’s GPIO5. Writing D2 in code works in both modes; a bare 2 means D2 only in the default mode and GPIO2 (pin A1) in “By GPIO number” mode.
  • Serial is the S3’s native USB. The sketch waits up to 3 s for the Serial Monitor to connect.

Code

dht22-nanoesp32.inoArduino C++Open in PlaygroundOpen in Playground
// DHT22 / AM2302 on an Arduino Nano ESP32.
// VCC → 3V3, DATA → D2, GND → GND. 10 kΩ pull-up DATA→3V3 for the bare 4-pin sensor.
// Write D2, not 2: with Tools → Pin Numbering "By Arduino pin" (default) both mean D2, but with
// "By GPIO number" a bare 2 is GPIO2 = pin A1. The D2 name is right in both modes.
#include <DHT.h>

DHT dht(D2, DHT22);

void setup() {
  Serial.begin(115200);
  uint32_t t0 = millis();
  while (!Serial && millis() - t0 < 3000) {}  // wait up to 3 s for the USB port
  dht.begin();
  Serial.println("DHT22 on D2 - first reading in 2 s");
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor - check wiring and pull-up");
    return;
  }
  Serial.printf("Temp %.1f C  Humidity %.1f %%\n", t, h);
}

Library: DHT sensor library (Adafruit (also install Adafruit Unified Sensor)) — compiled with DHT sensor library 1.4.7.

Expected serial output

Serial Monitor · 115200Output
DHT22 on D2 - first reading in 2 s
Temp 29.1 C  Humidity 58.2 %
Temp 29.1 C  Humidity 58.3 %

Common errors

“Failed to read from DHT sensor”

Check the pull-up and D2. Full fix.

Upload fails with “No DFU capable USB device”

Double-tap RST to enter the Arduino bootloader, then upload. Full fix.

↑↓ to move · Enter to open