Development

Sensors / Agriculture Board:

» Ag 14: Reading DS18B20 Temperature

In this example the Agriculture 2.0 sensor board is turned on and configured to read the temperature sensor on it once every second. This example works both with Agriculture_v20 and Agriculture_PRO

Required Materials

1 x Waspmote
1 x Battery
1 x Agriculture 2.0 board or Agriculture PRO 2.0 board
1 x DS18B20

Notes

* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Agriculture 2.0 technical guide.

Code

/*  
 *  --[Ag_14] - Reading DS18B20 Temperature at Agriculture v20 board-- 
 *  
 *  Explanation: Turn on the Ariculture v20 board and read the 
 *  temperature sensor on it once every second. This example works 
 *  both with Agriculture_v20 and Agriculture_PRO
 *  
 *  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 <WaspSensorAgr_v20.h>
#include <WaspFrame.h>

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


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

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

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

  // Power off the temperature sensor
  SensorAgrv20.setSensorMode(SENS_OFF, SENS_AGR_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): 3C3D3E800123343030353638363335234E6F64655F30312330235443423A32342E303623
frame (STR): <=>€#400568635#Node_01#0#TCB:24.06#
===============================
===============================
Current ASCII Frame:
Length: 36
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F30312331235443423A32342E313323
frame (STR): <=>€#400568635#Node_01#1#TCB:24.13#
===============================
===============================
Current ASCII Frame:
Length: 36
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F30312332235443423A32342E303623
frame (STR): <=>€#400568635#Node_01#2#TCB:24.06#
===============================
...

Quick Publish: