Skip to content

Commit dcb0bab

Browse files
committed
Dust sensor added. Thanks epierre.
1 parent 95467c4 commit dcb0bab

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

libraries/MySensors/MyMessage.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ typedef enum {
3838
V_RAINRATE, V_WIND, V_GUST, V_DIRECTION, V_UV, V_WEIGHT, V_DISTANCE,
3939
V_IMPEDANCE, V_ARMED, V_TRIPPED, V_WATT, V_KWH, V_SCENE_ON, V_SCENE_OFF,
4040
V_HEATER, V_HEATER_SW, V_LIGHT_LEVEL, V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5,
41-
V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME, V_LOCK_STATUS
41+
V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME, V_LOCK_STATUS,
42+
V_DUST_LEVEL
4243
} data;
4344

4445
// Type of internal messages (for internal messages)
@@ -53,7 +54,7 @@ typedef enum {
5354
typedef enum {
5455
S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND,
5556
S_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE,
56-
S_ARDUINO_REPEATER_NODE, S_LOCK, S_IR, S_WATER, S_AIR_QUALITY, S_CUSTOM
57+
S_ARDUINO_REPEATER_NODE, S_LOCK, S_IR, S_WATER, S_AIR_QUALITY, S_CUSTOM, S_DUST
5758
} sensor;
5859

5960
// Type of data stream (for streamed message)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Arduino Dust Sensort
3+
4+
connect the sensor as follows :
5+
6+
VCC >>> 5V
7+
A >>> A0
8+
GND >>> GND
9+
10+
Based on: http://www.dfrobot.com/wiki/index.php/Sharp_GP2Y1010AU
11+
Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
12+
Contribution: epierre
13+
COnverted to 1.4 by Henrik Ekblad
14+
15+
The dust sensor used (see purchase guide for latest link):
16+
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
17+
18+
*/
19+
20+
#include <MySensor.h>
21+
#include <SPI.h>
22+
23+
#define CHILD_ID_DUST 0
24+
#define DUST_SENSOR_ANALOG_PIN 1
25+
26+
unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
27+
//VARIABLES
28+
int val = 0; // variable to store the value coming from the sensor
29+
float valDUST =0.0;
30+
float lastDUST =0.0;
31+
int samplingTime = 280;
32+
int deltaTime = 40;
33+
int sleepTime = 9680;
34+
float voMeasured = 0;
35+
float calcVoltage = 0;
36+
float dustDensity = 0;
37+
38+
MySensor gw;
39+
MyMessage dustMsg(CHILD_ID_DUST, V_DUST_LEVEL);
40+
41+
void setup()
42+
{
43+
gw.begin();
44+
45+
// Send the sketch version information to the gateway and Controller
46+
gw.sendSketchInfo("Dust Sensor", "1.1");
47+
48+
// Register all sensors to gateway (they will be created as child devices)
49+
gw.present(CHILD_ID_DUST, S_DUST);
50+
51+
}
52+
53+
void loop()
54+
{
55+
uint16_t voMeasured = analogRead(DUST_SENSOR_ANALOG_PIN);// Get DUST value
56+
57+
// 0 - 5V mapped to 0 - 1023 integer values
58+
// recover voltage
59+
calcVoltage = voMeasured * (5.0 / 1024.0);
60+
61+
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
62+
// Chris Nafis (c) 2012
63+
dustDensity = (0.17 * calcVoltage - 0.1)*1000;
64+
65+
Serial.print("Raw Signal Value (0-1023): ");
66+
Serial.print(voMeasured);
67+
68+
Serial.print(" - Voltage: ");
69+
Serial.print(calcVoltage);
70+
71+
Serial.print(" - Dust Density: ");
72+
Serial.println(dustDensity); // unit: ug/m3
73+
74+
if (ceil(dustDensity) != lastDUST) {
75+
gw.send(dustMsg.set((int)ceil(dustDensity)));
76+
lastDUST = ceil(dustDensity);
77+
}
78+
79+
gw.sleep(SLEEP_TIME);
80+
}

0 commit comments

Comments
 (0)