Development

Sensors / Gases Board:

» Ga 03: Atmospheric Pressure Sensor Reading

In this example the Gases 2.0 board and the MPX4115A atmospheric pressure sensor are turned on, reading the sensor every second approximately and printing the result through the USB.

Required Materials

1 x Waspmote
1 x Battery
1 x Coin cell
1 x Gases 2.0 board
1 x Atmospheric Pressure sensor (MPX4115A)

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 output of this sensor may sometimes be noisy, in this case a software filtering will be advisable
* Remember the atmospheric pressure value obtained is absolute, it will be necessary a conversion in function of height

Code

/*  
 *  ------ [Ga_3] - Atmospheric Pressure Sensor for Gases v20-------- 
 *  
 *  Explanation: Turn on the Gases Board v20 and read the atmospheric
 *  pressure sensor 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>

//Variable to store the read atmospheric pressure value
float pressureVal;

void setup()
{
  //Turn on the USB and print a start message
  USB.ON();
  USB.println(F("start"));
  delay(100);
}
 
void loop()
{
  // Turn on the sensor board
  SensorGasv20.ON();
  
  // Turn on the atmospheric pressure sensor and wait for stabilization and
  // sensor response time
  SensorGasv20.setSensorMode(SENS_ON, SENS_PRESSURE);
  delay(20); 
 
  // Read the sensor
  pressureVal = SensorGasv20.readValue(SENS_PRESSURE);
  
  // Turn off the atmospheric pressure sensor
  SensorGasv20.setSensorMode(SENS_OFF, SENS_PRESSURE);
    
  // Turn off the sensor board
  SensorGasv20.OFF();
  
  // Print the result through the USB
  USB.print(F("Pressure: "));
  USB.print(pressureVal);
  USB.println(F(" kPa"));
  
  delay(1000);
}

Output

B#
start
Pressure: 109.1849975585 kPa
Pressure: 109.1849975585 kPa
Pressure: 108.9406051635 kPa

Quick Publish: