Adafruit_AHT10 Multiple Sensor
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit_AHT10 Multiple Sensor

by SteveV88 on Sun Jan 17, 2021 3:31 pm

I'm trying to use multiple sensors via the I2C-bus but i can't figuring out how the code must look like.

This is my code for one sensor, only for testingen if it works with the adress of the sensor (0x38)

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>

#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

void setup() {
  Serial.println("Adafruit AHT10/AHT20 demo!");

  if (! aht.begin(&Wire, 0x38)) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  Serial.println("AHT10 or AHT20 found");

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");

but when i change the adress into something else like (0x40), the code still works...

I have looked in the libaray code <Adafruit_AHTX0.h> and i think that the following the part is the part I need, only I don't know how it works ...

Code: Select all | TOGGLE FULL SIZE
 *    @brief  Sets up the hardware and initializes I2C
 *    @param  wire
 *            The Wire object to be used for I2C connections.
 *    @param  sensor_id
 *            The unique ID to differentiate the sensors from others
 *    @return True if initialization was successful, otherwise false.
bool Adafruit_AHTX0::begin(TwoWire *wire, int32_t sensor_id) {
  delay(20); // 20 ms to power up

  if (i2c_dev) {
    delete i2c_dev; // remove old interface

  i2c_dev = new Adafruit_I2CDevice(AHTX0_I2CADDR_DEFAULT, wire);

  if (!i2c_dev->begin()) {
    return false;

  uint8_t cmd[3];

  if (!i2c_dev->write(cmd, 1)) {
    return false;

  cmd[1] = 0x08;
  cmd[2] = 0x00;
  if (!i2c_dev->write(cmd, 3)) {
    return false;

  while (getStatus() & AHTX0_STATUS_BUSY) {
  if (!(getStatus() & AHTX0_STATUS_CALIBRATED)) {
    return false;

  humidity_sensor = new Adafruit_AHTX0_Humidity(this);
  temp_sensor = new Adafruit_AHTX0_Temp(this);
  return true;

Posts: 2
Joined: Sun Jan 17, 2021 2:52 pm

Re: Adafruit_AHT10 Multiple Sensor

by dastels on Sun Jan 17, 2021 4:52 pm

Both the AHT10 and AHT20 have a single, fixed address (0x38). From looking at the library code, any address you pass into the begin function is ignored.

The result is that you can't just connect multiple sensors to the I2C bus. To use multiples you would need to use an I2C multiplexer like https://www.adafruit.com/product/2717.


Posts: 5396
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.