The AHT20 is a small I2C temperature and humidity sensor that does the DHT22’s job more accurately, faster, and on a shared bus. A module costs about ₹120, often combined with a BMP280 pressure sensor on one board.
On the Uno it runs from 5V — the chip is rated up to 5.5 V — and wires to SDA/SCL, the same signals as A4/A5. It sits at I2C address 0x38, so it shares the bus with an LCD backpack or OLED without a clash.
The sketch reads temperature and humidity every 2 seconds with the Adafruit AHTX0 library.
Wiring
| Arduino Uno R3 | AHT20 temperature + humidity sensor | Wire | Notes |
|---|---|---|---|
| 5V | VCC | red | The AHT20 chip itself runs from 2.0 to 5.5 V. |
| GND | GND | black | |
| SCL | SCL | yellow | Same signal as A5 |
| SDA | SDA | blue | Same signal as A4 |
2.0–5.5 V part, 5 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
- Compared with a DHT22 it reads in about 80 ms, has no timing-critical protocol (so no interrupts are turned off), and shares the I2C bus with displays.
- The popular blue AHT20 + BMP280 combo board has both chips on one I2C bus: the AHT20 at 0x38 and the BMP280 at 0x77. This sketch reads the AHT20; add the BMP280 library for pressure.
- The Adafruit AHTX0 library pulls in Adafruit Unified Sensor and BusIO; this sketch uses about a quarter of the Uno’s 32 KB flash. Fine on its own, but count it if you add a graphics display.
- Mount it away from the Uno’s regulator and any USB charger — a degree of self-heating is common on a breadboard.
Code
// AHT20 temperature + humidity sensor on an Arduino Uno R3, I2C at 0x38.
// VCC → 5V, GND → GND, SCL → SCL (A5), SDA → SDA (A4).
#include <Wire.h>
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
void setup() {
Serial.begin(9600);
if (!aht.begin()) {
Serial.println(F("AHT20 not found at 0x38 - check SDA/SCL"));
for (;;) {}
}
Serial.println(F("AHT20 ready"));
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print(F("Temp "));
Serial.print(temp.temperature, 1);
Serial.print(F(" C Humidity "));
Serial.print(humidity.relative_humidity, 1);
Serial.println(F(" %"));
delay(2000); // AHT20 self-heats a little if read much faster
}// AHT20 temperature + humidity sensor on an Arduino Uno R3, I2C at 0x38.
// VCC → 5V, GND → GND, SCL → SCL (A5), SDA → SDA (A4).
#include <Wire.h>
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
void setup() {
Serial.begin(9600);
if (!aht.begin()) {
Serial.println(F("AHT20 not found at 0x38 - check SDA/SCL"));
for (;;) {}
}
Serial.println(F("AHT20 ready"));
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print(F("Temp "));
Serial.print(temp.temperature, 1);
Serial.print(F(" C Humidity "));
Serial.print(humidity.relative_humidity, 1);
Serial.println(F(" %"));
delay(2000); // AHT20 self-heats a little if read much faster
}Library: Adafruit AHTX0 (Adafruit) — compiled with Adafruit AHTX0 2.0.6.
Expected serial output
AHT20 ready
Temp 28.6 C Humidity 63.4 %
Temp 28.6 C Humidity 63.5 %AHT20 ready Temp 28.6 C Humidity 63.4 % Temp 28.6 C Humidity 63.5 %
Common errors
“AHT20 not found at 0x38”
SDA/SCL swapped or no power. Run the I2C scanner; 0x38 should appear.
Humidity stuck at 0 % or 100 %
An older AHT10 (also at 0x38) or a failed read. The AHTX0 library supports both; check the chip marking.
“Adafruit_Sensor.h: No such file”
Install Adafruit Unified Sensor as well — see this fix.