Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» GP 19: AQM with particle

This is the basic code to manage and read CO, O3, SO2, NO2 gas sensors and a prticle sensor. This gases are commonly meassured in air quality monitors. The concentration and the enviromental variables will be stored in a frame.

Required Materials

1 x Waspmote
1 x Battery
1 x Gases PRO board
1 x Temperature, Humidity and Pressure sensor BME280
1 x CO Gas Sensor [Calibrated]
1 x O3 Gas Sensor [Calibrated]
1 x SO2 Gas Sensor [Calibrated]
1 x NO2 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
- This example can only be executed in Waspmote v12

Code

/*  
 *  ------------  [GP_019] - AQM with particle  -------------- 
 *  
 *  Explanation: This is the basic code to manage and read CO, O3, SO2, NO2
 *  gas sensors and a prticle sensor. This gases are commonly meassured in 
 *  air quality monitors. 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.1
 *  Design:            David Gascón 
 *  Implementation:    Alejandro Gállego
 */

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

// Each object will be used by each gas sensor
Gas CO(SOCKET_A);
Gas O3(SOCKET_B);
Gas SO2(SOCKET_C);
Gas NO2(SOCKET_F);


float conc_CO;		// Stores the concentration level of CO in ppm
float conc_O3;		// Stores the concentration level of O3 in ppm
float conc_SO2;		// Stores the concentration level of SO2 in ppm
float conc_NO2;		// Stores the concentration level of NO2 in ppm
float temperature;	// Stores the temperature in ºC
float humidity;		// Stores the realitve humidity in %RH
float pressure;		// Stores the pressure in Pa

int status;
int measure;

char node_ID[] = "AQM_OPCN2";

void setup()
{
    USB.println(node_ID);
    // Set the Waspmote ID
    frame.setID(node_ID); 

}	


void loop()
{
    ///////////////////////////////////////////
    // 1a. Turn on particle sensor
    ///////////////////////////////////////////  

    // Power on the OPC_N2 sensor. 
    // If the gases PRO board is off, turn it on automatically.
    status = OPC_N2.ON();
    if (status == 1)
    {
        USB.println(F("Particle sensor started"));

    }
    else
    {
        USB.println(F("Error starting the particle sensor"));
    }

    ///////////////////////////////////////////
    // 1b. Read the particle sensor
    ///////////////////////////////////////////  

    if (status == 1)
    {
        // Power the fan and the laser and perform a measure of 8 seconds
        measure = OPC_N2.getPM(8000);
        if (measure == 1)
        {
            USB.println(F("Measure performed"));
            USB.print(F("PM 1: "));
            USB.print(OPC_N2._PM1);
            USB.println(F(" ug/m3"));
            USB.print(F("PM 2.5: "));
            USB.print(OPC_N2._PM2_5);
            USB.println(F(" ug/m3"));
            USB.print(F("PM 10: "));
            USB.print(OPC_N2._PM10);
            USB.println(F(" ug/m3"));
        }
        else
        {
            USB.print(F("Error performing the measure. Error code:"));
            USB.println(measure, DEC);
        }
    }

    ///////////////////////////////////////////
    // 1c. Turn off the particle sensor
    /////////////////////////////////////////// 
    // Power off the OPC_N2 sensor. If there aren't other sensors powered, 
    // turn off the board automatically
    OPC_N2.OFF();

    delay(15000);

    ///////////////////////////////////////////
    // 2a. Turn on gas sensors
    /////////////////////////////////////////// 

    // Power on the sensors. 
    // If the gases PRO board is off, turn it on automatically.
    CO.ON();
    O3.ON();
    SO2.ON();
    NO2.ON();

    // The sensor needs time to warm up and get a response from gas
    // To reduce the battery consumption, use deepSleep instead delay
    // After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);


    ///////////////////////////////////////////
    // 2b. Read gas sensors
    ///////////////////////////////////////////  
    // Read the sensors and compensate with the temperature internally
    conc_CO = CO.getConc();
    conc_O3 = O3.getConc();
    conc_SO2 = SO2.getConc();
    conc_NO2 = NO2.getConc();

    // Read enviromental variables
    // In this case, CO objet has been used.
    // O3, SO2 or NO2 objects could be used with the same result
    temperature = CO.getTemp();
    humidity = CO.getHumidity();
    pressure = CO.getPressure();

    // And print the values via USB
    USB.println(F("***************************************"));
    USB.print(F("CO concentration: "));
    USB.print(conc_CO);
    USB.println(F(" ppm"));
    USB.print(F("O3 concentration: "));
    USB.print(conc_O3);
    USB.println(F(" ppm"));
    USB.print(F("SO2 concentration: "));
    USB.print(conc_SO2);
    USB.println(F(" ppm"));
    USB.print(F("NO2 concentration: "));
    USB.print(conc_NO2);
    USB.println(F(" ppm"));
    USB.print(F("Temperature: "));
    USB.print(temperature);
    USB.println(F(" Celsius degrees"));
    USB.print(F("RH: "));
    USB.print(humidity);
    USB.println(F(" %"));
    USB.print(F("Pressure: "));
    USB.print(pressure);
    USB.println(F(" Pa"));


    ///////////////////////////////////////////
    // 2c. Turn off the gas sensors
    /////////////////////////////////////////// 

    // Power off the sensors sensor. If there aren't more gas sensors powered, 
    // turn off the board automatically
    CO.OFF();
    O3.OFF();
    SO2.OFF();
    NO2.OFF();


    ///////////////////////////////////////////
    // 4. Create ASCII frame
    ///////////////////////////////////////////
    // Maybe it will be necessary to increase the MAX_FRAME constant
    // Create new frame (ASCII)
    frame.createFrame(ASCII);

    // Add CO concentration
    frame.addSensor(SENSOR_GP_CO, conc_CO);
    // Add O3 concentration
    frame.addSensor(SENSOR_GP_O3, conc_O3);
    // Add SO2 concentration
    frame.addSensor(SENSOR_GP_SO2, conc_SO2);
    // Add NO2 concentration
    frame.addSensor(SENSOR_GP_NO2, conc_NO2);
    // Add temperature
    frame.addSensor(SENSOR_GP_TC, temperature);
    // Add humidity
    frame.addSensor(SENSOR_GP_HUM, humidity);
    // Add pressure
    frame.addSensor(SENSOR_GP_PRES, pressure);	
    // Add PM 1
    frame.addSensor(SENSOR_OPC_PM1,OPC_N2._PM1); 
    // Add PM 2.5
    frame.addSensor(SENSOR_OPC_PM2_5,OPC_N2._PM2_5); 
    // Add PM 10
    frame.addSensor(SENSOR_OPC_PM10,OPC_N2._PM10); 
    // Add PM 10
    frame.addSensor(SENSOR_BAT,PWR.getBatteryLevel()); 

    // Show the frame
    frame.showFrame();


    ///////////////////////////////////////////
    // 5. Sleep
    /////////////////////////////////////////// 

    // Go to deepsleep 
    // After 3 minutes, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:02:37", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

}

Output

Particle sensor started
Measure performed
PM 1: 0.87514883 ug/m3
PM 2.5: 1.824257 ug/m3
PM 10: 12.5989 ug/m3
***************************************
CO concentration: 2.7723183631 ppm
O3 concentration: 0.0000000000 ppm
SO2 concentration: 0.0000000000 ppm
NO2 concentration: 0.4902467250 ppm
Temperature: 25.7999992370 Celsius degrees
RH: 49.4218750000 %
Pressure: 99743.4218750000 Pa
===============================
Current ASCII Frame:
Length: 149
Frame Type: 128
frame (HEX): 3C3D3E800A233430303538303136372341514D5F4F50434E3223302347505F434F3A322E3737322347505F4F333A302E3030302347505F534F323A302E3030302347505F4E4F323A302E3439302347505F54433A32352E3830302347505F48554D3A34392E34322347505F505245533A393937343323504D313A302E3837353123504D325F353A312E38323433234241543A363423
frame (STR): <=>€
#400580167#AQM_OPCN2#0#GP_CO:2.772#GP_O3:0.000#GP_SO2:0.000#GP_NO2:0.490#GP_TC:25.800#GP_HUM:49.42#GP_PRES:99743#PM1:0.8751#PM2_5:1.8243#BAT:64#
===============================
Particle sensor started
Measure performed
PM 1: 1.5087285 ug/m3
PM 2.5: 3.3886695 ug/m3
PM 10: 26.078632 ug/m3
***************************************
CO concentration: 10.9534597396 ppm
O3 concentration: 0.0000000000 ppm
SO2 concentration: 3.1926932334 ppm
NO2 concentration: 0.5905479431 ppm
Temperature: 26.1000003814 Celsius degrees
RH: 48.5156250000 %
Pressure: 99726.6250000000 Pa
===============================
Current ASCII Frame:
Length: 150
Frame Type: 128
frame (HEX): 3C3D3E800A233430303538303136372341514D5F4F50434E3223312347505F434F3A31302E3935332347505F4F333A302E3030302347505F534F323A332E3139332347505F4E4F323A302E3539312347505F54433A32362E3130302347505F48554D3A34382E35322347505F505245533A393937323723504D313A312E3530383723504D325F353A332E33383837234241543A363423
frame (STR): <=>€
#400580167#AQM_OPCN2#1#GP_CO:10.953#GP_O3:0.000#GP_SO2:3.193#GP_NO2:0.591#GP_TC:26.100#GP_HUM:48.52#GP_PRES:99727#PM1:1.5087#PM2_5:3.3887#BAT:64#
==========================

Quick Publish: