Development

Sensors / Events Board:

» Ev 06: Socket 6 Humidity Sensor

In this example we turn on the Events Board v20 configuring the threshold of the socket 6 stage and wait for an interruption from this sensor to read its value, convert into humidity (808H5V6 sensor) and print it.

Required Materials

1 x Waspmote PRO
1 x Battery
1 x MiniUSB wire
1 x Events Sensor Board
1 x Humidity Sensor (808H5V6)

Notes

* Remember to turn on the manual switch for socket 1 in the Events 2.0 Sensor Board
* An 808H5V6 sensor is the one used in this example, but other sensors can be placed on this socket, please take a look at the Sensor Compatibility Guide
* Be careful not to miss this sensor with the 808H5V5 model used in other Sensor Boards

Code

/*  
 *  ------ [Ev_6] - Socket 6 Reading for Events v20-------- 
 *  
 *  Explanation: Turn on the Events Board v20 configuring the threshold
 *  of the socket 6 stage and wait for an interruption from this sensor
 *  to read its value, convert into humidity (808H5V6 sensor) and
 *  print it
 *  
 *  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.2
 *  Design:            David Gascón 
 *  Implementation:    Manuel Calahorra
 */

#include <WaspSensorEvent_v20.h>

// THRESHOLD for interruption from the sensor
const float THRESHOLD = 1.5;

// Variable to store the read value
float value;

void setup()
{
  // 1. Initialization of the modules  

  // Turn on the USB and print a start message
  USB.ON();
  USB.println(F("start"));

  // Turn on the sensor board
  SensorEventv20.ON();
  
  // Wait 15 seconds 
  USB.println(F("Wait for heating time..."));
  delay(15000);

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

  // Configure the socket 6 threshold
  SensorEventv20.setThreshold(SENS_SOCKET6, THRESHOLD);

  // Enable interruptions from the board
  SensorEventv20.attachInt();

}


void loop()
{
  ///////////////////////////////////////
  // 1. Read the sensor 
  ///////////////////////////////////////

  // 1.1. Read the sensor voltage output
  value = SensorEventv20.readValue(SENS_SOCKET6);

  // Print the info
  USB.print(F("Sensor output: "));    
  USB.print(value);
  USB.println(F(" Volts"));


  // 1.2. Read the sensor output
  value = SensorEventv20.readValue(SENS_SOCKET6, SENS_HUMIDITY);

  // Print the info
  USB.print(F("Humidity: "));    
  USB.print(value);
  USB.println(F("%RH"));



  ///////////////////////////////////////
  // 2. Go to deep sleep mode  
  ///////////////////////////////////////
  USB.println(F("enter deep sleep"));
  PWR.deepSleep("00:00:00:10",RTC_OFFSET,RTC_ALM1_MODE1,SOCKET0_OFF);

  USB.ON();
  USB.println(F("wake up\n"));



  ///////////////////////////////////////
  // 3. Check Interruption Flags
  ///////////////////////////////////////

  // 3.1. Check interruption from Sensor Board
  if(intFlag & SENS_INT)
  {
    interrupt_function();
  }

  // 3.2. Check interruption from RTC alarm
  if( intFlag & RTC_INT )
  {   
    USB.println(F("-----------------------------"));
    USB.println(F("RTC INT captured"));
    USB.println(F("-----------------------------"));

    // clear flag
    intFlag &= ~(RTC_INT);
  }

}




/**********************************************
 *
 * interrupt_function()
 *  
 * Local function to treat the sensor interruption
 *
 *
 ***********************************************/
void interrupt_function()
{
  // Disable interruptions from the board
  SensorEventv20.detachInt();

  // Load the interruption flag
  SensorEventv20.loadInt();

  // Read the sensor
  value = SensorEventv20.readValue(SENS_SOCKET6, SENS_HUMIDITY);

  // In case the interruption came from socket 6
  if( SensorEventv20.intFlag & SENS_SOCKET6)
  {
    USB.println(F("-----------------------------"));
    USB.println(F("Interruption from socket 6"));
    USB.println(F("-----------------------------"));
  }

  // Print the resistance of the sensor
  USB.print(F("Humidity: "));    
  USB.print(value);
  USB.println(F("%RH"));

  // Clean the interruption flag
  intFlag &= ~(SENS_INT);

  // Enable interruptions from the board
  SensorEventv20.attachInt();

}


Output

E#
start
Wait for heating time...
E#
start
Wait for heating time...
Sensor output: 1.0612902641 Volts
Humidity: 35.3763427734%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 1.0064516067 Volts
Humidity: 33.8709678649%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 0.9677418708 Volts
Humidity: 32.5806427001%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 0.9580644607 Volts
Humidity: 31.8279571533%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 1.0870966911 Volts
Humidity: 36.2365570068%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 1.2225805521 Volts
Humidity: 40.7526855468%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 1.3774193525 Volts
Humidity: 46.4516143798%RH
enter deep sleep
wake up

-----------------------------
Interruption from socket 6
-----------------------------
Humidity: 50.7526855468%RH
Sensor output: 1.5451612472 Volts
Humidity: 52.0430107116%RH
enter deep sleep
wake up

-----------------------------
RTC INT captured
-----------------------------
Sensor output: 1.8645161628 Volts
Humidity: 62.9032249450%RH
enter deep sleep
...

Quick Publish: