-
Notifications
You must be signed in to change notification settings - Fork 113
/
AirQuality-CO-NO2-NH3.ino
216 lines (186 loc) · 6.86 KB
/
AirQuality-CO-NO2-NH3.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <[email protected]>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Air Quality Sensors for MICS-6814
*
* Wiring:
*
* 5V
* GDN
* SDA -> A4 (on nano)
* SCL -> A5 (on nano)
*
* based on Jacky Zhang, Embedded Software Engineer [email protected]
* Contribution: epierre
*
* Precaution:
* The gasses detected by these gas sensors can be deadly in high concentrations. Always be careful to perform gas tests in well ventilated areas.
*
* Note:
* THESE GAS SENSOR MODULES ARE NOT DESIGNED FOR OR APPROVED FOR ANY APPLICATION INVOLVING HEALTH OR HUMAN SAFETY. THESE GAS SENSOR MODULES ARE FOR EXPERIMENTAL PURPOSES ONLY.*
**/
#include <SPI.h>
#include <MySensor.h>
#include <Wire.h>
#include <MutichannelGasSensor.h>
/**********************Application Related Macros**********************************/
#define GAS_CL2 (0)
#define GAS_O3 (1)
#define GAS_CO2 (2)
#define GAS_CO (3)
#define GAS_NH4 (4)
#define GAS_CH3 (6)
#define GAS_CH3_2CO (7)
#define GAS_H2 (8)
#define GAS_C2H5OH (9) //Alcohol, Ethanol
#define GAS_C4H10 (10)
#define GAS_LPG (11)
#define GAS_Smoke (12)
#define GAS_CO_sec (13)
#define GAS_LPG_sec (14)
#define GAS_CH4 (15)
#define GAS_NO2 (16)
#define GAS_SO2 (17)
#define GAS_C7H8 (18) //Toluene
#define GAS_H2S (19) //Hydrogen Sulfide
#define GAS_NH3 (20) //Ammonia
#define GAS_C6H6 (21) //Benzene
#define GAS_C3H8 (22) //Propane
#define GAS_NHEX (23) //n-hexa
#define GAS_HCHO (24) //HCHO / CH2O Formaldehyde
/*****************************Globals***********************************************/
unsigned long SLEEP_TIME = 600; // Sleep time between reads (in seconds)
//VARIABLES
int val = 0; // variable to store the value coming from the sensor
float calcVoltage = 0;
boolean metric = true;
//test
float a=0;
boolean pcReceived = false;
#define CHILD_ID_NH3 0
#define CHILD_ID_CO 1
#define CHILD_ID_NO2 2
#define CHILD_ID_C3H8 3
#define CHILD_ID_C4H10 4
#define CHILD_ID_CH4 5
#define CHILD_ID_H2 6
#define CHILD_ID_C2H5OH 7
MySensor gw; // initializing arduino
MyMessage msg_nh3(CHILD_ID_NH3, V_UNIT_PREFIX);
MyMessage msg_co(CHILD_ID_CO, V_UNIT_PREFIX);
MyMessage msg_no2(CHILD_ID_NO2, V_UNIT_PREFIX);
MyMessage msg_c3h8(CHILD_ID_C3H8, V_UNIT_PREFIX);
MyMessage msg_c4h10(CHILD_ID_C4H10, V_UNIT_PREFIX);
MyMessage msg_ch4(CHILD_ID_CH4, V_UNIT_PREFIX);
MyMessage msg_h2(CHILD_ID_H2, V_UNIT_PREFIX);
MyMessage msg_c2h5oh(CHILD_ID_C2H5OH, V_UNIT_PREFIX);
int val_nh3=0;
int val_co=0;
int val_no2=0;
int val_c3h8=0;
int val_c4h10=0;
int val_ch4=0;
int val_h2=0;
int val_c2h5oh=0;
void setup()
{
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("AIQ Multi Sensors MiCS", "1.0");
// Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_NH3, S_AIR_QUALITY);
gw.send(msg_nh3.set("ppm"));
gw.present(CHILD_ID_CO, S_AIR_QUALITY);
gw.send(msg_co.set("ppm"));
gw.present(CHILD_ID_NO2, S_AIR_QUALITY);
gw.send(msg_no2.set("ppm"));
gw.present(CHILD_ID_C3H8, S_AIR_QUALITY);
gw.send(msg_c3h8.set("ppm"));
gw.present(CHILD_ID_C4H10, S_AIR_QUALITY);
gw.send(msg_c4h10.set("ppm"));
gw.present(CHILD_ID_CH4, S_AIR_QUALITY);
gw.send(msg_ch4.set("ppm"));
gw.present(CHILD_ID_H2, S_AIR_QUALITY);
gw.send(msg_h2.set("ppm"));
gw.present(CHILD_ID_C2H5OH, S_AIR_QUALITY);
gw.send(msg_c2h5oh.set("ppm"));
mutichannelGasSensor.begin(0x04);//the default I2C address of the slave is 0x04
mutichannelGasSensor.powerOn();
}
void loop() //code written in here will be in a loop
{
float c;
c = mutichannelGasSensor.measure_NH3();
if((c>=0)&&(c!=val_nh3)) {
Serial.print("NH3: ");
Serial.print(c);
val_nh3=c;
gw.send(msg_nh3.set(c,3));
}
c = mutichannelGasSensor.measure_CO();
if((c>=0)&&(c!=val_co)) {
Serial.print("CO: ");
Serial.print(c);
val_co=c;
gw.send(msg_co.set(c,3));
}
c = mutichannelGasSensor.measure_NO2();
if((c>=0)&&(c!=val_no2)) {
Serial.print("NO2: ");
Serial.print(c);
val_no2=c;
gw.send(msg_no2.set(c,3));
}
/*c = mutichannelGasSensor.measure_C3H8();
Serial.print("The concentration of C3H8 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
gw.send(msg_c3h8.set(c,3));
c = mutichannelGasSensor.measure_C4H10();
Serial.print("The concentration of C4H10 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
gw.send(msg_c4h10.set(c,3));
c = mutichannelGasSensor.measure_CH4();
Serial.print("The concentration of CH4 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
gw.send(msg_ch4.set(c,3));
c = mutichannelGasSensor.measure_H2();
Serial.print("The concentration of H2 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
gw.send(msg_h2.set(c,3));
c = mutichannelGasSensor.measure_C2H5OH();
Serial.print("The concentration of C2H5OH is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
gw.send(msg_c2h5oh.set(c,3));*/
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
gw.sleep(SLEEP_TIME*4); //sleep for: sleepTime
}