AHT10 i2C Readings way off

Hey am fairly new to programming and having trouble with the AHT10 sensor.

I am just trying to up load to a ESP32 WROOM 32 and have it present readings on the serial monitor for now.
I finally found some sample code which seemed to work however the Humidity and Temp readings are always around 2.8% and -50C which seems slightly off being a nice spring morning in the UK...

The readings do change slightly if I warm it up or breath on it to increase humidity it just seems wildy uncalibrated.

my code is:

#include <Wire.h>

#define SHT10_ADDRESS 0x38

void setup() {
  Wire.begin(); // Initialize I2C
  Serial.begin(9600);
}

void loop() {
  // Start measurement
  Wire.beginTransmission(SHT10_ADDRESS);
  Wire.write(0xAC);
  Wire.write(0x33);
  Wire.write(0x00);
  Wire.endTransmission();

  // Wait for measurement to complete (e.g., 80ms)
  delay(80);

  // Request data
  Wire.requestFrom(SHT10_ADDRESS, 7);

  // Read data
  if (Wire.available()) {
    byte status = Wire.read(); // Status byte (not used here)
    byte humidity_msb = Wire.read();
    byte humidity_lsb = Wire.read();
    byte temp_msb = Wire.read();
    byte temp_lsb = Wire.read();
    byte checksum = Wire.read();
    
   // Process humidity and temperature data (example)
    float humidity = ((humidity_msb << 8) | humidity_lsb) * 100.0 / 1048576.0;
    float temperature = (((temp_msb << 8) | temp_lsb) * 200.0 / 1048576.0) - 50.0;

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

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

delay(2000); // Wait for next reading
}

Any pointers would be most welcome, I have tried with a second AHT10 I have to the same avail.

You might like to use a library for that sensor:

Also, AHT10 is not same as SHT10.

I have included the library
#include <Adafruit_AHTX0.h>

and changed the senesor name to AHT10 (i had been playing around with the sensor name to see if anything worked.

However now I just get the error "Not connected, select board and port to connect automatically"

This was the same error I was getting when trying to use the AHT10 Example code?!

Scratch that I closed and opened the serial port and its functioning but with the same drastically low readinds!

So you try this code?

#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

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

  if (! aht.begin()) {
    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");

  delay(500);
}

using pins

  • sdaPin GPIO21
  • sclPin GPIO22
  • 3.3V
  • GND

Holy Cow it works!
I was using those pins yes, Ill have to go over this and figure out what was going on.

Thanks!

You are welcome!