Development

Sensors / Events Board v30:

» Ev v30 03: Liquid Level sensor

This example show the Liquid Level sensor works in SOCKET2. The sensor can be connected in SOCKET_1, SOCKET_3 and SOCKET_4 too.

Required Materials

1 x Waspmote
1 x Battery
1 x MiniUSB wire
1 x Events Board v30
1 x Liquid Level sensor

Notes

- This example is valid only for Waspmote v15

Code

/*  
 *  --[Ev_v30_03] - Reading Liquid Level sensor 
 *  
 *  Explanation: This example show the Liquid Level sensor works in
 *  SOCKET2. The sensor can be connected in SOCKET_1, SOCKET_3 and 
 *  SOCKET_4 too.
 *  
 *  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:    Carlos Bello
 */

#include <WaspSensorEvent_v30.h>

uint8_t value=0;

//Instance object
liquidLevelClass liquidLevel(SOCKET_2); 
 
void setup() 
{
  // Turn on the USB and print a start message
  USB.ON();
  USB.println(F("Start program"));  
 
  // Turn on the sensor board
  Events.ON();
  
  // Firstly, wait for signal stabilization  
  value = liquidLevel.readliquidLevel();
  while (value == 1)
  {    
    USB.println(F("...wait for stabilization"));
    delay(1000);
    value = liquidLevel.readliquidLevel();  
  }
  
  // Enable interruptions from the board
  Events.attachInt();
}


void loop() 
{  
  ///////////////////////////////////////
  // 1. Read the sensor level 
  ///////////////////////////////////////
  // Read the sensor level
  value = liquidLevel.readliquidLevel();
  
  // Print the info
  if (value == 1)
  {  
    USB.println(F("Sensor output: LEVEL REACHED"));
  }
  else
  {
    USB.println(F("Sensor output: LEVEL NOT REACHED"));    
  } 
  

  ///////////////////////////////////////
  // 2. Check Interruption Flags
  ///////////////////////////////////////
   
  // 2.1. Check interruption from Sensor Board
  if(intFlag & SENS_INT)
  {
    interrupt_function();
  }
  
  // 2.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);
  }

  
  ///////////////////////////////////////
  // 3. Go to deep sleep mode  
  ///////////////////////////////////////
  USB.println(F("enter deep sleep"));
  PWR.deepSleep("00:00:00:10", RTC_OFFSET, RTC_ALM1_MODE1, SENSOR_ON);  
  
  USB.ON();
  USB.println(F("wake up\n"));
}




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

  // Load the interruption flag
  Events.loadInt();  
  
  // In case the interruption came from Liquid Level
  if (liquidLevel.getInt())
  {
    USB.println(F("-----------------------------"));
    USB.println(F("Interruption from Liquid Level"));
    USB.println(F("-----------------------------"));
  }

  // Printing and enabling interruptions
  USB.println(F("LEVEL REACHED\n"));   

  // User should implement some warning
  // In this example, now wait for signal
  // stabilization to generate a new interruption
  // Read the sensor level
  value = liquidLevel.readliquidLevel();
  
  while (value == 1 )
  {    
    USB.println(F("LEVEL REACHED"));
    delay(1000);
    value = liquidLevel.readliquidLevel();     
  }
  
  // Clean the interruption flag
  intFlag &= ~(SENS_INT);
  // Enable interruptions from the board
  Events.attachInt();
}

Output

H#
Start program
Sensor output: LEVEL NOT REACHED
enter deep sleep
wake up

Sensor output: LEVEL NOT REACHED
-----------------------------
RTC INT captured
-----------------------------
enter deep sleep
wake up

Sensor output: LEVEL NOT REACHED
-----------------------------
RTC INT captured
-----------------------------
enter deep sleep
...

Quick Publish: