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.

» SM 05: Flow Sensor on 3V3 Socket Reading

In this example the Smart Metering sensor board is turned on and the flow sensor, placed on socket 5, read every second approximately, printing the result through the USB port.

Required Materials

1 x Waspmote
1 x Battery
1 x Smart Metering board
1 x Flow sensor

Notes

* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Smart Cities technical guide.
* Take into account that when powering socket 5 you will be turning on also socket 4.
* To read a different sensor from the YFS401 you should replace constant SENS_FLOW_YFS401 by SENS_FLOW_YFG1, SENS_FLOW_FS100, SENS_FLOW_FS200 or SENS_FLOW_FS400.
* This example can only be executed in Waspmote v12

Code

/*  
 *  --[SM_5] - Reading the Flow Sensor connected to the 3.3V socket on Smart Metering v20 board-- 
 *  
 *  Explanation: Turn on the flow sensor every second, taking a measurement and
 *               printing its result through the USB port.
 *  
 *  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 <WaspSensorSmart_v20.h>

// Variable to store the read value
float value;

void setup()
{
  // Turn on the USB and print a start message
  USB.ON();
  USB.println(F("start"));
  delay(100);

  // Turn on the sensor board
  SensorSmartv20.ON();
  
  // Turn on the RTC
  RTC.ON();
  
}
 
void loop()
{
  // Part 1: Sensor reading
  // Turn on the sensor and wait for stabilization and response time
  SensorSmartv20.setSensorMode(SENS_ON, SENS_SMART_FLOW_3V3);
  delay(10);
  
  // Read the flow sensor 
  value = SensorSmartv20.readValue(SENS_SMART_FLOW_3V3, SENS_FLOW_YFS401);
  
  // Turn off the sensor
  SensorSmartv20.setSensorMode(SENS_OFF, SENS_SMART_FLOW_3V3);
  
  // Part 2: USB printing
  // Print the flow value through the USB
  USB.print(F("Flow: "));
  USB.print(value);
  USB.println(F("l/min"));
  
  delay(1000);
}

Output

D#
start
Flow: 0.0000000000l/min
Flow: 7.7333331108l/min
Flow: 16.9333324432l/min
Flow: 15.3333330154l/min
Flow: 7.3333334922l/min
Flow: 0.5333333492l/min
Flow: 0.0000000000l/min

Quick Publish: