SCP v30 03: Pellistor gas sensors
This is the basic code to manage and read the pellistor sensor. These sensors include: methane (CH4) and other combustible gases.

Required Materials

1 x Waspmote 1 x Battery 1 x Smart Cities Board 1 x Temperature, Humidity and Pressure sensor BME280 1 x Pellistor 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_03] - Pellistor gas sensors ------------
3
4
Explanation: This is the basic code to manage and read the Pellistor
5
gas sensor with Smart Cities PRO board. Pellistor sensor list:
6
- CH4
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_C);
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("Pellistor CH4 example"));
66
USB.println(F("A BME sensor in socket A is also required"));
67
}
68
69
void loop()
70
{
71
///////////////////////////////////////////
72
// 1. Power on sensors
73
///////////////////////////////////////////
74
75
// switch on BME sensor (temperature, humidity and pressure)
76
bme.ON();
77
78
// Read enviromental variables
79
temperature = bme.getTemperature();
80
humidity = bme.getHumidity();
81
pressure = bme.getPressure();
82
83
// Power off the BME sensor
84
bme.OFF();
85
86
// Power on the Pellistor sensor.
87
// If the gases PRO board is off, turn it on automatically.
88
gas_sensor.ON();
89
90
// Pellistor gas sensor needs a warm up time at least 120 seconds
91
// To reduce the battery consumption, use deepSleep instead delay
92
// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
93
USB.println(F("Enter deep sleep mode to wait for Pellistor heating time..."));
94
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
95
USB.ON();
96
USB.println(F("wake up!!"));
97
98
///////////////////////////////////////////
99
// 2. Read sensors
100
///////////////////////////////////////////
101
102
// Read the Pellistor sensor and compensate with the temperature internally
103
concentration = gas_sensor.getConc(temperature);
104
105
// Power off the Pellistor sensor
106
gas_sensor.OFF();
107
108
// And print the values via USB
109
USB.println(F("***************************************"));
110
USB.print(F("Gas concentration: "));
111
USB.printFloat(concentration, 3);
112
USB.println(F(" % LEL"));
113
USB.print(F("Temperature: "));
114
USB.printFloat(temperature, 3);
115
USB.println(F(" Celsius degrees"));
116
USB.print(F("RH: "));
117
USB.printFloat(humidity, 3);
118
USB.println(F(" %"));
119
USB.print(F("Pressure: "));
120
USB.printFloat(pressure, 3);
121
USB.println(F(" Pa"));
122
USB.println(F("***************************************"));
123
124
///////////////////////////////////////////
125
// 3. Sleep
126
///////////////////////////////////////////
127
128
// Go to deepsleep.
129
// After 3 minutes, Waspmote wakes up thanks to the RTC Alarm
130
USB.println(F("Enter deep sleep mode"));
131
PWR.deepSleep("00:00:03:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
132
USB.ON();
133
USB.println(F("wake up!!"));
134
}
Copied!

Output

1
H#
2
Pellistor CH4 example
3
A BME sensor in socket A is also required
4
Enter deep sleep mode to wait for Pellistor heating time...
5
wake up!!
6
***************************************
7
Gas concentration: 0.000 % LEL
8
Temperature: 24.650 Celsius degrees
9
RH: 19.853 %
10
Pressure: 99428.687 Pa
11
***************************************
12
Enter deep sleep mode
Copied!
Last modified 1yr ago