intmeasurePin=A7;/*Connect dust sensor to Arduino Analog A7 pin*/
intmeasurePin=A7;/*Connect dust sensor to Arduino Analog A7 pin*/
intledPower=11;/*LED Power Pin*/
intledPower=11;/*LED Power Pin*/
unsignedintsamplingTime=280;/*the same as ints in that they store a 2 byte value*/
unsignedintsamplingTime=280;/*the same as ints in that they store a 2 byte value*/
unsignedintdeltaTime=40;/*Calculate time taken by loop.*/
unsignedintdeltaTime=40;/*Calculate time taken by loop.*/
unsignedintsleepTime=9680;/*Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)*/
unsignedintsleepTime=9680;/*Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)*/
floatvoMeasured=0;/*Voltage value*/
floatvoMeasured=0;/*Voltage value*/
floatcalcVoltage=0;/*Calculate Voltage*/
floatcalcVoltage=0;/*Calculate Voltage*/
floatdustDensity=0;/*Dust Density Size*/
floatdustDensity=0;/*Dust Density Size*/
voidsetup(){
voidsetup(){
Serial.begin(9600);/*initialize the Serial Monitor at a baud rate of 9600 for debugging purposes*/
Serial.begin(9600);/*initialize the Serial Monitor at a baud rate of 9600 for debugging purposes*/
pinMode(ledPower,OUTPUT);
pinMode(ledPower,OUTPUT);
}
}
voidloop(){
voidloop(){
digitalWrite(ledPower,LOW);/*turn on the IR LED*/
digitalWrite(ledPower,LOW);/*turn on the IR LED*/
delayMicroseconds(samplingTime);/*waiting for 0.28ms before taking a reading of the output voltage value*/
delayMicroseconds(samplingTime);/*waiting for 0.28ms before taking a reading of the output voltage value*/
voMeasured=analogRead(measurePin);/*Read the voltage values from the analog pin*/
voMeasured=analogRead(measurePin);/*Read the voltage values from the analog pin*/
delayMicroseconds(deltaTime);/*40-microsecond delay before turning the dust sensor led off*/
delayMicroseconds(deltaTime);/*40-microsecond delay before turning the dust sensor led off*/
digitalWrite(ledPower,HIGH);/*LED should be pulsed on once every 10ms. It means LED start to blinking*/
digitalWrite(ledPower,HIGH);/*LED should be pulsed on once every 10ms. It means LED start to blinking*/
delayMicroseconds(sleepTime);/*Sleep time because 10ms cycle = 10000 - 280 - 40 = 9680 microseconds. It means this delay loop in 1 sec*/
delayMicroseconds(sleepTime);/*Sleep time because 10ms cycle = 10000 - 280 - 40 = 9680 microseconds. It means this delay loop in 1 sec*/
calcVoltage=voMeasured*(5.0/1024);/* 0 - 5.0V mapped to 0 - 1023 integer values (if you use 3.3V, map 0 - 3.3V to 0 - 1023) */
dustDensity=0.17*calcVoltage-0.1;/* Using linear eqaution for calculate Dust Density*/