Example Code for Arduino – BMP280 Temperature, Pressure, and Altitude Reading
Read the temperature, atmospheric pressure, altitude and other information collected by the 10Dof module, and print the values through the serial port. The units of the measured values are Celsius, pa, and m, respectively. The altitude is calculated from the temperature and pressure values collected by the on-board sensor BMP280, not the actual measured value, and there is an error.
Hardware Preparation
- 1×UNO microcontroller Board
- 1×BNO055 BMP280 intelligent 10DOF AHRS(V1.0) Module
- DuPont lines
Software Preparation
- Arduino IDE, click to download Arduino IDE
- BNO055 Library
- BMP280 Library
How to install library files? Click the link.
Wiring Diagram

Sample Code
/*!
* read_data.ino
*
* Download this demo to test simple read from bmp280, connect sensor through IIC interface
* Data will print on your serial monitor
*
* Copyright [DFRobot](https://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V1.0
* date 12/03/2019
*/
#include "DFRobot_BMP280.h"
#include "Wire.h"
typedef DFRobot_BMP280_IIC BMP; // ******** use abbreviations instead of full names ********
BMP bmp(&Wire, BMP::eSdo_low);
#define SEA_LEVEL_PRESSURE 1015.0f // sea level pressure
// show last sensor operate status
void printLastOperateStatus(BMP::eStatus_t eStatus)
{
switch(eStatus) {
case BMP::eStatusOK: Serial.println("everything ok"); break;
case BMP::eStatusErr: Serial.println("unknow error"); break;
case BMP::eStatusErrDeviceNotDetected: Serial.println("device not detected"); break;
case BMP::eStatusErrParameter: Serial.println("parameter error"); break;
default: Serial.println("unknow status"); break;
}
}
void setup()
{
Serial.begin(115200);
bmp.reset();
Serial.println("bmp read data test");
while(bmp.begin() != BMP::eStatusOK) {
Serial.println("bmp begin faild");
printLastOperateStatus(bmp.lastOperateStatus);
delay(2000);
}
Serial.println("bmp begin success");
delay(100);
}
void loop()
{
float temp = bmp.getTemperature();
uint32_t press = bmp.getPressure();
float alti = bmp.calAltitude(SEA_LEVEL_PRESSURE, press);
Serial.println();
Serial.println("======== start print ========");
Serial.print("temperature (unit Celsius): "); Serial.println(temp);
Serial.print("pressure (unit pa): "); Serial.println(press);
Serial.print("altitude (unit meter): "); Serial.println(alti);
Serial.println("======== end print ========");
delay(1000);
}
Result

Was this article helpful?
