» Ga v30 03: CO2 sensor
Turn on the Gases Board v30 and read the CO2 sensor every second, printing the result through the USB
Required Materials
1 x Waspmote
1 x Battery
1 x MiniUSB wire
1 x Gases Board v30
1 x CO2 sensor
Notes
- This example is valid only for Waspmote v15
Code
/*
* ------ [Ga_v30_3] CO2 Sensor reading for v30 --------
*
* Explanation: Turn on the Gases Board v30 and read the CO2
* sensor every second, printing the result through the USB
*
* 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.0
* Design: David Gascón
* Implementation: Ahmad Saad
*/
// Library include
#include <WaspSensorGas_v30.h>
#include <WaspFrame.h>
// CO2 Sensor must be connected physically in SOCKET_2
CO2SensorClass CO2Sensor;
// Concentratios used in calibration process (PPM Values)
#define POINT1_PPM_CO2 350.0 // <-- Normal concentration in air
#define POINT2_PPM_CO2 1000.0
#define POINT3_PPM_CO2 3000.0
// Calibration vVoltages obtained during calibration process (Volts)
#define POINT1_VOLT_CO2 0.300
#define POINT2_VOLT_CO2 0.350
#define POINT3_VOLT_CO2 0.380
// Define the number of calibration points
#define numPoints 3
float concentrations[] = { POINT1_PPM_CO2, POINT2_PPM_CO2, POINT3_PPM_CO2 };
float voltages[] = { POINT1_VOLT_CO2, POINT2_VOLT_CO2, POINT3_VOLT_CO2 };
char node_ID[] = "CO2_example";
void setup()
{
// Configure the USB port
USB.ON();
USB.println(F("CO2 Sensor reading for v30..."));
// Calculate the slope and the intersection of the logarithmic function
CO2Sensor.setCalibrationPoints(voltages, concentrations, numPoints);
///////////////////////////////////////////
// 1. Turn on the board and the SOCKET
///////////////////////////////////////////
// Switch ON and configure the Gases Board
Gases.ON();
// Switch ON the CO2 Sensor SOCKET_2
CO2Sensor.ON();
}
void loop()
{
///////////////////////////////////////////
// 2. Read sensors
///////////////////////////////////////////
// Voltage value of the sensor
float CO2Vol = CO2Sensor.readVoltage();
// PPM value of CO2
float CO2PPM = CO2Sensor.readConcentration();
// Print of the results
USB.print(F("CO2 Sensor Voltage: "));
USB.print(CO2Vol);
USB.print(F("volts |"));
USB.print(F(" CO2 concentration estimated: "));
USB.print(CO2PPM);
USB.println(F(" ppm"));
///////////////////////////////////////////
// 3. Create ASCII frame
///////////////////////////////////////////
// Create new frame (ASCII)
frame.createFrame(ASCII, node_ID);
// Add CO2 PPM value
frame.addSensor(SENSOR_GASES_CO2, CO2PPM);
// Show the frame
frame.showFrame();
delay(1000);
}
Output
H#
CO2 Sensor reading for v30...
CO2 Sensor Voltage: 0.0532638835volts | CO2 concentration estimated: 378.7921688 ppm
===============================
Current ASCII Frame:
Length: 47
Frame Type: 134
frame (HEX): 3C3D3E8601233638323537303633443933373432303723434F325F6578616D706C65233023434F323A3337382E37393223
frame (STR): <=>�#68257063D9374207#CO2_example#0#CO2:378.792#
===============================
CO2 Sensor Voltage: 0.0291203689volts | CO2 concentration estimated: 378.6572993 ppm
===============================
Current ASCII Frame:
Length: 47
Frame Type: 134
frame (HEX): 3C3D3E8601233638323537303633443933373432303723434F325F6578616D706C65233123434F323A3337382E363523
frame (STR): <=>�#68257063D9374207#CO2_example#1#CO2:378.65#
===============================
CO2 Sensor Voltage: 0.0289351844volts | CO2 concentration estimated: 379.1542593 ppm
===============================
Current ASCII Frame:
Length: 47
Frame Type: 134
frame (HEX): 3C3D3E8601233638323537303633443933373432303723434F325F6578616D706C65233223434F323A3337392E313523
frame (STR): <=>�#68257063D9374207#CO2_example#2#CO2:379.15#
===============================