Development

» Ga v30 02: O2 sensor

Turn on the Gases Board v30 and read the O2 sensor every five seconds, 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 O2 sensor

Notes

- This example is valid only for Waspmote v15

Code

/*  
 *  --------- [Ga_v30_2] O2 Sensor reading for v30  -------------- 
 *  
 *  Explanation: Turn on the Gases Board v30 and read the O2
 *  sensor every five seconds, 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>

// O2 Sensor must be connected in SOCKET_1
O2SensorClass O2Sensor(SOCKET_1);

// Percentage values of Oxygen
#define POINT1_PERCENTAGE 0.0    
#define POINT2_PERCENTAGE 5.0  

// Calibration Voltage Obtained during calibration process (in mV)
#define POINT1_VOLTAGE 0.35
#define POINT2_VOLTAGE 2.0

float concentrations[] = {POINT1_PERCENTAGE, POINT2_PERCENTAGE};
float voltages[] =       {POINT1_VOLTAGE, POINT2_VOLTAGE};

char node_ID[] = "O2_example";

void setup() 
{ 
  // Configure the USB port
  USB.ON();
  USB.println(F("O2 Sensor reading example"));

  O2Sensor.setCalibrationPoints(voltages, concentrations);
   
  ///////////////////////////////////////////
  // 1. Turn on the board
  /////////////////////////////////////////// 
  
  // Switch ON and configure the Gases Board
  Gases.ON();  
  // Switch ON the SOCKET_1
  O2Sensor.ON();
}

void loop()
{
  ///////////////////////////////////////////
  // 2. Read sensors
  ///////////////////////////////////////////  

  // O2 Sensor does not need power suplly
  float O2Vol = O2Sensor.readVoltage();
  
  USB.print(F("O2 concentration Estimated: "));
  USB.print(O2Vol);
  USB.print(F(" mV | "));
  delay(100);

  // Read the concentration value in %
  float O2Val = O2Sensor.readConcentration();
  
  USB.print(F(" O2 concentration Estimated: "));
  USB.print(O2Val);
  USB.println(F(" %"));  

  ///////////////////////////////////////////
  // 3. Create ASCII frame
  /////////////////////////////////////////// 
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII, node_ID);
  // Add Oxygen concentration value
  frame.addSensor(SENSOR_GASES_O2, O2Val);  
  // Show the frame
  frame.showFrame();

  delay(5000);   
}

Output

H#
O2 Sensor reading example
O2 concentration Estimated: 0.9515000343 mV | O2 concentration Estimated: 0.6196969985 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652330234F323A302E36323023
frame (STR): <=>�#41187063D93742F4#O2_example#0#O2:0.620#
===============================
O2 concentration Estimated: 2.6024999618 mV | O2 concentration Estimated: 3.7636365890 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652331234F323A332E37363423
frame (STR): <=>�#41187063D93742F4#O2_example#1#O2:3.764#
===============================
O2 concentration Estimated: 2.5474998950 mV | O2 concentration Estimated: 3.4409086704 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652332234F323A332E34343123
frame (STR): <=>�#41187063D93742F4#O2_example#2#O2:3.441#
===============================
O2 concentration Estimated: 2.8210000991 mV | O2 concentration Estimated: 4.5696973800 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652333234F323A342E35373023
frame (STR): <=>�#41187063D93742F4#O2_example#3#O2:4.570#
===============================
O2 concentration Estimated: 2.7344999313 mV | O2 concentration Estimated: 4.1696972846 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652334234F323A342E31373023
frame (STR): <=>�#41187063D93742F4#O2_example#4#O2:4.170#
===============================
O2 concentration Estimated: 2.7019999027 mV | O2 concentration Estimated: 4.3590908050 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652335234F323A342E33353923
frame (STR): <=>�#41187063D93742F4#O2_example#5#O2:4.359#
===============================
O2 concentration Estimated: 2.7014997005 mV | O2 concentration Estimated: 3.8575756072 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652336234F323A332E38353823
frame (STR): <=>�#41187063D93742F4#O2_example#6#O2:3.858#
===============================
O2 concentration Estimated: 2.5735001564 mV | O2 concentration Estimated: 3.6393945217 %
===============================
Current ASCII Frame:
Length: 45
Frame Type: 134
frame (HEX): 3C3D3E86012334313138373036334439333734324634234F325F6578616D706C652337234F323A332E36333923
frame (STR): <=>�#41187063D93742F4#O2_example#7#O2:3.639#
===============================
...

Quick Publish: