AHT20 temperature and humidity sensor
The ASAIR AHT20 on its four-pin I2C breakout: temperature and relative humidity at
address 0x38. Aliases: AHT20 module, AHT10 successor, DHT11 replacement.
It is the sensor replacing the DHT11 in newer kits. It measures the same two things, more accurately, and it does it on the I2C bus, so it shares two wires with a display instead of needing a pin and a timing-critical protocol of its own.
Pins
| Pin | What it does |
|---|---|
VCC |
Supply, 2.0 V to 5.5 V. |
GND |
Ground. |
SCL |
I2C clock. The module carries the pull-ups. |
SDA |
I2C data. |
Properties
temperature (°C, -40 to 85) and humidity (%RH, 0 to 100) are the weather, and
the two sliders on the part change them while the circuit runs.
How it talks
There are no registers. A write is a command and a read is the status byte and the data after it, as the datasheet lays out:
- Power on takes up to 20 ms; until then the address is not acknowledged.
- Trigger a measurement with
0xAC 0x33 0x00. It takes 80 ms, and bit 7 of the status byte (busy) is set the whole time. - Read the status byte and then six bytes: two 20-bit counts, humidity first,
sharing the middle byte, and a CRC-8 (polynomial
0x31, starting at0xFF). - Convert:
RH = count / 2^20 x 100 %andT = count / 2^20 x 200 - 50 °C. - Soft reset is
0xBA, and takes up to 20 ms.
A slider moved between measurements shows up in the next one, never the one already taken.
The library
Adafruit_AHTX0.h works as its tutorial uses it:
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
void setup() {
Serial.begin(115200);
if (!aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print(temp.temperature);
Serial.print(" C ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
delay(2000);
}
The readings are floats built from whole hundredths, so printing them works on every
board. Sums on them (temp.temperature * 1.8 + 32) link only on the Uno R4; for
arithmetic, aht.getTemperatureCentis() and aht.getHumidityCentis() return the
same reading in hundredths.
What the model gets right
The command set, the 20 ms power-on and reset times, the 80 ms measurement with its
busy bit, the bit packing and the CRC, all from the ASAIR datasheet (V1.1). The chip
powers up calibrated (status bit 3 set), as the parts sold do, and reads 0x18 when
idle.
What it does not model
The accuracy figures (±2 %RH and ±0.3 °C typical), the 8 s humidity response time, and self-heating, which is why the sheet asks for a reading no more often than every 2 seconds.
Common mistakes
Reading straight after the trigger. The chip needs 80 ms, and a read before then has the busy bit set and the old data.
See it in action
Touch climate display shows an AHT20 on a 16x2 LCD sharing the same two wires. Open it at /templates.