SCP v30 01: Electrochemical gas sensors
This is the basic code to manage and read an electrochemical gas sensor with Smart Cities PRO board. These sensors include: CO, O2, O3, NO, NO2, SO2, NH3, H2, H2S, HCl, HCN, PH3, ETO and Cl2.

Required Materials

1 x Waspmote 1 x Battery 1 x Smart Cities PRO board 1 x Temperature, Humidity and Pressure sensor BME280 1 x Electrochemical Gas Sensor [Calibrated]

Notes

- Remember to connect the battery to Waspmote for proper operation. - The connection of the sensor is described in the Smart Cities PRO technical guide. - Cycle time: 2 minutes

Code

1
/*
2
------------ [SCP_v30_01] - Electrochemical gas sensors --------------
3
4
Explanation: This is the basic code to manage and read an electrochemical
5
gas sensor with Smart Cities PRO board. Electrochemical sensor list:
6
- CO
7
- O2
8
- O3
9
- NO
10
- NO2
11
- SO2
12
- NH3
13
- H2
14
- H2S
15
- HCl
16
- HCN
17
- PH3
18
- ETO
19
- Cl2
20
21
Copyright (C) 2017 Libelium Comunicaciones Distribuidas S.L.
22
http://www.libelium.com
23
24
This program is free software: you can redistribute it and/or modify
25
it under the terms of the GNU General Public License as published by
26
the Free Software Foundation, either version 3 of the License, or
27
(at your option) any later version.
28
29
This program is distributed in the hope that it will be useful,
30
but WITHOUT ANY WARRANTY; without even the implied warranty of
31
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
GNU General Public License for more details.
33
34
You should have received a copy of the GNU General Public License
35
along with this program. If not, see <http://www.gnu.org/licenses/>.
36
37
Version: 3.2
38
Design: David Gascón
39
Implementation: Alejandro Gállego
40
*/
41
42
#include <WaspSensorCities_PRO.h>
43
44
/*
45
Define object for sensor: gas_sensor
46
Input to choose board socket.
47
Waspmote OEM. Possibilities for this sensor:
48
- SOCKET_1
49
- SOCKET_3
50
- SOCKET_5
51
P&S! Possibilities for this sensor:
52
- SOCKET_B
53
- SOCKET_C
54
- SOCKET_F
55
*/
56
Gas gas_sensor(SOCKET_F);
57
58
/*
59
Waspmote OEM. Possibilities for this sensor:
60
- SOCKET_1
61
- SOCKET_2
62
- SOCKET_3
63
- SOCKET_4
64
- SOCKET_5
65
P&S! Possibilities for this sensor:
66
- SOCKET_A
67
- SOCKET_B
68
- SOCKET_C
69
- SOCKET_E
70
- SOCKET_F
71
*/
72
bmeCitiesSensor bme(SOCKET_A);
73
74
// variables
75
float concentration; // Stores the concentration level in ppm
76
float temperature; // Stores the temperature in ºC
77
float humidity; // Stores the realitve humidity in %RH
78
float pressure; // Stores the pressure in Pa
79
80
void setup()
81
{
82
USB.println(F("Electrochemical gas sensor example"));
83
USB.println(F("A BME sensor in socket A is also required"));
84
}
85
86
void loop()
87
{
88
///////////////////////////////////////////
89
// 1. Read Temperature, humidity and pressure sensor (BME)
90
///////////////////////////////////////////
91
92
// switch off gas sensor for better performance
93
gas_sensor.OFF();
94
// switch on BME sensor (temperature, humidity and pressure)
95
bme.ON();
96
97
// Read enviromental variables
98
temperature = bme.getTemperature();
99
humidity = bme.getHumidity();
100
pressure = bme.getPressure();
101
102
// switch off BME sensor (temperature, humidity and pressure)
103
bme.OFF();
104
// switch on gas sensor again
105
gas_sensor.ON();
106
107
108
///////////////////////////////////////////
109
// 2. Read gas sensor
110
///////////////////////////////////////////
111
112
// Wait heating time
113
// some sensors demand at least one minute
114
// of heating time after switching them on
115
USB.println(F("Enter deep sleep mode to wait for electrochemical heating time..."));
116
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
117
USB.ON();
118
USB.println(F("wake up!!"));
119
120
// Read the electrochemical sensor and compensate with the temperature internally
121
concentration = gas_sensor.getConc(temperature);
122
123
// And print the values via USB
124
USB.println(F("***************************************"));
125
USB.print(F("Gas concentration: "));
126
USB.printFloat(concentration, 3);
127
USB.println(F(" ppm"));
128
USB.print(F("Temperature: "));
129
USB.printFloat(temperature, 3);
130
USB.println(F(" Celsius degrees"));
131
USB.print(F("RH: "));
132
USB.printFloat(humidity, 3);
133
USB.println(F(" %"));
134
USB.print(F("Pressure: "));
135
USB.printFloat(pressure, 3);
136
USB.println(F(" Pa"));
137
USB.println(F("***************************************"));
138
139
140
///////////////////////////////////////////
141
// 3. Sleep
142
///////////////////////////////////////////
143
144
// Go to deepsleep
145
// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
146
USB.println(F("Enter deep sleep mode"));
147
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
148
USB.ON();
149
USB.println(F("wake up!!"));
150
}
Copied!

Output

1
H#
2
Electrochemical gas sensor example
3
A BME sensor in socket A is also required
4
Enter deep sleep mode to wait for electrochemical heating time...
5
wake up!!
6
***************************************
7
Gas concentration: 0.163 ppm
8
Temperature: 24.430 Celsius degrees
9
RH: 19.965 %
10
Pressure: 99440.171 Pa
11
***************************************
12
Enter deep sleep mode
Copied!
Last modified 1yr ago