SCP v30 02: NDIR gas sensors
This is the basic code to manage and read the NDIR gas sensor with Smart Cities PRO board. These sensors include: CO2.

Required Materials

1 x Waspmote 1 x Battery 1 x Smart Cities PRO board 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 Smart Cities PRO technical guide. - Cycle time: 5 minutes

Code

1
/*
2
------------ [SCP_v30_02] - NDIR gas sensors ------------
3
4
Explanation: This is the basic code to manage and read the NDIR
5
gas sensor with Smart Cities PRO board. NDIR sensor list:
6
- CO2
7
8
Copyright (C) 2017 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.2
25
Design: David Gascón
26
Implementation: Alejandro Gállego
27
*/
28
29
#include <WaspSensorCities_PRO.h>
30
31
/*
32
Define object for sensor: gas_sensor
33
Input to choose board socket.
34
Waspmote OEM. Possibilities for this sensor:
35
- SOCKET_1
36
- SOCKET_3
37
- SOCKET_5
38
P&S! Possibilities for this sensor:
39
- SOCKET_B
40
- SOCKET_C
41
- SOCKET_F
42
*/
43
Gas gas_sensor(SOCKET_F);
44
45
/*
46
Waspmote OEM. Possibilities for this sensor:
47
- SOCKET_2
48
- SOCKET_4
49
P&S! Possibilities for this sensor:
50
- SOCKET_A
51
- SOCKET_B
52
- SOCKET_C
53
- SOCKET_E
54
- SOCKET_F
55
*/
56
bmeCitiesSensor bme(SOCKET_A);
57
58
float concentration; // Stores the concentration level in ppm
59
float temperature; // Stores the temperature in ºC
60
float humidity; // Stores the realitve humidity in %RH
61
float pressure; // Stores the pressure in Pa
62
63
void setup()
64
{
65
USB.println(F("NDIR CO2 example"));
66
USB.println(F("A BME sensor in socket A is also required"));
67
}
68
69
70
void loop()
71
{
72
///////////////////////////////////////////
73
// 1. Power on sensors
74
///////////////////////////////////////////
75
76
// switch on BME sensor (temperature, humidity and pressure)
77
bme.ON();
78
79
// Read enviromental variables
80
temperature = bme.getTemperature();
81
humidity = bme.getHumidity();
82
pressure = bme.getPressure();
83
84
// Power off the BME sensor
85
bme.OFF();
86
87
88
// Power on the NDIR sensor.
89
// If the gases PRO board is off, turn it on automatically.
90
gas_sensor.ON();
91
92
// NDIR gas sensor needs a warm up time at least 120 seconds
93
// To reduce the battery consumption, use deepSleep instead delay
94
// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
95
USB.println(F("Enter deep sleep mode to wait for NDIR heating time..."));
96
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
97
USB.ON();
98
USB.println(F("wake up!!"));
99
100
101
///////////////////////////////////////////
102
// 2. Read sensors
103
///////////////////////////////////////////
104
105
// Read the NDIR sensor and compensate with the temperature internally
106
concentration = gas_sensor.getConc(temperature);
107
108
// Power off the NDIR sensor
109
gas_sensor.OFF();
110
111
// And print the values via USB
112
USB.println(F("***************************************"));
113
USB.print(F("Gas concentration: "));
114
USB.printFloat(concentration, 3);
115
USB.println(F(" ppm"));
116
USB.print(F("Temperature: "));
117
USB.printFloat(temperature, 3);
118
USB.println(F(" Celsius degrees"));
119
USB.print(F("RH: "));
120
USB.printFloat(humidity, 3);
121
USB.println(F(" %"));
122
USB.print(F("Pressure: "));
123
USB.printFloat(pressure, 3);
124
USB.println(F(" Pa"));
125
USB.println(F("***************************************"));
126
127
128
///////////////////////////////////////////
129
// 3. Sleep
130
///////////////////////////////////////////
131
132
// Go to deepsleep.
133
// After 3 minutes, Waspmote wakes up thanks to the RTC Alarm
134
USB.println(F("Enter deep sleep mode"));
135
PWR.deepSleep("00:00:03:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
136
USB.ON();
137
USB.println(F("wake up!!"));
138
}
Copied!

Output

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