Development

» 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

/*  
 *  ------------  [SCP_v30_01] - Electrochemical gas sensors  -------------- 
 *  
 *  Explanation: 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. Cycle time: 2 minutes
 *  
 *  Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation, either version 3 of the License, or  
 *  (at your option) any later version.  
 *   
 *  This program is distributed in the hope that it will be useful,  
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 *  GNU General Public License for more details.  
 *   
 *  You should have received a copy of the GNU General Public License  
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  
 * 
 *  Version:           3.1
 *  Design:            David Gascón 
 *  Implementation:    Alejandro Gállego
 */

#include <WaspSensorCities_PRO.h>
#include <WaspSensorGas_Pro.h>

/*
 * Define object for sensor: gas_PRO_sensor
 * Input to choose board socket. 
 * Waspmote OEM. Possibilities for this sensor:
 * 	- SOCKET_1 
 * 	- SOCKET_3
 * 	- SOCKET_5
 * P&S! Possibilities for this sensor:
 * 	- SOCKET_B
 * 	- SOCKET_C
 * 	- SOCKET_F
 */
Gas gas_PRO_sensor(SOCKET_1);

float concentration;	// Stores the concentration level in ppm
float temperature;	// Stores the temperature in ºC
float humidity;		// Stores the realitve humidity in %RH
float pressure;		// Stores the pressure in Pa

void setup()
{
    USB.println(F("Electrochemical gas sensor example"));
    USB.println(F("A temperature, humidity and pressure sensor in socket 2 is also required"));
	
    ///////////////////////////////////////////
    // 1. Turn on the sensors
    /////////////////////////////////////////// 
	
	// Power on the socket 1 for the gas sensor
	SensorCitiesPRO.ON(SOCKET_1);
	// Power on the socket 2 for the temperature sensor
	SensorCitiesPRO.ON(SOCKET_2);
	
    // Power on the electrochemical sensor. It also boots the temperature sensor
    gas_PRO_sensor.ON();
	
    // First sleep time
    // After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
	
}	


void loop()
{

    ///////////////////////////////////////////
    // 2. Read sensors
    ///////////////////////////////////////////  

    // Read the electrochemical sensor and compensate with the temperature internally
    concentration = gas_PRO_sensor.getConc();

    // Read enviromental variables
    temperature = gas_PRO_sensor.getTemp();
    humidity = gas_PRO_sensor.getHumidity();
    pressure = gas_PRO_sensor.getPressure();

    // And print the values via USB
    USB.println(F("***************************************"));
    USB.print(F("Gas concentration: "));
    USB.print(concentration);
    USB.println(F(" ppm"));
    USB.print(F("Temperature: "));
    USB.print(temperature);
    USB.println(F(" Celsius degrees"));
    USB.print(F("RH: "));
    USB.print(humidity);
    USB.println(F(" %"));
    USB.print(F("Pressure: "));
    USB.print(pressure);
    USB.println(F(" Pa"));

    ///////////////////////////////////////////
    // 5. Sleep
    /////////////////////////////////////////// 

    // Go to deepsleep	
    // After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);

}


Output

H#
Electrochemical gas sensor example
A temperature, humidity and pressure sensor in socket 2 is also required
***************************************
Gas concentration: 1.3395874500 ppm
Temperature: 24.1499996185 Celsius degrees
RH: 43.3388671875 %
Pressure: 99751.7031250000 Pa
***************************************
Gas concentration: 1.0520660877 ppm
Temperature: 24.1399993896 Celsius degrees
RH: 43.3388671875 %
Pressure: 99747.3125000000 Pa
***************************************
Gas concentration: 0.9409783363 ppm
Temperature: 24.1499996185 Celsius degrees
RH: 43.3056640625 %
Pressure: 99750.0000000000 Pa
***************************************
Gas concentration: 0.5358583450 ppm
Temperature: 24.1499996185 Celsius degrees
RH: 43.3281250000 %
Pressure: 99749.1328125000 Pa

Quick Publish: