added link to https://github.com/mickey9801/GP2Y1010AU0F
[Arduino] / GP2Y10 / GP2Y10.ino
1 /**
2  * Example for using GP2Y1010AU0F Dust Sensor library
3  * Created by Mickey Chan
4  * library from https://github.com/mickey9801/GP2Y1010AU0F
5  */
6
7 #include <GP2Y1010AU0F.h>
8
9 int measurePin = A0;   // Connect dust sensor analog measure pin to Arduino A0 pin
10 int ledPin     = 2;    // Connect dust sensor LED pin to Arduino pin 2
11
12 GP2Y1010AU0F dustSensor(ledPin, measurePin); // Construct dust sensor global object
13
14 void setup() {
15   Serial.begin(115200);
16   //Serial.println(F("GP2Y1010AU0F Dust Sensor Library Example"));
17
18   dustSensor.begin();
19 }
20
21
22 #define samples 10
23 float dustDensity = 0;
24 int x;
25
26 void loop() {
27
28   dustDensity = 0;
29   for (x = 0; x < samples; x++) {
30
31     dustDensity += dustSensor.read();
32     delay( 1000 / samples );
33
34   }
35   
36   Serial.print("Dust_Density=");
37   Serial.println(dustDensity / samples);
38
39 }