Last active
April 13, 2018 07:17
-
-
Save gguuss/6fe20f399e32c784a1e423218a3dae63 to your computer and use it in GitHub Desktop.
Arduino dust sensor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on instructions at: | |
// http://www.instructables.com/id/How-to-Interface-With-Optical-Dust-Sensor/ | |
int measurePin = A3; int ledPower = 12; int samplingTime = 280;int deltaTime = 40; | |
int sleepTime = 9680; float voMeasured = 0; float calcVoltage = 0; | |
float dustDensity = 0; | |
float readDust(){ | |
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); | |
calcVoltage = voMeasured * (5.0 / 1024); | |
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/ | |
// Chris Nafis (c) 2012 | |
return (0.17 * calcVoltage - 0.1)*1000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment