AHT20 temperature + humidity with ESP32
Supply 3.3-5 V
Bus I2C
I2C address
0x38
Measures temperature, humidity
Pins and ESP32 wiring
| Pin | Role | ESP32 pin | Notes |
|---|---|---|---|
| VIN | Power | 3V3 | |
| GND | Ground | GND | |
| SCL | I2C clock (SCL) | D22 | |
| SDA | I2C data (SDA) | D21 |
Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.
Good to know
- Its address is fixed at 0x38: one per bus. The DHT20 uses the same chip and the same address. (Aosong AHT20 datasheet, Sensor address 0x38)
- After power-up, wait 40 ms; each measurement takes about 80 ms. (Aosong AHT20 datasheet, Sensor reading process)
Starter code (Arduino)
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA = GPIO 21, SCL = GPIO 22
Wire.beginTransmission(0x38);
bool found = Wire.endTransmission() == 0;
Serial.println(found ? "AHT20 temperature + humidity found at 0x38" : "Not found: check power, GND and SDA/SCL");
}
void loop() {}
Sources
- Aosong AHT20 datasheet, I2C address 0x38
- Aosong AHT20 datasheet, Supply voltage 2.2 to 5.5 V
Try it in 3D in BoardPilot
AHT20 temperature + humidity on other boards: wiring and code
Arduino Mega 2560 R3 Arduino Nano Arduino Uno R3 WeAct Black Pill STM32F411CE ESP32-C3-DevKitM-1 ESP32-S3-DevKitC-1 Nordic nRF52840 DK NUCLEO-F401RE Raspberry Pi Pico 2 Raspberry Pi Pico W Raspberry Pi Pico Teensy 4.1
Learn the basics
Lesson: UART, I2C and SPI I2C I2C address SDA and SCL Pull-up resistor
Related parts
ADS1015 12-bit ADCADS1115 16-bit ADCADXL375 high-g accelerometer (±200 g)AHT10 temperature + humidityAHT20 + BMP280 combo moduleAM2320 temperature + humidity
Part data: CC BY 4.0, free to reuse with credit to BoardPilot.