Can pressure sensors like the SparkFun Qwiic MicroPressure Sensor, be used as an altimeter?

Can pressure sensors like the SparkFun Qwiic MicroPressure Sensor (https://www.sparkfun.com/products/16476), be used as an altimeter, over a long period of time, say 2-3 hours?

I’ve read through a few articles recommending using a pressure sensor to calculate the altitude. I know that they use pressure to calculate the altitude, and one can use them to calculate relative altitude (not absolute altitude) and can be used to calculate the change in altitude.

In a nutshell, the logic is usually along the lines of:

initialize
    read the initial pressure
    initial altitude = f(initial pressure)
loop
    read the current pressure
    current altitude = f(current pressure)
    altitude change = current altitude - initial altitude
    display the altitude change

This (seems to me) to only work if the ambient atmospheric pressure doesn’t change, which, even if indoors, changes throughout the day.

As an example, write a sketch with the previous logic, and run it for a few hours. While it is running, don’t move the sensor. Since the sensor isn’t moving, the altitude change that’s calculated should remain the same (roughly, +/- the sensitivity), but since the ambient pressure is changing throughout the day, the altitude change (that’s reported) changes (even though it is left still)

So maybe I’m missing something here, but it seems like using a pressure sensor to calculate the altitude works when the application runs for only a short period of time (maybe 30 minutes or less) but not when the application runs for a few hours. Or is there a way to calculate the altitude, and altitude change over the course of a few hours?

I don’t believe this part would have the precision needed to accurately measure altitude. You’d be much better off using a purpose built altimeter chip like the MPL3115A2 that’s the same price as the qwiic micro pressure.

Also, period of time you measure over doesn’t matter but air pressure is constantly changing and that will appear to make it look like your altitude is changing.

You will need to correct your measurements for the current barometric pressure to get an accurate altitude, current barometric pressure can be found at the nearest airport to you by checking that airports altimeter setting. For example, the link below will give the altimeter setting for Denver International Airport. (Substitute your nearest airport code for KDEN)

https://e6bx.com/weather/KDEN/

Click the “decode” checkbox to get plain English results.

it seems like using a pressure sensor to calculate the altitude works when the application runs for only a short period of time (maybe 30 minutes or less) but not when the application runs for a few hours.

The period is unpredictable, as it depends on the weather. The ambient air pressure can change dramatically over minutes as a storm front moves in, or remain relatively stable for days.

It is best to calibrate an altimeter frequently – either use your current altitude to calibrate soon before you expect it to change, or use a weather report, keeping in mind that most weather reports (and especially airports) correct the local reading to sea level.