Air Pressure
Requirements
Materials
- Air pressure sensor
BMP280
Basics
The BMP280 sensor measures both air pressure (hPa) and temperature (° C). This sensor is controlled via the I²C Protokoll, and requires an operating voltage of 3.3 to 5 volts. I²C devices are connected to the senseBoxMCU via the I²C / Wire port and thus read out digitally (see also The serial databus).
The I²C address of the BMP280 can be switched via theBMP280 sensor
SDO
pin:
If SDO
is at ground (GND
) the address is 0x76
, otherwise 0x77
. This communication is handled by the senseBox library for us.
Since the air pressure depends on the altitude above sea level, the body height of the senseBox can also be determined via the Height determination via the air pressure
BMP280
. For this purpose, a reference pressure P0
is needed whose height is known. Usually, the current air pressure is used at sea level. Since the air pressure can fluctuate greatly depending on the current weather, this "altitude measurement" but is not very accurate, and must be recalibrated again and again.
Construction
To get the sensor up and running just plug it in to the I²C / wire port!
Programming - Reading the sensor
The sensor can be controlled via the SenseBoxMCU.h
library. After this has been integrated, an instance bmp
of it must be created. On this object all functions of the library are called:
#include <SenseBoxMCU.h>
BMP280 bmp_sensor;
In the setup()-function
setup ()
-function, the sensor must be initialized. Use the following linesvoid setup(){
bmp_sensor.begin();
}
Now the sensor has to be read in the loop()-function
loop ()
-function. The variables temp
and pressure
then each contain the current measured values.void loop(){
double temp, pressure;
pressure = bmp_sensor.getPressure();
temp = bmp_sensor.getTemperature();
}
Exercises
Connect the Exercise 1
BMP280
sensor to the Arduino, and create an Arduino sketch, which regularly outputs air pressure and temperature on the serial monitor!
You have learned that the construction height of the senseBox can be determined from the measured air pressure. Use the function Exercise 2
bmp.altitude (...)
to calculate the height and output it on the serial monitor as well.