Sea level pressure for BMP280

Arduino Asked on December 28, 2021

I have a BMP280 and BMP180 pressure sensor and I have both of them connected via I²C to a ESP8266.

For the BMP180, I can get the sea level air pressure when I pass the pressure and altitude like so:

#include <SFE_BMP180.h>
SFE_BMP180 bmp180;
Serial.print(bmp180.sealevel(pressure, 800));

Is there a similar thing for the BMP280? Reading pressure and temperature works fine:

#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp280;
double temperature = bmp280.readTemperature();
double pressure = bmp280.readPressure() / 100;

2 Answers

Try this following segment: I used it myself and it worked fine.

As you don't get any default Method for returning the sea-level pressure from BMP280, I had to calculate on my own.

#include <Wire.h>
#include "SPI.h" //Why? Because library supports SPI and I2C connection
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

//Setup connection of the sensor
Adafruit_BMP280 bmp; // I2C
/*//For SPI connection!
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

float pressure;       //To store the barometric pressure (Pa)
float temperature;    //To store the temperature (oC)
float SLpressure_mB;

void setup() {
  bmp.begin();    //Begin the sensor
    Serial.begin(9600); //Begin serial communication at 9600bps
    Serial.println("Equivalent Sea Level Pressure Test:");

void loop() {
  //Read values from the sensor:
  pressure = bmp.readPressure();
  temperature = bmp.readTemperature();
  SLpressure_mB = (((pressure * 100.0)/pow((1-((float)(ELEVATION))/44330), 5.255))/100.0)  
  //Print values to serial monitor:
  Serial.print(F("Pressure: "));
    Serial.print(pressure, 2);
    Serial.print(" Pa");
    Serial.print(("Temp: "));
    Serial.print(" oC");
    Serial.print("Equivalent Sea Level Pressure: ");
    Serial.print(SLpressure_mB, 2);
    Serial.println(" mB");
    delay(5000); //Update every 5 sec

Answered by prikarsartam on December 28, 2021

It seems this was planned for the Adafruit BMP280 library but not implemented. Looking at Adafruit_BMP280.h we see commented code that has a method seaLevelForAltitude():

class Adafruit_BMP280_Unified : public Adafruit_Sensor
    Adafruit_BMP280_Unified(int32_t sensorID = -1);

    bool  begin(uint8_t addr = BMP280_ADDRESS, uint8_t chipid = BMP280_CHIPID);
    void  getTemperature(float *temp);
    void  getPressure(float *pressure);
    float pressureToAltitude(float seaLevel, float atmospheric, float temp);
    float seaLevelForAltitude(float altitude, float atmospheric, float temp);
    void  getEvent(sensors_event_t*);
    void  getSensor(sensor_t*);

    uint8_t   _i2c_addr;
    int32_t   _sensorID;


In another library, BMP280-arduino-library, I found a function that seems to work:

double BMP280::sealevel(double P, double A)
// Given a pressure P (mb) taken at a specific altitude (meters),
// return the equivalent pressure (mb) at sea level.
// This produces pressure readings that can be used for weather measurements.

First, I just copied that function into my code (without the class name), due to the friendly pizza license. Later I switched to that library and it also worked fine.

Answered by Thomas Weller on December 28, 2021

Add your own answers!

Related Questions

IMU (MPU9250) and Ticker on ESP32

1  Asked on December 10, 2020 by r-ho


Where this function is defined?

1  Asked on December 7, 2020 by ravi-s


Ultrasonic Sensor(HC-SR04) recording random distance

1  Asked on December 1, 2020 by shubham-bajaj


How to save data in arduino when it’s power goes off

3  Asked on December 1, 2020 by user63158


Max7219 7-segment display not working

0  Asked on November 29, 2020 by elayer213


Unresolved reference to public function from library

1  Asked on November 6, 2020 by omar_hussein


SG 90 servos randomly spinning

0  Asked on October 25, 2020


void loop() stops running after an hour or so

1  Asked on October 22, 2020 by imrobert7


Multiple sensors I2C stop working suddenly

0  Asked on October 6, 2020 by zaffresky


Is it possible to exit a loop on the change of an input state?

1  Asked on September 15, 2020 by jabawokjayuk


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir