NodeMCU ESP8266 read data from GP2Y1010AU0F not correct

images
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?

Fix what? It looks all okey. What atmosphere do You provide for the sensor?
To get none varying readings You need to use a controlled atmosphere. Normal "at home" atmosphere is not good enough.
Test increasing the 280 microsecond delay by a factor 10, 50, 100....

And where did these equations come from? What makes you think they're correct?

Also, your schematic shows you powering the sensor with 5V, and then interfacing it with a processor that runs at 3.3V. That's didn't do your ADC input any favours.

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