Commit 90ae8d68 authored by Gayan Kavinda Gamlath's avatar Gayan Kavinda Gamlath 😂

Dust Update Code

parent a1f6cf0e
int measurePin = A7; /*Connect dust sensor to Arduino Analog A7 pin*/ int measurePin = A7; /*Connect dust sensor to Arduino Analog A7 pin*/
int ledPower = 11; /*LED Power Pin*/ int ledPower = 11; /*LED Power Pin*/
unsigned int samplingTime = 280; /*the same as ints in that they store a 2 byte value*/ unsigned int samplingTime = 280; /*the same as ints in that they store a 2 byte value*/
unsigned int deltaTime = 40; /*Calculate time taken by loop.*/ unsigned int deltaTime = 40; /*Calculate time taken by loop.*/
unsigned int sleepTime = 9680; /*Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)*/ unsigned int sleepTime = 9680; /*Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)*/
float voMeasured = 0; /*Voltage value*/ float voMeasured = 0; /*Voltage value*/
float calcVoltage = 0; /*Calculate Voltage*/ float calcVoltage = 0; /*Calculate Voltage*/
float dustDensity = 0; /*Dust Density Size*/ float dustDensity = 0; /*Dust Density Size*/
void setup() { void setup() {
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);
} }
void loop() { void loop() {
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*/
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment