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.

AHT20 with ESP32 DevKit V1 — I2C humidity sensor at 3.3 V

Wire an AHT20 (or the AHT20 + BMP280 combo board) to an ESP32 DevKit V1 at 3.3 V on GPIO21/22 and read temperature and humidity with Adafruit AHTX0.

Arduino C++Verified — core esp32 3.3.12, Adafruit AHTX0 2.0.6, 3 Nov 2026Compile-only

Community draft — report a mistake

The AHT20 is a cheap, accurate I2C temperature and humidity sensor (±2 % RH, ±0.3 °C) that has replaced the DHT11 in many newer kits.

The ESP32 DevKit V1 wires it to 3V3 and the default I2C pins D21 (SDA) and D22 (SCL) — four wires, no resistors. The sketch uses Adafruit’s AHTX0 library and prints a reading every two seconds.

Wiring

ESP32 DevKit V1Only the pins used are shown · 3.3 V logicAHT20 temperature + humidity sensorGNDD22D213V3VCCGNDSCLSDA
Every connection
ESP32 DevKit V1AHT20 temperature + humidity sensorWireNotes
3V3VCCredThe module’s pull-ups go to VCC; 3V3 keeps SDA/SCL at ESP32 levels.
GNDGNDblack
D22SCLyellow
D21SDAblue

2.0–5.5 V part, 3.3 V board. Most AHT20 breakouts have pull-ups to their own VCC. On ESP32, Pico and other 3.3 V boards, power the module from 3.3 V so SDA/SCL never rise above 3.3 V.

Board quirks

  • The AHT20 has a fixed address, 0x38, so only one fits on a bus. For two, use the ESP32’s second I2C controller: Wire1.begin(SDA, SCL) on another pin pair such as D32/D33.
  • The popular blue “AHT20 + BMP280” board puts both chips on the same four pins: the AHT20 at 0x38, the BMP280 at 0x77. The Adafruit AHTX0 and BMP280 libraries run side by side on the same Wire bus.
  • getEvent() starts a measurement and waits about 80 ms for it. Don’t call it faster than every 2 s or the chip self-heats.
  • Older AHT10 modules (0x38 too) also work with this library, but they misbehave when they share the bus with other devices.

Code

aht20-esp32.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// AHT20 temperature + humidity on an ESP32 DevKit V1 (I2C address 0x38).
// VCC → 3V3, GND → GND, SCL → D22, SDA → D21.
#include <Wire.h>
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!aht.begin(&Wire)) {
    Serial.println("No AHT20 at 0x38 — check wiring and 3V3");
    while (true) delay(1000);
  }
  Serial.println("AHT20 ready");
}

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);  // triggers a measurement (~80 ms) and reads it
  Serial.printf("Temp %.2f °C  Humidity %.1f %%\n", temp.temperature, humidity.relative_humidity);
  delay(2000);
}

Library: Adafruit AHTX0 (Adafruit) — compiled with Adafruit AHTX0 2.0.6.

Expected serial output

Serial Monitor · 115200Output
AHT20 ready
Temp 28.62 °C  Humidity 63.8 %
Temp 28.63 °C  Humidity 63.9 %

Common errors

“No AHT20 at 0x38”

Check SDA/SCL and 3V3. On the combo board make sure you’re on the I2C pins, not the BMP280’s unused SDO/CSB holes. I2C scanner.

Readings stop updating after hours

An AHT20 can lock up on a noisy bus. Power-cycle it from a GPIO (through a transistor) or add 100 nF across VCC–GND at the sensor.

Compile error: Adafruit_I2CDevice.h not found

Adafruit BusIO is missing — install it next to AHTX0. Fix.

↑↓ to move · Enter to open