Choose your country and language
Language
In this lesson, we will explore the AHT10 temperature & humidity sensor, an important component in your IoT air quality monitoring station. By the end of the lesson, you will understand what the AHT10 sensor is, how it works, and why it is suitable for measuring environmental data in this project.
The AHT10 is a high-precision, fully calibrated digital sensor designed to measure both temperature and humidity. It combines accurate measurements with a compact form factor, making it ideal for IoT applications.
![]() |
AHT10 high-precision temperature and humidity sensor |
![]() |
TTGO T-Display ESP32 16MB with WiFi, Bluetooth and 1.1" color LCD screen |
![]() |
Dupont cables, 40 pcs |
The AHT10 sensor works by using a specialized polymer capacitor to measure relative humidity and a thermistor to measure temperature. Here is a brief overview of how it works:
The sensor then digitizes these values and sends them to the ESP32 via the I2C interface.
The AHT10 sensor is an excellent choice for our IoT air quality monitoring station because of its combination of precision, low power consumption, and easy integration. Here are some reasons why it is a perfect fit:
The sensor data will be processed by the ESP32 and either displayed on a TFT screen or sent to a web server for remote access.
The sensor's role in the project:
About the measurements: The station in this series measures temperature and relative humidity using the AHT10. These are indoor climate readings, not direct measurements of CO2, VOCs, or particles. The series name “air quality monitoring” should be understood with this limitation.
Install Adafruit AHTX0 and the dependencies suggested by the Library Manager. The Adafruit_AHTX0 library was introduced in lesson 9. Connect the AHT10 as in lesson 7: VCC to 3.3V, GND to GND, SDA to GPIO 21, and SCL to GPIO 22. These pins apply to the original ESP32/TTGO T-Display board in this series; check the pinout for other board variants.
#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("AHT10 not found. Check power and I2C wiring.");
while (true) { delay(100); }
}
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" C");
Serial.print("Relative humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
delay(2000);
}Create a sketch, paste the code, select the correct board and port, and upload. Open the Serial Monitor at 115200 baud. Temperature in °C and relative humidity in % appear every 2 seconds. If the sensor is not found, the program stops after an error message: check the power supply and I2C wiring.
The code uses begin() for initialization and getEvent(&humidity, &temp) for readings. The order is humidity first, then temperature. The API and field names were checked against Adafruit’s official example. Official Adafruit AHTX0 example.
In the next lesson, episode 11, we cover troubleshooting in Arduino IDE. Episode 12 introduces TFT screens.
Language