Development

Sensors / Gases PRO Board:

» GP 02: CO2

This is the basic code to manage and read the carbon dioxide (CO2) gas sensor. 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 CO2 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_02] - CO2 ------------
 *  
 *  Explanation: This is the basic code to manage and read the carbon dioxide
 *  (CO2) gas sensor. 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.2 
 *  Design:            David Gascón 
 *  Implementation:    Alejandro Gállego
 */

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

/*
 * Define object for sensor: CO2
 * Input to choose board socket. 
 * Waspmote OEM. Possibilities for this sensor:
 * 	- SOCKET_1 
 * P&S! Possibilities for this sensor:
 * 	- SOCKET_A
 * 	- SOCKET_B
 * 	- SOCKET_C
 * 	- SOCKET_F
 */
Gas CO2(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

char node_ID[] = "CO2_example";

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


void loop()
{		
	///////////////////////////////////////////
	// 1. Power on  sensors
	///////////////////////////////////////////  
	
	// Power on the CO2 sensor. 
	// If the gases PRO board is off, turn it on automatically.
	CO2.ON();
	
	// CO2 gas sensor needs a warm up time at least 60 seconds	
	// To reduce the battery consumption, use deepSleep instead delay
	// After 1 minute, Waspmote wakes up thanks to the RTC Alarm
	PWR.deepSleep("00:00:01:10", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
	
	
	///////////////////////////////////////////
	// 2. Read sensors
	///////////////////////////////////////////  
	
	// Read the CO2 sensor and compensate with the temperature internally
	concentration = CO2.getConc();
	
	// Read enviromental variables
	temperature = CO2.getTemp();
	humidity = CO2.getHumidity();
	pressure = CO2.getPressure();
	
	
	///////////////////////////////////////////
	// 3. Power off sensors
	///////////////////////////////////////////  
	
	// Power off the CO2 sensor. If there aren't more gas sensors powered,
	// turn off the board automatically
	CO2.OFF();
	
	
	///////////////////////////////////////////
	// 4. Create ASCII frame
	/////////////////////////////////////////// 
	
	// Create new frame (ASCII)
	frame.createFrame(ASCII);
	
	// Add CO2 concentration
	frame.addSensor(SENSOR_GP_CO2, concentration);
	// 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 4 minutes, Waspmote wakes up thanks to the RTC Alarm
	PWR.deepSleep("00:00:04:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
	
}

Output

E#
CO2 example
===============================
Current ASCII Frame:
Length: 85
Frame Type: 128
frame (HEX): 3C3D3E80042333383235333733363823434F325F6578616D706C6523302347505F434F323A3731332E3030302347505F54433A32382E3738302347505F48554D3A34322E38352347505F505245533A393831313723
frame (STR): <=>€#382537368#CO2_example#0#GP_CO2:713.000#GP_TC:28.780#GP_HUM:42.85#GP_PRES:98117#
===============================

===============================
Current ASCII Frame:
Length: 85
Frame Type: 128
frame (HEX): 3C3D3E80042333383235333733363823434F325F6578616D706C6523312347505F434F323A3732362E3030302347505F54433A32382E3737302347505F48554D3A34322E37392347505F505245533A393831313623
frame (STR): <=>€#382537368#CO2_example#1#GP_CO2:726.000#GP_TC:28.770#GP_HUM:42.79#GP_PRES:98116#
===============================

Quick Publish: