File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
GP2Y1014AU0F_demos/GP2Y1014AU Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+
Original file line number Diff line number Diff line change
1
+
Original file line number Diff line number Diff line change
1
+ #define dustPin A0 // Black wire
2
+ #define ledPin 5 // White wire
3
+
4
+ #define ANALOG_VOLTAGE 3.3 // analog top of range
5
+
6
+ // Yellow, Green wire connects to ground
7
+ // Blue wire connects to 5V via 150 ohm resistor (see DS)
8
+ // Red wire connects to 5V
9
+
10
+ void setup ()
11
+ {
12
+ Serial.begin (115200 );
13
+ while (!Serial) delay (100 );
14
+
15
+ Serial.println (" GP2Y1010AU0F Sensor demo" );
16
+ pinMode (ledPin, OUTPUT);
17
+ }
18
+
19
+
20
+ void loop ()
21
+ {
22
+ float output_voltage, dust_density;
23
+
24
+ digitalWrite (ledPin, LOW); // power on the LED
25
+ delayMicroseconds (280 ); // Wait 0.28ms according to DS
26
+ // take analog reading
27
+ output_voltage = analogRead (dustPin);
28
+ delay (1 );
29
+
30
+ digitalWrite (ledPin, HIGH); // turn the LED off
31
+
32
+ output_voltage = (output_voltage / 1023 ) * ANALOG_VOLTAGE;
33
+ dust_density = (0.18 * output_voltage) - 0.1 ;
34
+
35
+ Serial.print (" Voltage = " );
36
+ Serial.print (output_voltage);
37
+ Serial.print (" ,\t Dust Density = " );
38
+ Serial.print (dust_density);
39
+ Serial.println (" mg/m3" );
40
+ delay (1000 );
41
+ }
You can’t perform that action at this time.
0 commit comments