-
Notifications
You must be signed in to change notification settings - Fork 113
/
DustSensor.ino
95 lines (71 loc) · 2.57 KB
/
DustSensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Arduino Dust Sensor for Sharp_GP2Y1010AU
connect the sensor as follows :
*Please note both analogic and digital must be wired at the same time*
Analogic connector:
VCC >>> 5V
A >>> A1
GND >>> GND
Digital connector:
VCC >>> 5V
D >>> D1
GND >>> GND
Based on: http://www.dfrobot.com/wiki/index.php/Sharp_GP2Y1010AU
Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
Contribution: epierre
COnverted to 1.4 by Henrik Ekblad
The dust sensor used (see purchase guide for latest link):
http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5575069610&toolid=10001&campid=5337433187&customid=&icep_item=171259125886&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg
*/
#include <MySensor.h>
#include <SPI.h>
#define CHILD_ID_DUST 0
#define DUST_SENSOR_ANALOG_PIN 1
#define DUST_SENSOR_DIGITAL_PIN 1
unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
//VARIABLES
int val = 0; // variable to store the value coming from the sensor
float valDUST =0.0;
float lastDUST =0.0;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
MySensor gw;
MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL);
void setup()
{
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Dust Sensor", "1.2");
// Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_DUST, S_DUST);
pinMode(DUST_SENSOR_DIGITAL_PIN,OUTPUT); //light on dust sensor led
}
void loop()
{
digitalWrite(DUST_SENSOR_DIGITAL_PIN,LOW); // power on the LED
delayMicroseconds(280);
uint16_t voMeasured = analogRead(DUST_SENSOR_ANALOG_PIN);// Get DUST value
delayMicroseconds(40);
digitalWrite(DUST_SENSOR_DIGITAL_PIN,HIGH); // turn the LED off
// 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = voMeasured * (5.0 / 1024.0);
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
// Chris Nafis (c) 2012
dustDensity = (0.17 * calcVoltage - 0.1)*1000;
Serial.print("Raw Signal Value (0-1023): ");
Serial.print(voMeasured);
Serial.print(" - Voltage: ");
Serial.print(calcVoltage);
Serial.print(" - Dust Density: ");
Serial.println(dustDensity); // unit: ug/m3
if (ceil(dustDensity) != lastDUST) {
gw.send(dustMsg.set((int)ceil(dustDensity)));
lastDUST = ceil(dustDensity);
}
gw.sleep(SLEEP_TIME);
}