I use ESP8266 connect to GP2Y1010AU0F like image. I use this code for run ESP8266.
int dustPin = A0;
int ledPin = 4;
float voltsMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
void setup()
{
Serial.begin(57600);
pinMode(ledPin,OUTPUT);
}
void loop()
{
digitalWrite(ledPin,LOW); // power on the LED
delayMicroseconds(280);
voltsMeasured = analogRead(dustPin); // read the dust value
delayMicroseconds(40);
digitalWrite(ledPin,HIGH); // turn the LED off
delayMicroseconds(9680);
//measure your 5v and change below
calcVoltage = voltsMeasured * (3.3 / 1024.0);
dustDensity = 0.17 * calcVoltage - 0.1;
Serial.println("GP2Y1010AU0F readings");
Serial.print("Raw Signal Value = ");
Serial.println(voltsMeasured);
Serial.print("Voltage = ");
Serial.println(calcVoltage);
Serial.print("Dust Density = ");
Serial.println(dustDensity); // mg/m3
Serial.println("");
delay(1000);
}
It show output like this which Dust Density is not correct.
GP2Y1010AU0F readings
Raw Signal Value = 104.00
Voltage = 0.34
Dust Density = -0.04
GP2Y1010AU0F readings
Raw Signal Value = 110.00
Voltage = 0.35
Dust Density = -0.04
GP2Y1010AU0F readings
Raw Signal Value = 111.00
Voltage = 0.36
Dust Density = -0.04
How to fix it?