Skip to content

Commit 79fbc2c

Browse files
committed
New dust sensor alternates
1 parent 3b85459 commit 79fbc2c

File tree

3 files changed

+172
-5
lines changed

3 files changed

+172
-5
lines changed

dustSensor/dustSensor.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A0: A/D: Dust Sensor Analog Signal
77
D2: INT0 I/P: Dust Sensor Interrupt - Link to D9
88
D9: Timer 1 OC1A PWM O/P: Dust Sensor Samples - Link to D2
99
D10: Timer 1 OC1B PWM O/P: Dust Sensor LED Pulses
10+
LED Power: 5V to device pin 1 through a 150ohm resistor
1011
*/
1112

1213
#define VOLTAGE 5.0 // Arduino supply voltage
@@ -106,15 +107,19 @@ void loop() // run over and over again
106107

107108
float latest_dust = latest_reading * (VOLTAGE / 1023.0);
108109
float average_dust = average_reading * (VOLTAGE/ 1023.0);
109-
/* For text to the serial console
110-
Serial.print("Latest Dust Reading (V): ");
110+
/* For text to the serial console */
111+
Serial.print("TIMER1: ");
112+
Serial.print("Voltage: ");
111113
Serial.print(latest_dust);
112-
Serial.print("\t\tAverage Dust Reading (V): ");
114+
Serial.print("\t - Latest reading: ");
115+
Serial.print(latest_reading);
116+
Serial.print("\tAverage Dust Reading (V): ");
113117
Serial.println(average_dust);
114-
*/
115-
/* For data for the Serial plotter */
118+
119+
/* For data for the Serial plotter
116120
Serial.print(latest_dust);
117121
Serial.print("\t");
118122
Serial.println(average_dust);
123+
*/
119124
}
120125
}

dustSensor_noInt/dustSensor_noInt.ino

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Standalone Sketch to use with a Arduino Fio and a
3+
Sharp Optical Dust Sensor GP2Y1010AU0F
4+
5+
Blog: http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
6+
Code: https://github.com/Trefex/arduino-airquality/
7+
For Pin connections, please check the Blog or the github project page
8+
Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
9+
Changelog:
10+
2012-Dec-01: Cleaned up code
11+
2012-Dec-13: Converted mg/m3 to ug/m3 which seems to be the accepted standard
12+
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
13+
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
14+
to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
15+
*/
16+
17+
#define VOLTAGE 5.0 // Arduino supply voltage
18+
19+
int measurePin = A0;
20+
int ledPower = 10;
21+
22+
int samplingTime = 280;
23+
int deltaTime = 40;
24+
int sleepTime = 9680;
25+
26+
float voMeasured = 0;
27+
float calcVoltage = 0;
28+
float dustDensity = 0;
29+
30+
void setup(){
31+
Serial.begin(115200);
32+
pinMode(ledPower,OUTPUT);
33+
}
34+
35+
void loop(){
36+
digitalWrite(ledPower,LOW); // power on the LED
37+
delayMicroseconds(samplingTime);
38+
39+
voMeasured = analogRead(measurePin); // read the dust value
40+
41+
delayMicroseconds(deltaTime);
42+
digitalWrite(ledPower,HIGH); // turn the LED off
43+
delayMicroseconds(sleepTime);
44+
45+
// 0 - 5.0V mapped to 0 - 1023 integer values
46+
calcVoltage = voMeasured * (VOLTAGE / 1024);
47+
48+
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
49+
// Chris Nafis (c) 2012
50+
dustDensity = (0.17 * calcVoltage - 0.1)*1000;
51+
Serial.print("delayMu(): ");
52+
Serial.print("Voltage: ");
53+
Serial.print(calcVoltage);
54+
55+
Serial.print("\t Latest reading: ");
56+
Serial.print(voMeasured);
57+
58+
Serial.print("\t Dust Density [ug/m3]: ");
59+
Serial.println(dustDensity);
60+
61+
delay(1000);
62+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Standalone Sketch to use with a Arduino Fio and a
3+
Sharp Optical Dust Sensor GP2Y1010AU0F
4+
5+
Blog: http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
6+
Code: https://github.com/Trefex/arduino-airquality/
7+
For Pin connections, please check the Blog or the github project page
8+
Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
9+
Changelog:
10+
2012-Dec-01: Cleaned up code
11+
2012-Dec-13: Converted mg/m3 to ug/m3 which seems to be the accepted standard
12+
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
13+
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
14+
to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
15+
*/
16+
17+
#define VOLTAGE 5.0 // Arduino supply voltage
18+
19+
int measurePin = A0;
20+
int ledPower = 10;
21+
22+
int samplingTime = 280;
23+
int deltaTime = 40;
24+
int sleepTime = 9680;
25+
26+
float voMeasured = 0;
27+
float calcVoltage = 0;
28+
float dustDensity = 0;
29+
30+
const int numReadings = 100; // samples are taken at 100Hz so calculate average over 1sec
31+
32+
int readings[numReadings]; // the readings from the analog input
33+
int readIndex = 0; // the index of the current reading
34+
long int total = 0; // the running total
35+
int latest_reading = 0; // the latest reading
36+
int average_reading = 0; // the average reading
37+
38+
void setup(){
39+
Serial.begin(115200);
40+
pinMode(ledPower,OUTPUT);
41+
// Initialise sample buffer
42+
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
43+
readings[thisReading] = 0;
44+
}
45+
}
46+
47+
// Dust sample interrupt service routine
48+
void takeReading() {
49+
// subtract the last reading:
50+
total = total - readings[readIndex];
51+
// read from the sensor:
52+
latest_reading = analogRead(dustPin);
53+
readings[readIndex] = latest_reading;
54+
// add the reading to the total:
55+
total = total + latest_reading;
56+
// advance to the next position in the array:
57+
readIndex = readIndex + 1;
58+
59+
// if we're at the end of the array...wrap around to the beginning:
60+
if (readIndex >= numReadings) readIndex = 0;
61+
62+
// calculate the average:
63+
average_reading = total / numReadings; // Seems to work OK with integer maths - but total does need to be long int
64+
}
65+
66+
uint32_t timer = millis();
67+
68+
void loop(){
69+
// if millis() or timer wraps around, we'll just reset it
70+
if (timer > millis()) timer = millis();
71+
// approximately every second or so, print out the dust reading
72+
if (millis() - timer > 1000) {
73+
timer = millis(); // reset the timer
74+
digitalWrite(ledPower,LOW); // power on the LED
75+
delayMicroseconds(samplingTime);
76+
77+
//voMeasured = analogRead(measurePin); // read the dust value
78+
79+
delayMicroseconds(deltaTime);
80+
digitalWrite(ledPower,HIGH); // turn the LED off
81+
delayMicroseconds(sleepTime);
82+
83+
// 0 - 5.0V mapped to 0 - 1023 integer values
84+
calcVoltage = latest_reading * (VOLTAGE / 1023.0);
85+
86+
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
87+
// Chris Nafis (c) 2012
88+
dustDensity = (0.17 * calcVoltage - 0.1)*1000;
89+
90+
Serial.print("delayMu(): ");
91+
Serial.print("Voltage: ");
92+
Serial.print(latest_reading);
93+
94+
Serial.print("\t - A0: ");
95+
Serial.print(calcVoltage);
96+
97+
Serial.print(" - Dust Density [ug/m3]: ");
98+
Serial.println(dustDensity);
99+
}
100+
}

0 commit comments

Comments
 (0)