Error In Interfacing Dust Sensor to Arduino

hello, i am a beginner of Arduino and I still dont know how to code properly, I was trying to write a small code for my Particle Sensor But I Got This Error
Code:

/*


 Interfacing Sharp Optical Dust Sensor GP2Y1014AU0F with Arduino


*/


#define measurePin = 0; //Connect dust sensor to Arduino A0 pin


#define ledPower = 7;   //Connect 3 led driver pins of dust sensor to Arduino D2


int samplingTime = 280; // time required to sample signal coming out   of the sensor


int deltaTime = 40; // 


int sleepTime = 9680;


float voMeasured = 0;


float calcVoltage = 0;


float dustDensity = 0;


void setup(){


  Serial.begin(9600);


  pinMode(ledPower,OUTPUT);


}


void loop(){


  digitalWrite(ledPower,LOW); // power on the LED


  delayMicroseconds(samplingTime);


  voMeasured = analogRead(measurePin); // read the dust value


  delayMicroseconds(deltaTime);


  digitalWrite(ledPower,HIGH); // turn the LED off


  delayMicroseconds(sleepTime);


  // 0 - 5V mapped to 0 - 1023 integer values


  // recover voltage


  calcVoltage = voMeasured * (5.0 / 1024.0);


  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/


  // Chris Nafis (c) 2012


  dustDensity = 170 * calcVoltage - 0.1;


  Serial.println(dustDensity); // unit: ug/m3


  delay(1000);


}

Error:

   digitalWrite(ledPower,HIGH); // turn the LED off
                        ^

exit status 1

Compilation error: expected primary-expression before '=' token
#define measurePin A0 //Connect dust sensor to Arduino A0 pin
#define ledPower 7 //Connect 3 led driver pins of dust sensor to Arduino D2 

Though D2 on an Uno is 2, not 7. What board are you using?

im using Arduino uno

i changed that but i still get

\.arduinoIDE-unsaved20231129-16752-r3xv92.bhm9e\sketch_dec29a\sketch_dec29a.ino:61:16: note: in expansion of macro 'ledPower'
   digitalWrite(ledPower,HIGH); // turn the LED off
                ^~~~~~~~
\.arduinoIDE-unsaved20231129-16752-r3xv92.bhm9e\sketch_dec29a\sketch_dec29a.ino:61:24: error: expected primary-expression before ',' token
   digitalWrite(ledPower,HIGH); // turn the LED off
                        ^

exit status 1

Compilation error: expected primary-expression before '=' token

Show your updated sketch.

/*


 Interfacing Sharp Optical Dust Sensor GP2Y1014AU0F with Arduino


*/


#define measurePin = 0; //Connect dust sensor to Arduino A0 pin


#define ledPower = 2;   //Connect 3 led driver pins of dust sensor to Arduino D2


int samplingTime = 280; // time required to sample signal coming out   of the sensor


int deltaTime = 40; // 


int sleepTime = 9680;


float voMeasured = 0;


float calcVoltage = 0;


float dustDensity = 0;


void setup(){


  Serial.begin(9600);


  pinMode(ledPower,OUTPUT);


}


void loop(){


  digitalWrite(ledPower,LOW); // power on the LED


  delayMicroseconds(samplingTime);


  voMeasured = analogRead(measurePin); // read the dust value


  delayMicroseconds(deltaTime);


  digitalWrite(ledPower,HIGH); // turn the LED off


  delayMicroseconds(sleepTime);


  // 0 - 5V mapped to 0 - 1023 integer values


  // recover voltage


  calcVoltage = voMeasured * (5.0 / 1024.0);


  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/


  // Chris Nafis (c) 2012


  dustDensity = 170 * calcVoltage - 0.1;


  Serial.println(dustDensity); // unit: ug/m3


  delay(1000);


}


Go back and read post 2 again.

i changed the #define ledPower 7 to #define ledPower 2, do have to change anything else?

@iliasoli
Change
#define measurePin = 0;
to
#define measurePin A0

Change
#define ledPower = 7;
to
#define ledPower 7

No equal sign and no semicolon

Then your original code will work with analog input A0 and digital pin 7

1 Like

Glad it worked
Have a nice day

1 Like

thanks

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