SCP v30 05: Temperature, humidity and pressure sensor
This is the basic code to manage and read the temperature, humidity and pressure sensor.

Required Materials

1 x Waspmote 1 x Battery 1 x Smart Cities PRO board 1 x Temperature, Humidity and Pressure sensor BME280

Notes

- Remember to connect the battery to Waspmote for proper operation. - The connection of the sensor is described in the Smart Cities PRO technical guide. - Cycle time: 3 minutes

Code

1
/*
2
------- [SCP_v30_05] - Temperature, humidity and pressure sensor ---------
3
4
Explanation: This is the basic code to manage and read the temperature,
5
humidity and pressure sensor. Cycle time: 3 minutes
6
7
Copyright (C) 2017 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.2
24
Design: David Gascón
25
Implementation: Alejandro Gállego
26
*/
27
28
#include <WaspSensorCities_PRO.h>
29
30
/*
31
Waspmote OEM. Possibilities for this sensor:
32
- SOCKET_1
33
- SOCKET_2
34
- SOCKET_3
35
- SOCKET_4
36
- SOCKET_5
37
P&S! Possibilities for this sensor:
38
- SOCKET_A
39
- SOCKET_B
40
- SOCKET_C
41
- SOCKET_E
42
- SOCKET_F
43
*/
44
bmeCitiesSensor bme(SOCKET_A);
45
46
float temperature; // Stores the temperature in ºC
47
float humidity; // Stores the realitve humidity in %RH
48
float pressure; // Stores the pressure in Pa
49
50
void setup()
51
{
52
USB.println(F("Temperature, humidity and pressure sensor example"));
53
}
54
55
void loop()
56
{
57
///////////////////////////////////////////
58
// 1. Turn on the sensor
59
///////////////////////////////////////////
60
61
bme.ON();
62
63
///////////////////////////////////////////
64
// 2. Read sensors
65
///////////////////////////////////////////
66
67
temperature = bme.getTemperature();
68
humidity = bme.getHumidity();
69
pressure = bme.getPressure();
70
71
// And print the values via USB
72
USB.println(F("***************************************"));
73
USB.print(F("Temperature: "));
74
USB.printFloat(temperature, 2);
75
USB.println(F(" Celsius degrees"));
76
USB.print(F("RH: "));
77
USB.printFloat(humidity, 2);
78
USB.println(F(" %"));
79
USB.print(F("Pressure: "));
80
USB.printFloat(pressure, 2);
81
USB.println(F(" Pa"));
82
83
///////////////////////////////////////////
84
// 3. Turn off the sensor
85
///////////////////////////////////////////
86
87
bme.OFF();
88
89
///////////////////////////////////////////
90
// 4. Sleep
91
///////////////////////////////////////////
92
93
// Go to deepsleep
94
// After 10 seconds, Waspmote wakes up thanks to the RTC Alarm
95
USB.println(F("Go to deep sleep mode..."));
96
PWR.deepSleep("00:00:00:10", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
97
USB.println(F("Wake up!!\r\n"));
98
}
Copied!

Output

1
H#
2
Temperature, humidity and pressure sensor example
3
The sensor is placed in socket B
4
***************************************
5
Temperature: 23.94 Celsius degrees
6
RH: 43.88 %
7
Pressure: 99736.10 Pa
8
Go to deep sleep mode...
9
Wake up!!
10
11
***************************************
12
Temperature: 24.00 Celsius degrees
13
RH: 43.88 %
14
Pressure: 99738.10 Pa
15
Go to deep sleep mode...
16
Wake up!!
Copied!
Last modified 1yr ago