/* * --[SM_11] - Reading the Load Cell connected to the 5V socket on Smart Metering v20 board-- * * Explanation: Turn on the load cell every six seconds, taking a * measurement and printing its result through the USB port. * * 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 . * * Version: 0.1 * Design: David Gascón * Implementation: Manuel Calahorra */ #include // 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_LCELLS_5V); delay(5000); // Read the load cell value = SensorSmartv20.readValue(SENS_SMART_LCELLS_5V); // Turn off the sensor SensorSmartv20.setSensorMode(SENS_OFF, SENS_SMART_LCELLS_5V); // Part 2: USB printing // Print the voltage value through the USB USB.print(F("Voltage: ")); USB.print(value); USB.println(F("V")); delay(1000); } SM 11: 5V Load Cell Reading | Libelium

Development

» SM 11: 5V Load Cell Reading

In this example the Smart Metering sensor board is turned on, the load cell placed on socket 9 powered at 5V and read approximately every six seconds, printing results through the USB port.

Required Materials

1 x Waspmote
1 x Battery
1 x Smart Metering PRO board
1 x Load Cell 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.
* The conversion from volts into weight will depend on the installation of the load cell
* This example can only be executed in Waspmote v12

Code

/*  
 *  --[SM_11] - Reading the Load Cell connected to the 5V socket on Smart Metering v20 board-- 
 *  
 *  Explanation: Turn on the load cell every six seconds, taking a
 *               measurement and printing its result through the USB port.
 *  
 *  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:    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_LCELLS_5V);
  delay(5000);
  
  // Read the load cell
  value = SensorSmartv20.readValue(SENS_SMART_LCELLS_5V);
  
  // Turn off the sensor
  SensorSmartv20.setSensorMode(SENS_OFF, SENS_SMART_LCELLS_5V);
  
  // Part 2: USB printing
  // Print the voltage value through the USB
  USB.print(F("Voltage: "));
  USB.print(value);
  USB.println(F("V"));
  
  delay(1000);
}

Output

B#
start
Voltage: 0.0064516124V
Voltage: 0.0129032254V
Voltage: 0.3161290168V
Voltage: 1.0000000000V
Voltage: 1.2645161151V
Voltage: 0.8451612472V
Voltage: 0.0064516124V

Quick Publish: