BME280 pressure and altitude relationship

I asked a similar question some time ago and in the meantime I was able to find some information about my location, i.e. altitude and pressure correction refered to the local airport.
Everything looks fine, but I still do not understand how these two parameters are dipendent. Here are some sampling I get (taken every 30 sec):

P=1009.2, A=237
P=1009.2, A=237
P=1009.2, A=237
P=1009.3, A=236
P=1009.4, A=235
P=1009.5, A=235
P=1009.6, A=233
P=1009.6, A=233
P=1009.7, A=233
P=1009.7, A=233
P=1009.8, A=232

Actually my altitude should be about 315m.

This is the relavant piece of code I'm using:

#include <Adafruit_BME280.h>
Adafruit_BME280 bme; 

#define SEALEVELPRESSURE_HPA 1002 
// I use this value against the standard 1013.25 that I read in a number of sketches; this is supposed to be the real Sea Level  Pressure at my location

// ratio between local pressure (1013 from local Caravaggio airport) to my absolute reading (978) right now
// I use this ratio to obtain a pressure value close to what expected
#define PRESSRATIO 1.036 

float temperature, humidity, pressure, altitude;

void ReadBME() {
  temperature = bme.readTemperature(); 
  delay(5);
  humidity = bme.readHumidity() + 0.5;
  delay(5);
  pressure = PRESSRATIO * bme.readPressure();
  delay(5);
  altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
 ...show results ....
}

Why the altitude varies when the pressure changes?
I understood that these parameters are correlated, thus the altitude is calculated from the pressure, but does it mean that I can not have the 2 real values indipendently?

The relationship between air pressure and altitude is explained here, along with an on line calculator: Air Pressure at Altitude Calculator

Your code replaces "Equation 1" with a ratio that is valid for only one location.

Air pressure at your location depends on the "sea level pressure", which has to be updated frequently in order to obtain the correct altitude.

1 Like

Thanks for the link, really useful.
Said that, I'm still confused a lot. Indipendently from the correct air pressure, which can vary according to the Sea Level pressure at my location, I would expect that the altitude of my board that is stable on my desk remains the same even when the wheater (pressure) changes.
Am I wrong?

In your link I entered the current data from the local airport (ITALY BG airport Caravaggio - METAR LIME - Aeroporto Internazionale Il Caravaggio) in the Calculate Altitude from Air Pressure window.
I set:
Pressure at Sea Level: 101325 (standard - fixed?)
Temperature: 5°
Air Pressure at Altitude: 101500 PA
Altitude (result): -14.05 m

Now, since temperature and pressure are correct, I presume, and the result is wrong, I believe that the variable to be changed here is the Pressure at Sea Level, which is?
I played with this value until I got a valid and known altitude for the airport, 238m, and
the SLP was 104520 PA.
That is what made me cry: how can I know which is the correct SLP to use?
In other words: when I get this value (104520) should I ever use it (constant) for all the future measurments?

Pressure at Sea Level: 101325 (standard - fixed?)

No, that is just the internationally accepted average. The actual sea level pressure changes on a time scale of hours to days according to the weather. Pressure changes are inter-related and extend over very wide areas, depending on geography, solar radiation and winds.

The altitude is calculated from the sea level pressure and the local pressure by the barometric equation, which is a pretty good approximation to the real relationship.

If you know your altitude, you can calculate the sea level pressure from the local pressure, then the altitude readings will be correct until the weather changes. Recalculate the sea level pressure to correct the reading.

Dear jremington, I do really appreciate your effort to make me understand the matter...unfortunately I'm possibly to dumb or ignorant to get it.
Let me try in a different way using your sentence:

If you know your altitude, you can calculate the sea level pressure from the local pressure, then the altitude readings will be correct until the weather changes. Recalculate the sea level pressure to correct the reading.

  1. Let's say that I know my current altitude (315m) and I read a pressure of 980hPA, which is the formula to calculate the "sea level pressure"?

  2. After that, any time I need to calculate a new altitude since I'm moving, which SLP should I use since, according to point 1, this is obtained from the altitude?

Sorry to bother you with my questions

  1. There are many websites with formulas and also calculators, quickly revealed by the search phrase "calculate sea level pressure from altitude". Here is one: Sea Level Pressure Calculator | iCalculator™
    Also, many Arduino BMP280 libraries have a function built in to do so. Did you check? The Adafruit library you are using has this function, which seems promising:
    float seaLevelForAltitude(float altitude, float atmospheric);

  2. Once you have set the correct sea level pressure, the altitude will be correct at your elevation and others, until the weather changes. This is called "calibrating the altimeter".

And its one of the reasons aircraft get regular local weather updates when not at cruising altitudes, and its also the reason they switch to the "standard" model when above ~10,000 feet, since cruising over the ocean you are not be able to get local weather reports - the airlanes actual altitudes thus change with the weather, but all the aircraft in the lanes use the same model so they match each other.

altitude is height above ground. the height of your location above mean sea level is elevation. you assign the value elevation in your code

these are code snippets that uses data from a BME280 to calculate everything but wind chill. that requires an anemometer, which I have not yet implemented. they work in my program, you may need to twiddle and fiddle to make them work in your program.


// RX side variables to retrieve weather data

float temperature_C;  
float temperature_F;
float pressure_hPa;
float Pressure;
float pressure_inHg;
float Humidity;
float seaLevelPressure_hPa (1013.25);  // 1013.25/33.863886666667 = 29.92 in hg
float seaLevelPressure_inHg;
float dewpoint_F;
float dewpoint_C;
String temperature;
String pressure;
String humidity;

// RX side code to calculate weather data from raw BME280 readings.

void BME_280_conversions()
{
  temperature_C = (temperature.toInt());
  Serial.print("Temperature C = ");
  Serial.print(temperature_C);
  Serial.println(" *C");
  temperature_F = ((1.8 * temperature_C) + 32); // Convert Celcius temperature to Fahrenheit
  Serial.print("Temperature F = ");
  Serial.print(temperature_F);
  Serial.println( " F" );

  Pressure = (pressure.toInt());
  pressure_hPa = ((Pressure / 100.0F));
  Serial.print("Pressure hPa  = ");
  Serial.print(pressure_hPa);
  Serial.println("  hPa" );
  pressure_inHg = ((pressure_hPa / 100.0F) / 33.864); // Convert hectoPascals to inHg
  Serial.print("Pressure inHG = ");
  Serial.print(pressure_inHg);
  Serial.println( " inHG");

  Humidity = (humidity.toInt());
  Serial.print( "Humidity      = ");
  Serial.print(Humidity);
  Serial.println(" %");

  seaLevelPressure_hPa = pressure_hPa / pow(1.0 - 0.0065 * localElevation / (temperature_C + 273.15), 5.255);
  Serial.print( "Sea Level Pressure hPa  = " );
  Serial.print( seaLevelPressure_hPa );
  Serial.println( " hPa");
  seaLevelPressure_inHg = seaLevelPressure_hPa / 33.864;
  Serial.print( "Sea Level Pressure inHg = " );
  Serial.print( seaLevelPressure_inHg );
  Serial.println( " inHg");

  dewpoint_F = 243.04 * (log(Humidity / 100) + ((17.625 * temperature_F) / (243.04 + temperature_F))) / (17.625 - log(Humidity / 100) - ((17.625 * temperature_F) / (243.04 + temperature_F)));
  Serial.print("Dewpoint = ");
  Serial.print(dewpoint_F);
  Serial.println(" F");
  dewpoint_C = ((temperature_F - 32) / 1.8 ); // Convert Fahrenheit temperature to Celcius
  Serial.print("Dewpoint = ");
  Serial.print(dewpoint_C);
  Serial.println(" C");
  Serial.println();
}

This is becaming a nightmare to me. I read all the comments and I'm even more confused.
Let me firstly say that I used the link 'Sea level Pressure Calculator' but there is something wrong with it: I set Atmosperic Pressure=99800 PA and Altitude=315m. The calculator does not return any value. If I set the Altitude=315mm (millimeters) I got a Sea Level Pressure = 103608.7673 Pa, which could be valid.
Curious, but not important.

I changed my main function in this way:

#define BASEALTITUDE 315.00 //default base elevation in meters

void ReadBME() {
  char floatAlt[7];                     // float converted to string
  char floatPres[10];                   // float converted to string
  char floatSLP[10];                    // float converted to string
  temperature = bme.readTemperature();  //negative temperature ???
  delay(5);
  humidity = bme.readHumidity() + 0.5;
  delay(5);
  pressure = bme.readPressure() / 100.0;
  delay(5);
  SLP = bme.seaLevelForAltitude(BASEALTITUDE, pressure);
  delay(5);
  altitude = bme.readAltitude(SLP);  //SEALEVELPRESSURE_HPA
  delay(5);

  dtostrf(pressure, 6, 1, floatPres);
  dtostrf(SLP, 6, 1, floatSLP);
  dtostrf(altitude, 4, 0, floatAlt);

  sprintf(buf, "SLP=%s : Pres=%s : A=%s", floatSLP, floatPres,  floatAlt);
  Serial.println(buf);
}

