

The AHT20, manufactured by DFRobot (Part ID: AHT20), is a digital temperature and humidity sensor designed for precise environmental monitoring. It features a compact design, low power consumption, and I2C communication, making it ideal for integration into a wide range of microcontroller-based projects. The AHT20 is widely used in applications such as weather stations, HVAC systems, IoT devices, and industrial automation.








The AHT20 offers reliable performance with the following key specifications:
| Parameter | Value |
|---|---|
| Supply Voltage | 2.0V to 5.5V |
| Operating Current | 0.25 mA (average) |
| Communication Interface | I2C |
| Temperature Range | -40°C to 85°C |
| Temperature Accuracy | ±0.3°C |
| Humidity Range | 0% to 100% RH |
| Humidity Accuracy | ±2% RH |
| Response Time | ≤8 seconds |
| Dimensions | 3.8mm x 3.8mm x 1.0mm |
The AHT20 sensor has four pins, as described in the table below:
| Pin Name | Description |
|---|---|
| VCC | Power supply input (2.0V to 5.5V) |
| GND | Ground |
| SDA | I2C data line |
| SCL | I2C clock line |
0x38.Below is an example of how to interface the AHT20 with an Arduino UNO using the I2C protocol:
#include <Wire.h>
// AHT20 I2C address
#define AHT20_ADDRESS 0x38
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Initialize the AHT20 sensor
Wire.beginTransmission(AHT20_ADDRESS);
Wire.write(0xBE); // Send initialization command
Wire.endTransmission();
delay(10); // Allow time for initialization
}
void loop() {
// Trigger measurement
Wire.beginTransmission(AHT20_ADDRESS);
Wire.write(0xAC); // Trigger measurement command
Wire.write(0x33); // Data byte 1
Wire.write(0x00); // Data byte 2
Wire.endTransmission();
delay(80); // Wait for measurement to complete
// Read measurement data
Wire.requestFrom(AHT20_ADDRESS, 6); // Request 6 bytes of data
if (Wire.available() == 6) {
uint8_t data[6];
for (int i = 0; i < 6; i++) {
data[i] = Wire.read(); // Read each byte
}
// Process temperature and humidity data
uint32_t humidity = ((uint32_t)data[1] << 12) | ((uint32_t)data[2] << 4) |
(data[3] >> 4);
uint32_t temperature = ((uint32_t)(data[3] & 0x0F) << 16) |
((uint32_t)data[4] << 8) | data[5];
float humidityPercent = (humidity * 100.0) / 1048576.0;
float temperatureCelsius = (temperature * 200.0 / 1048576.0) - 50.0;
// Print results to the serial monitor
Serial.print("Humidity: ");
Serial.print(humidityPercent);
Serial.println(" %");
Serial.print("Temperature: ");
Serial.print(temperatureCelsius);
Serial.println(" °C");
}
delay(2000); // Wait 2 seconds before the next reading
}
No Data from the Sensor:
Inaccurate Readings:
I2C Communication Errors:
0x38) matches the one used in your code.Q: Can the AHT20 operate at 5V?
A: Yes, the AHT20 supports a supply voltage range of 2.0V to 5.5V, making it compatible with both 3.3V and 5V systems.
Q: How often can I take measurements?
A: The AHT20 has a response time of ≤8 seconds, but it is recommended to wait at least 2 seconds between measurements for optimal performance.
Q: Do I need to calibrate the AHT20?
A: No, the AHT20 is factory-calibrated and does not require additional calibration.