Development

Sensors / Smart Metering Board:

» SM 13: Reading DS18B20 Temperature

In this example the Smart Metering sensor board is turned on and configured to read the temperature sensor on it once every second.

Required Materials

1 x Waspmote
1 x Battery
1 x Coin cell
1 x Smart Metering board
1 x DS18B20

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 3 you will be turning on also socket 2.

Code

/*  
 *  --[SM_13] - Reading DS18B20 Temperature at Smart Metering board-- 
 *  
 *  Explanation: Turn on the Smart Metering board and read the 
 *  temperature sensor on it once every second.
 *  
 *  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:    Luis Miguel Marti
 */

#include <WaspSensorSmart_v20.h>
#include <WaspFrame.h>

float digitalTemperature; 
char node_ID[] = "Node_01";


void setup() 
{
  USB.ON();
  USB.println(F("Temperature example"));
  SensorSmartv20.ON();
  // Set the Waspmote ID
  frame.setID(node_ID); 
}
 
void loop()
{
  ///////////////////////////////////////////
  // 1. Turn on the sensors
  /////////////////////////////////////////// 

  // Power on the temperature sensor
  SensorSmartv20.setSensorMode(SENS_ON, SENS_SMART_TEMP_DS18B20);
  delay(100);
  
  
  ///////////////////////////////////////////
  // 2. Read sensors
  ///////////////////////////////////////////  

  // Read the temperature sensor
  digitalTemperature = SensorSmartv20.readValue(SENS_SMART_TEMP_DS18B20);
  
  
  ///////////////////////////////////////////
  // 3. Turn off the sensors
  /////////////////////////////////////////// 

  // Power off the temperature sensor
  SensorSmartv20.setSensorMode(SENS_OFF, SENS_SMART_TEMP_DS18B20);
  
  
  ///////////////////////////////////////////
  // 4. Create ASCII frame
  /////////////////////////////////////////// 

  // Create new frame (ASCII)
  frame.createFrame(ASCII);

  // Add temperature
  frame.addSensor(SENSOR_TCB, digitalTemperature);

  // Show the frame
  frame.showFrame();

  //wait 1 seconds
  delay(1000);
}

Output

E#
Temperature example
===============================
Current ASCII Frame:
Length: 36
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F30312335235443423A32352E303623
frame (STR): <=>€#400568635#Node_01#5#TCB:25.06#
===============================
===============================
Current ASCII Frame:
Length: 36
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F30312336235443423A32352E333123
frame (STR): <=>€#400568635#Node_01#6#TCB:25.31#
===============================
===============================
Current ASCII Frame:
Length: 36
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F30312337235443423A32352E363323
frame (STR): <=>€#400568635#Node_01#7#TCB:25.63#
===============================

Quick Publish: