ESP32 – i2c AHT10

Table of Contents

Links

Some demo form Adafruit_AHTx0.h

Starter Code Still in Progress

				
					/*
    I used this code with a ESP32c3
*/

#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

// change in pins_arduino.h if you want other i2c Pins! PATH: C:\Users\:userName:\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\variants\esp32c3
// static const uint8_t SDA = 7;
// static const uint8_t SCL = 8;

Adafruit_Sensor *aht_humidity, *aht_temp;

void setup(void) {
  Serial.begin(115200);
  while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit AHT10/AHT20 test!");

  if (!aht.begin()) {
    Serial.println("Failed to find AHT10/AHT20 chip");
    while (1) {
      delay(10);
    }
  }

  Serial.println("AHT10/AHT20 Found!");
  aht_temp = aht.getTemperatureSensor();
  aht_temp->printSensorDetails();

  aht_humidity = aht.getHumiditySensor();
  aht_humidity->printSensorDetails();
}

void loop() {
  //  /* Get a new normalized sensor event */
  sensors_event_t humidity;
  sensors_event_t temp;
  aht_humidity->getEvent(&humidity);
  aht_temp->getEvent(&temp);

  Serial.print("\tHumidity: \t");
  Serial.print(humidity.relative_humidity);
  Serial.println(" % rH");
  Serial.print("\tTemperature: \t");
  Serial.print(temp.temperature);
  Serial.println(" degrees C");
  Serial.println();
  
  delay(1000);
}
				
			

Leave a Comment