dust sensor with averageing
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 7 Jan 2020 14:49:34 +0000 (15:49 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 7 Jan 2020 14:49:34 +0000 (15:49 +0100)
GP2Y10/GP2Y10.ino [new file with mode: 0644]

diff --git a/GP2Y10/GP2Y10.ino b/GP2Y10/GP2Y10.ino
new file mode 100644 (file)
index 0000000..4478393
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Example for using GP2Y1010AU0F Dust Sensor library
+ * Created by Mickey Chan
+ */
+
+#include <GP2Y1010AU0F.h>
+
+int measurePin = A0;   // Connect dust sensor analog measure pin to Arduino A0 pin
+int ledPin     = 2;    // Connect dust sensor LED pin to Arduino pin 2
+
+GP2Y1010AU0F dustSensor(ledPin, measurePin); // Construct dust sensor global object
+
+void setup() {
+  Serial.begin(115200);
+  //Serial.println(F("GP2Y1010AU0F Dust Sensor Library Example"));
+
+  dustSensor.begin();
+}
+
+
+#define samples 10
+float dustDensity = 0;
+int x;
+
+void loop() {
+
+  dustDensity = 0;
+  for (x = 0; x < samples; x++) {
+
+    dustDensity += dustSensor.read();
+    delay( 1000 / samples );
+
+  }
+  
+  Serial.print("Dust_Density=");
+  Serial.println(dustDensity / samples);
+
+}