Ag v30 12: DS18B20 sensor
Turn on the Agriculture v30 board and read the temperature sensor every second

Required Materials

1 x Waspmote 1 x Agriculture Board v30 1 x DS18B20 sensor

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
* --[Ag_v30_12] - DS18B20 sensor reading
3
*
4
* Explanation: Turn on the Agriculture v30 board and read the
5
* temperature sensor every second
6
*
7
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*
23
* Version: 3.0
24
* Design: David Gascón
25
* Implementation: Carlos Bello
26
*/
27
28
#include <WaspSensorAgr_v30.h>
29
30
// Variable to store the read value
31
float temp = 0;
32
//Instance object
33
ds18b20Class ds18b20;
34
35
void setup()
36
{
37
// Turn on the USB and print a start message
38
USB.ON();
39
USB.println(F("Start program"));
40
41
// Turn on the sensor board
42
Agriculture.ON();
43
}
44
45
void loop()
46
{
47
// Part 1: Read Values
48
// Read the temperature sensor
49
temp = ds18b20.readDS18b20();
50
51
// Part 2: USB printing
52
// Print values through the USB
53
USB.print(F("Temperature (DS18B20): "));
54
USB.print(temp);
55
USB.println(F(" ºC"));
56
delay(1000);
57
}
Copied!

Output

1
H#
2
Start program
3
Temperature (DS18B20): 26.4375000000 C
4
Temperature (DS18B20): 26.4375000000 C
5
Temperature (DS18B20): 26.4375000000 C
6
Temperature (DS18B20): 26.5000000000 C
7
Temperature (DS18B20): 26.6250000000 C
8
Temperature (DS18B20): 26.7500000000 C
9
Temperature (DS18B20): 26.8125000000 C
10
...
Copied!
Last modified 1yr ago