How to Use the AHT10 Temperature and Humidity Sensor with Arduino

How to Use the AHT10 Temperature and Humidity Sensor with Arduino

The AHT10 is a precision temperature and humidity sensor that communicates via the I2C interface. It’s compact, reliable, and perfect for weather monitoring projects, IoT applications, and environmental sensing. In this tutorial, we will guide you step-by-step on how to interface the AHT10 with an Arduino.

What You Will Need

  1. AHT10 Temperature and Humidity Sensor Module
  2. Arduino Board (e.g., Uno, Mega, Nano)
  3. Breadboard
  4. Jumper Wires
  5. A computer with the Arduino IDE installed

Step 1: Wiring the AHT10 to Arduino

The AHT10 module communicates using the I2C protocol, requiring just two data lines: SDA (data) and SCL (clock). Below are the typical connections:

AHT10 Pin Arduino Uno Pin
VCC 3.3V or 5V
GND GND
SDA A4 (SDA)
SCL A5 (SCL)

Note: Check your specific Arduino board’s I2C pinout if you’re using a different model.

Step 2: Install the AHT10 Library

To simplify coding, we’ll use the "Adafruit AHT10" library.

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. In the Library Manager, search for "Adafruit AHT10".
  4. Select the library and click Install.

Step 3: Upload the Code

Here’s the example code to read temperature and humidity from the AHT10:

#include <Wire.h>
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

void setup() {
  Serial.begin(9600);
  Serial.println("AHT10 Sensor Test");

  if (!aht.begin()) {
    Serial.println("Failed to find AHT10 sensor!");
    while (1) delay(10);
  }
  Serial.println("AHT10 found and initialized.");
}

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);  // Read temperature and humidity

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(humidity.relative_humidity);
  Serial.println(" %");

  delay(2000);  // Wait 2 seconds before next reading
}

Step 4: Test the Setup

  1. Connect your Arduino to the computer using a USB cable.
  2. Open the Arduino IDE and select the correct Board and Port from the Tools menu.
  3. Upload the code by clicking the Upload button.
  4. Open the Serial Monitor from the Arduino IDE (Tools > Serial Monitor) and set the baud rate to 9600.
  5. You should see temperature and humidity readings displayed every 2 seconds.

Troubleshooting

  • Sensor not detected: Double-check the wiring and ensure SDA/SCL pins are correctly connected.
  • Incorrect readings: Ensure the sensor is not exposed to extreme conditions during initialization.
  • Library issues: Make sure the "Adafruit AHT10" library is properly installed.

Conclusion

You’ve successfully interfaced the AHT10 sensor with an Arduino. The AHT10’s accurate temperature and humidity readings make it ideal for various applications, from home automation to weather stations. Experiment with the data and integrate it into your own projects. Have fun building!

Leave a comment

Notice an Issue? Have a Suggestion?
If you encounter a problem or have an idea for a new feature, let us know! Report a problem or request a feature here.