GP 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 Gases PRO board v30 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 Gases PRO v30 technical guide. - Cycle time: 3 minutes

Code

1
/*
2
------- [GP_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) 2018 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 <WaspSensorGas_Pro.h>
29
30
/*
31
* Waspmote OEM. Possibilities for this sensor:
32
* - CENTRAL SOCKET
33
* P&S! Possibilities for this sensor:
34
* - SOCKET_E
35
*/
36
bmeGasesSensor bme;
37
38
float temperature; // Stores the temperature in ºC
39
float humidity; // Stores the realitve humidity in %RH
40
float pressure; // Stores the pressure in Pa
41
42
void setup()
43
{
44
USB.ON();
45
USB.println(F("Temperature, humidity and pressure sensor example"));
46
}
47
48
void loop()
49
{
50
///////////////////////////////////////////
51
// 1. Turn on the sensor
52
///////////////////////////////////////////
53
54
bme.ON();
55
56
///////////////////////////////////////////
57
// 2. Read sensors
58
///////////////////////////////////////////
59
60
// Read enviromental variables
61
temperature = bme.getTemperature();
62
humidity = bme.getHumidity();
63
pressure = bme.getPressure();
64
65
// And print the values via USB
66
USB.println(F("***************************************"));
67
USB.print(F("Temperature: "));
68
USB.print(temperature);
69
USB.println(F(" Celsius degrees"));
70
USB.print(F("RH: "));
71
USB.print(humidity);
72
USB.println(F(" %"));
73
USB.print(F("Pressure: "));
74
USB.print(pressure);
75
USB.println(F(" Pa"));
76
77
///////////////////////////////////////////
78
// 3. Turn off the sensor
79
///////////////////////////////////////////
80
81
bme.OFF();
82
83
///////////////////////////////////////////
84
// 3. Sleep
85
///////////////////////////////////////////
86
87
// Go to deepsleep
88
// After 3 minutes, Waspmote wakes up thanks to the RTC Alarm
89
USB.println(F("Go to deep sleep mode..."));
90
PWR.deepSleep("00:00:03:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
91
USB.ON();
92
USB.println(F("Wake up!!\r\n"));
93
}
Copied!

Output

1
H#
2
Temperature, humidity and pressure sensor example
3
***************************************
4
Temperature: 24.2600002288 Celsius degrees
5
RH: 43.1982421875 %
6
Pressure: 99752.3593750000 Pa
7
***************************************
8
Temperature: 24.3199996948 Celsius degrees
9
RH: 43.1914062500 %
10
Pressure: 99750.8281250000 Pa
11
***************************************
12
Temperature: 24.3400001525 Celsius degrees
13
RH: 43.1826171875 %
14
Pressure: 99748.4531250000 Pa
15
***************************************
16
Temperature: 24.3500003814 Celsius degrees
17
RH: 43.1728515625 %
18
Pressure: 99751.2343750000 Pa
Copied!
Last modified 1yr ago