Ag xtr 18: MB7040 sensor reading
Basic example that turns on, reads and turn off the sensor. Measured parameters are stored in the corresponding class variables and printed by the serial monitor.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 MB7040 sensor

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_18] - MB7040 sensor reading --------------------
3
4
Explanation: Basic example that turns on, reads and turn off the
5
sensor. Measured parameters are stored in the corresponding class
6
variables and printed by the serial monitor.
7
8
Measured parameters:
9
- Distance
10
11
Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
12
http://www.libelium.com
13
14
This program is free software: you can redistribute it and/or modify
15
it under the terms of the GNU General Public License as published by
16
the Free Software Foundation, either version 3 of the License, or
17
(at your option) any later version.
18
19
This program is distributed in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
GNU General Public License for more details.
23
24
You should have received a copy of the GNU General Public License
25
along with this program. If not, see .
26
27
Version: 3.1
28
Design: David Gascón
29
Implementation: J.Siscart, V.Boria
30
*/
31
32
#include <WaspSensorXtr.h>
33
34
/*
35
SELECT THE RIGHT SOCKET FOR EACH SENSOR.
36
37
Possible sockets for this sensor are:
38
- XTR_SOCKET_A _________
39
- XTR_SOCKET_D |---------|
40
| A B C |
41
|_D__E__F_|
42
43
44
Example: a 5TM sensor on socket A will be
45
[Sensor Class] [Sensor Name] [Selected socket]
46
Decagon_5TM mySensor (XTR_SOCKET_A);
47
48
Refer to the technical guide for information about possible combinations.
49
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
50
*/
51
52
// [Sensor Class] [Sensor Name] [Selected socket]
53
ultrasound mySensor(XTR_SOCKET_A);
54
55
void setup()
56
{
57
USB.println(F("MB7040 example"));
58
59
60
}
61
62
void loop()
63
{
64
// 1. Turn ON the sensor
65
mySensor.ON();
66
67
// 2. Read the sensor. Store parameter in local variable
68
uint16_t distance = mySensor.getDistance();
69
70
// 3. Turn off the sensor
71
mySensor.OFF();
72
73
// 4. Print information
74
USB.println(F("---------------------------"));
75
USB.println(F("MB7040"));
76
USB.print(F("Distance: "));
77
USB.print(distance);
78
USB.println(F(" cm"));
79
USB.println(F("---------------------------\n"));
80
81
delay(5000);
82
83
}
Copied!

Output

1
H#
2
MB7040 example
3
---------------------------
4
MB7040
5
Distance: 27 cm
6
---------------------------
7
---------------------------
8
MB7040
9
Distance: 20 cm
10
---------------------------
Copied!
Last modified 1yr ago