Development

Sensors / Gases PRO Board:

» GP 17: AQM

This is the basic code to manage and read CO, O3, SO2 and NO2 gas sensors. This gases are commonly meassured in air quality monitors. The concentration and the enviromental variables will be stored in a frame. Cycle time: 5 minutes.

Required Materials

1 x Waspmote
1 x Battery
1 x Gases PRO board
1 x Temperature, Humidity and Pressure sensor BME280
1 x CO Gas Sensor [Calibrated]
1 x O3 Gas Sensor [Calibrated]
1 x SO2 Gas Sensor [Calibrated]
1 x NO2 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 technical guide.
Cycle time: 5 minutes

Code

/*  
 *  ------------  [GP_017] - AQM  -------------- 
 *  
 *  Explanation: This is the basic code to manage and read CO, O3, SO2 and NO2
 *  gas sensors. This gases are commonly meassured in air quality monitors.
 *  The concentration and the enviromental variables will be stored in a 
 *  frame. Cycle time: 5 minutes.
 *  
 *  Copyright (C) 2015 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:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Alejandro Gállego
 */

#include <WaspSensorGas_Pro.h>
#include <WaspFrame.h>

// Each object will be used by each gas sensor
Gas CO(SOCKET_1);
Gas O3(SOCKET_3);
Gas SO2(SOCKET_4);
Gas NO2(SOCKET_6);


float conc_CO;		// Stores the concentration level of CO in ppm
float conc_O3;		// Stores the concentration level of O3 in ppm
float conc_SO2;		// Stores the concentration level of SO2 in ppm
float conc_NO2;		// Stores the concentration level of NO2 in ppm
float temperature;	// Stores the temperature in ºC
float humidity;		// Stores the realitve humidity in %RH
float pressure;		// Stores the pressure in Pa

char node_ID[] = "AQI_example";

void setup()
{
	USB.println(F("AQI example"));
	// Set the Waspmote ID
	frame.setID(node_ID); 
}	


void loop()
{
	///////////////////////////////////////////
	// 1. Turn on sensors
	///////////////////////////////////////////  
	
	// Power on the sensors. 
	// If the gases PRO board is off, turn it on automatically.
	CO.ON();
	O3.ON();
	SO2.ON();
	NO2.ON();
	
	// The sensor needs time to warm up and get a response from gas
	// To reduce the battery consumption, use deepSleep instead delay
	// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
	PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
	
	
	///////////////////////////////////////////
	// 2. Read sensors
	///////////////////////////////////////////  
	
	// Read the sensors and compensate with the temperature internally
	conc_CO = CO.getConc();
	conc_O3 = O3.getConc();
	conc_SO2 = SO2.getConc();
	conc_NO2 = NO2.getConc();
	
	// Read enviromental variables
	// In this case, CO objet has been used.
	// O3, SO2 or NO2 objects could be used with the same result
	temperature = CO.getTemp();
	humidity = CO.getHumidity();
	pressure = CO.getPressure();
	
	
	///////////////////////////////////////////
	// 3. Turn off the sensors
	/////////////////////////////////////////// 
	
	// Power off the sensors sensor. If there aren't more gas sensors powered, 
	// turn off the board automatically
	CO.OFF();
	O3.OFF();
	SO2.OFF();
	NO2.OFF();
	
	
	///////////////////////////////////////////
	// 4. Create ASCII frame
	/////////////////////////////////////////// 
	
	// Create new frame (ASCII)
	frame.createFrame(ASCII);
	
	// Add CO concentration
	frame.addSensor(SENSOR_GP_CO, conc_CO);
	// Add O3 concentration
	frame.addSensor(SENSOR_GP_O3, conc_O3);
	// Add SO2 concentration
	frame.addSensor(SENSOR_GP_SO2, conc_SO2);
	// Add NO2 concentration
	frame.addSensor(SENSOR_GP_NO2, conc_NO2);
	// Add temperature
	frame.addSensor(SENSOR_GP_TC, temperature);
	// Add humidity
	frame.addSensor(SENSOR_GP_HUM, humidity);
	// Add pressure
	frame.addSensor(SENSOR_GP_PRES, pressure);	
	
	// Show the frame
	frame.showFrame();
	
	
	///////////////////////////////////////////
	// 5. Sleep
	/////////////////////////////////////////// 
	
	// Go to deepsleep 
	// After 3 minutes, Waspmote wakes up thanks to the RTC Alarm
	PWR.deepSleep("00:00:03:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
	
}

Output

E#
AQI example
===============================
Current ASCII Frame:
Length: 121
Frame Type: 128
frame (HEX): 3C3D3E800723333832353337333638234151495F6578616D706C6523302347505F434F3A31322E3538312347505F4F333A302E3135302347505F534F323A302E3334302347505F4E4F323A302E3130322347505F54433A32382E3636302347505F48554D3A34302E35302347505F505245533A393830363023
frame (STR): <=>€#382537368#AQI_example#0#GP_CO:12.581#GP_O3:0.150#GP_SO2:0.340#GP_NO2:0.102#GP_TC:28.660#GP_HUM:40.50#GP_PRES:98060#
===============================
===============================
Current ASCII Frame:
Length: 121
Frame Type: 128
frame (HEX): 3C3D3E800723333832353337333638234151495F6578616D706C6523312347505F434F3A31322E3132302347505F4F333A302E3039392347505F534F323A302E3330312347505F4E4F323A302E3132332347505F54433A32382E3637302347505F48554D3A34302E34372347505F505245533A393830353923
frame (STR): <=>€#382537368#AQI_example#1#GP_CO:12.120#GP_O3:0.099#GP_SO2:0.301#GP_NO2:0.123#GP_TC:28.670#GP_HUM:40.47#GP_PRES:98059#
===============================

Quick Publish: