GP v30 02: NDIR gas sensors
This is the basic code to manage and read the NDIR gas sensor. These sensors include: CO2.

Required Materials

1 x Waspmote 1 x Battery 1 x Gases PRO board v30 1 x Temperature, Humidity and Pressure sensor BME280 1 x NDIR 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: 5 minutes

Code

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

Output

1
H#
2
NDIR CO2 example
3
***************************************
4
Gas concentration: 769.0821533203 ppm
5
Temperature: 23.7999992370 Celsius degrees
6
RH: 44.0214843750 %
7
Pressure: 99777.7031250000 Pa
8
***************************************
9
Gas concentration: 792.1773681640 ppm
10
Temperature: 23.7800006866 Celsius degrees
11
RH: 44.0195312500 %
12
Pressure: 99768.8828125000 Pa
13
***************************************
14
Gas concentration: 821.9870300292 ppm
15
Temperature: 23.7800006866 Celsius degrees
16
RH: 44.0126953125 %
17
Pressure: 99768.1250000000 Pa
18
***************************************
19
Gas concentration: 794.0631408691 ppm
20
Temperature: 23.7399997711 Celsius degrees
21
RH: 44.0019531250 %
22
Pressure: 99777.4687500000 Pa
Copied!
Last modified 1yr ago