Skip to content

Commit 765f236

Browse files
authored
Merge pull request adafruit#1232 from ladyada/master
simple demo
2 parents 0a50b16 + a36613e commit 765f236

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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(",\tDust Density = ");
38+
Serial.print(dust_density);
39+
Serial.println(" mg/m3");
40+
delay(1000);
41+
}

0 commit comments

Comments
 (0)