This is an ouput sample obtained lowering and raising the board over the desk:

SLP=1033.9 : Pres= 995.9 : A= 315
T= 23.0, U=28, P=  10.0, A=315
SLP=1033.9 : Pres= 995.9 : A= 315
T= 22.9, U=26, P=  10.0, A=315
SLP=1034.1 : Pres= 996.0 : A= 315

The pressure values change but the altitude remains the same.
This is obvious since the altitude is calculated from the seaLevelForAltitude, which in turns ia calculated using the constant base altitude...it is a race condition.
In Italy we have a sentence that, Google translated, say: the dog that eats its own tail

Turning back to my original post, I still do not understand is there is, and which, a fixed variable to use to calculate the other two values: Sea Level Pressure, local pressure and altitude.

Let me try with another semplicistic example:
I'm at home (315m) and I calculate the SLP using my known altitude and local pressure (998 hPA). I get in example a 1034 hPA for SLP.
Then I go for a walk in the wood on the hill, at around 800m, with a changing bad weather (lower pressure?).
How do I calculate the local pressure and altitude while moving?

Sorry if I'm boring.

That result is correct, and that calculator is working as expected.

If the local air pressure is above the sea level air pressure, then your elevation is below sea level and negative. If you move to higher elevation > 0 nearby, then the local pressure will generally be less than sea level pressure.

The calculator I linked in post #6 was just the first one that came up out of several. I just tried it and it does not seem to work as expected.

How do I calculate the local pressure and altitude while moving?

You don't. You measure the local air pressure.

  1. If you know the current sea level pressure, use that to calculate the current altitude from the local pressure.

  2. If you know the altitude, use the altitude and the measured local pressure to calculate the equivalent sea level pressure. Use that sea level value to calculate subsequent altitude values from subsequent local pressure values, until the weather changes.

  3. If you don't know the altitude or the equivalent sea level pressure, then assume SLP = 101325 Pa, which is a reasonable basis to estimate the altitude from the local pressure (to within a few hundred meters).

Note: most people do not make a distinction between the terms "altitude" and "elevation".

1 Like

You use your phone for a local recent weather report to get the sea-level pressure.

The pressure at any point depends on both the altitude and the current weather conditions .
The weather affects the pressure , so people can compare weather conditions , the equivalent pressure at sea level is used ( otherwise it would make it hard to tell what the weather would be forecast up a hill compared to valley ). That’s just a convention.

In an air craft the pressure at the airport and it’s altitude are used so the altimeter ( just a pressure gauge ) knows where the ground is !
If you are moving , pressing against the air will alter the pressure you read .

If you want local altitude a GPS might be better

Well jremington, at least now I understand what I can and can not do ! Sorry for the delay in aswering but I was away.

If you don't know the altitude or the equivalent sea level pressure, then assume SLP = 101325 Pa, which is a reasonable basis to estimate the altitude from the local pressure (to within a few hundred meters).

My idea is to have a portable devices for people (maybe not myself) who go for a walk up to the local mountains (500..2000m) inside woods, where the phone hardly has any signal ( :flushed:).
They want to know the reached altitude (or elevation?) and, important, have some indications about the wheather changes (lowering local pressure = possible storm or rain coming, right?).
In origin I even added a striking sensor (AS3935) to detect lighting in the area, but unfortunately it did not work despite a lot of tests...but this is another story.

Just a last help or suggestion: if the walker approximately knows the starting altitude and calculate the sea leve pressure according to your point 2, would be better/useful to use that value later on, togheter with the local pressure, to get a better altitude ?
Many thanks

That is what most people do. Others set the starting altitude to zero, and then measure altitude relative to the starting point.

You can buy very inexpensive digital altimeters/barometers that work on exactly this principle. I use this one: 8 In 1 Digital Altimeter Barometer Thermometer for Hiking Climbing Outdoor Sport | eBay

When you say "the phone has hardly any signal" in the woods, do you mean GPS signals? My experience has been that phones have fairly decent GPS sensors that work well in forests... at least they do around here.

Some (many?) phones have barometric pressure sensors that work with altimeter apps, so even if the GPS signal is not available or reliable, one's approximate elevation would be.

And, if one carries and knows how to read a topographic map (or has one on their phone), one can usually determine their elevation, to a sufficient degree, using various landmarks.

As for the weather outlook - that's what forecasts are for.

I'd forget the idea of a special Arduino driven elevation/weather device. I certainly wouldn't carry one.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.