GP v30 01: Electrochemical gas sensors
This is the basic code to manage and read an electrochemical gas sensor. 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 Gases PRO board v30 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 Gases PRO v30 technical guide. - Cycle time: 2 minutes

Code

1
/*
2
* ------------ [GP_v30_01] - Electrochemical gas sensors --------------
3
*
4
* Explanation: This is the basic code to manage and read an electrochemical
5
* gas sensor. These sensors include: CO, O2, O3, NO, NO2, SO2, NH3, H2, H2S,
6
* HCl, HCN, PH3, ETO and Cl2. Cycle time: 2 minutes
7
*
8
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
9
* http://www.libelium.com
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Version: 3.1
25
* Design: David Gascón
26
* Implementation: Alejandro Gállego
27
*/
28
29
#include <WaspSensorGas_Pro.h>
30
31
/*
32
* Define object for sensor: gas_PRO_sensor
33
* Input to choose board socket.
34
* Waspmote OEM. Possibilities for this sensor:
35
* - SOCKET_1
36
* - SOCKET_2
37
* - SOCKET_3
38
* - SOCKET_4
39
* - SOCKET_5
40
* - SOCKET_6
41
* P&S! Possibilities for this sensor:
42
* - SOCKET_A
43
* - SOCKET_B
44
* - SOCKET_C
45
* - SOCKET_F
46
*/
47
Gas gas_PRO_sensor(SOCKET_2);
48
49
float concentration; // Stores the concentration level in ppm
50
float temperature; // Stores the temperature in ºC
51
float humidity; // Stores the realitve humidity in %RH
52
float pressure; // Stores the pressure in Pa
53
54
void setup()
55
{
56
USB.println(F("Electrochemical gas sensor example"));
57
58
///////////////////////////////////////////
59
// 1. Turn on the sensors
60
///////////////////////////////////////////
61
62
// Power on the electrochemical sensor.
63
// If the gases PRO board is off, turn it on automatically.
64
gas_PRO_sensor.ON();
65
66
// First sleep time
67
// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
68
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
69
}
70
71
void loop()
72
{
73
///////////////////////////////////////////
74
// 2. Read sensors
75
///////////////////////////////////////////
76
77
// Read the electrochemical sensor and compensate with the temperature internally
78
concentration = gas_PRO_sensor.getConc();
79
80
// Read enviromental variables
81
temperature = gas_PRO_sensor.getTemp();
82
humidity = gas_PRO_sensor.getHumidity();
83
pressure = gas_PRO_sensor.getPressure();
84
85
// And print the values via USB
86
USB.println(F("***************************************"));
87
USB.print(F("Gas concentration: "));
88
USB.print(concentration);
89
USB.println(F(" ppm"));
90
USB.print(F("Temperature: "));
91
USB.print(temperature);
92
USB.println(F(" Celsius degrees"));
93
USB.print(F("RH: "));
94
USB.print(humidity);
95
USB.println(F(" %"));
96
USB.print(F("Pressure: "));
97
USB.print(pressure);
98
USB.println(F(" Pa"));
99
100
///////////////////////////////////////////
101
// 5. Sleep
102
///////////////////////////////////////////
103
104
// Go to deepsleep
105
// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
106
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
107
}
Copied!

Output

1
H#
2
Electrochemical gas sensor example
3
***************************************
4
Gas concentration: 1.0250854492 ppm
5
Temperature: 23.7700004577 Celsius degrees
6
RH: 43.6787109375 %
7
Pressure: 99772.0937500000 Pa
8
***************************************
9
Gas concentration: 0.9870300292 ppm
10
Temperature: 23.8099994659 Celsius degrees
11
RH: 43.6845703125 %
12
Pressure: 99764.1406250000 Pa
13
***************************************
14
Gas concentration: 0.9490051269 ppm
15
Temperature: 23.7999992370 Celsius degrees
16
RH: 43.6767578125 %
17
Pressure: 99769.3125000000 Pa
18
***************************************
19
Gas concentration: 1.0631408691 ppm
20
Temperature: 23.7700004577 Celsius degrees
21
RH: 43.6679687500 %
22
Pressure: 99775.5625000000 Pa
Copied!
Last modified 1yr ago