AHS01IB - Absolute Humidity Sensor Code

Hi everyone,
I am trying to use Asair brand humidity sensor AHS01IB. Its datasheet is attached.
It requires i2c communication, which I am struggling with. I contacted the company Asair, and they shared the sample code (AHS01 Sample Code.c) also attached.

This is my first time using i2c communication, can someone please help me write a simple code to reach the humidity levels from the sensor?

1151993_AHS01IB-Absolute-humidity-sensor-User-Manual-20191217.pdf (1.1 MB)
AHS01 Sample Code.c (3.8 KB)

something like this maybe...
(Compiles, NOT tested!)

#include <Wire.h>

/*------------------------------------------------ --------------------------
	AHS01IA I2C slave address: 0x2A
	Reading operation steps: 1 ) Send start command 2 ) Read data
-------------------------------------------------- --------------------------*/

#define AHS01IA_Addr 0x2A
#define I2C_CMD_READ 	0x0002
#define I2C_CMD_START 	0x0601
#define I2C_CMD_STOP 	0x0701

/*------------------------------------------------ --------------------------

-------------------------------------------------- --------------------------*/

void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  
  	// Peripheral initialization
   // sensor start command
  Wire.beginTransmission(AHS01IA_Addr); // transmit to device #4
  Wire.write(0x06);        // sends five bytes
  Wire.write(0x01);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  
	delay(1000);
	
}

void loop() {
  Wire.beginTransmission(AHS01IA_Addr); // transmit to device 
  Wire.write(0x00);        // sends five bytes
  Wire.write(0x02);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  
  delay(500);
  
  Wire.requestFrom(AHS01IA_Addr, 3);    // request to device

  while (Wire.available()) { // peripheral may send less than requested
    byte c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }
  Serial.println("");
  
}

hope that helps....

Run the I2C scanner and if it does not show the address post an annotated schematic showing exactly how you have wired it. Show all connections, power, ground, power sources etc and note any wires over 10"/25cm in length.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.