Development

Sensors / Gases Board:

» Ga 13: Calibrated sensor reading

This is an example of how to read a sensor of the new calibrated line offered by Libelium with the Gas Sensor Board. Although this code works for the CO calibrated sensor, it can be easily extended just by copying the lines regarding calibration in this code to that of the corresponding sensor.

Required Materials

1 x Waspmote
1 x Battery
1 x Gases 2.0 board
1 x CO Calibrated Sensor (TGS2442)

Notes

* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Gases 2.0 technical guide.
* The sensor gain and load resistor have been adjusted to operate with a given unit of a TGS2442 sensor, they will depend on the sensor used and the application, for more information about how to select this parameters take a look at the Gases 2.0 board technical guide.
* The only thing necessary to read any other Calibrated Sensor will be to add to the example for the given sensor the lines shown in this code related to calibration (creation of arrays coCalibrationConcentration and coCalibrationOutput, variable ppmVal and use of function calculateConcentration).
* Remember the accuracy shown by the sensor will highly depend on the time the sensor has been heated. In the case of the CO and NH3 sensors this time will depend on the number of reading cycles applied, since this sensors must be only powered with short pulses provided during the readValue function execution.

Code

/*  
 *  ------ [Ga_13] - CO Calibrated sensor Reading for Gases v20-------- 
 *  
 *  Explanation: Turn on the Gases Board v20 and reads the CO sensor
 *  placed on socket 4 every second, printing the result
 *  through the USB
 *  
 *  Copyright (C) 2012 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:    
 */

#include <WaspSensorGas_v20.h>

#define GAIN  1      // GAIN of the sensor stage
#define RESISTOR 100  // LOAD RESISTOR of the sensor stage

// INTRODUCE IN THE NEXT ARRAY THE CONCENTRATION VALUES
int coCalibrationConcentration[3] = {50,100,300};

// INTRODUCE IN THE NEXT ARRAY THE CALIBRATION OUTPUT OF THE SENSORS
float coCalibrationOutput[3] = {114.3312 , 40.2036 , 11.7751};

// Variable to store the read CO value
float coVal;
float ppmVal;

void setup()
{
  // Turn on the USB and print a start message
  USB.ON();
  USB.println(F("start"));
  delay(100);

  // Turn on the sensor board
  SensorGasv20.ON();

  // Turn on the RTC
  RTC.ON();

  // Configure the CO sensor on socket 4
  SensorGasv20.configureSensor(SENS_SOCKET4CO, GAIN, RESISTOR);
  
}
 
void loop()
{
  
  // Read the sensor 
  coVal = SensorGasv20.readValue(SENS_SOCKET4CO);
  
  // Print the result through the USB
  USB.print(F("CO: "));
  USB.print(coVal);
  USB.print(F("V - "));

  // Conversion from voltage into kiloohms  
  coVal = SensorGasv20.calculateResistance(SENS_SOCKET4CO, coVal, GAIN, RESISTOR);
  USB.print(coVal);
  USB.print(F("kohms - "));
  
  // Conversion from sensor resistance in kiloohms in parts per million  
  ppmVal = SensorGasv20.calculateConcentration(coCalibrationConcentration,coCalibrationOutput,coVal);
  USB.print(ppmVal);
  USB.println(F("ppm"));

}

Output

D#
start
CO: 0.5258064270V - 965.8776855468kohms - 8.6578607559ppm
CO: 0.4935483932V - 1035.5485839843kohms - 8.1904315948ppm
CO: 0.4967741489V - 1028.1743164062kohms - 8.2372074127ppm
CO: 0.4935483932V - 1035.5485839843kohms - 8.1904315948ppm
CO: 0.4935483932V - 1035.5485839843kohms - 8.1904315948ppm
CO: 0.4967741489V - 1028.1743164062kohms - 8.2372074127ppm

Quick Publish: