AFS01 Micro Air Flow Sensor unable to connect to arduino

I purchase a micro airflow sensor from

http://www.aosong.com/en/products-38.html

It has some sample code which i think uses stm32 and is based on as different sensor. I want to work on this sensor using arduino.
It has a data sheet https://www.es.co.th/Schemetic/PDF/AFS01IA.PDF
which is totally different from all the tutorials i have searched on internet. I am unable to do anything with this data sheet.
After scanning address with i2c scanner i am getting address 0x40 but in the data sheet it says 0x15.
I am very new to arduino can someone guide me how to proceed ?

Try and check to run the project with the detected I²C address.

Post the data sheet of AFS01.

i have tried to run this code which i wrote from all the searching and tutorials i could find

#include <Wire.h>

#define SLA 0x15
#define RAD 0x2B
#define WAD 0x2A

int16_t data = 0;

void setup() {
    // put your setup code here, to run once:

    Serial.begin(9600);
    Wire.begin();

    Wire.beginTransmission(SLA);
 
    Wire.write(RAD);
 
    Wire.write(0x00);
    Wire.write(0x02);
 
    Wire.endTransmission();
   
}

void loop() {
   
   
    Wire.requestFrom(SLA, 2);
    int a = Wire.read();
    int b = Wire.read();
    Serial.println(a);
    Serial.println(b);

   delay(500);
    
}

if i use SLA as 0x15 i get -1 as repeated output and if i use SLA as 0x40 i get 0 as repeated output in serial monitot. I have attached data sheet in the post

Hi Azreelteal,
I've tested this code extensively, and it's doing exactly what it's supposed to :
Use - Wire.beginTransmission(0x40);

#include <Wire.h>

u8 Data[3];
u16 Value,Temp1,Temp2;

void setup() 
{
  Wire.begin(); 
  Serial.begin(9600);       
  delay (100);
  Wire.beginTransmission(0x40);
  Wire.write(0x10);
  Wire.write(0x00);
  Wire.endTransmission();
  delay (80);
}

void loop()
{
  Wire.requestFrom(0x40, 3);

  if (Wire.available() > 0)
  {
    Wire.readBytes(Data, 3);
  }

  Temp1 = ((Data[0])<<8);
  Temp2 = Data[1];
  
  Serial.print("Data[0]:");
  Serial.print(Data[0]);
  Serial.print(" Data[1]:");
  Serial.print(Data[1]);
  Serial.print(" Data[2]:");
  Serial.print(Data[2]);
  Serial.print("\n");

  Value = Temp1 | Temp2;

  Serial.print(Value);
  Serial.print("\n");
  delay(500);
} 

Feel free to give this code a quick review and inform me of any issues you may come across

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