BMP180 library altitude calculation troubles

Hello all,

I’m currently working on a research project which involves triggering a relay at a certain altitude on a weather balloon. What I am currently using as an altimeter is a BMP180 Barometric Pressure Temperature and Altitude Sensor, as well as this tutorial and library. I currently have my Arduino Uno wired up to the BMP 180, as well as an LCD display to show the results. However, though the sensor does seem to read the temperature and barometric pressure of the surrounding area, the “pressure.altitude(P,p0);” always returns the initial given altitude. I have gone to different altitudes with the sensor and Arduino still running to see if the value would change, but it never did. Am I doing something wrong? What else can/should I try?

Note: The only changes I have made to the code are the inclusion of the LiquidCrystal library, a reduction of the delay between readings to once every 0.25 seconds, and simple print functions to output the values of P, p0, and a to the display. I have attached my .ino file as well.

alt_test.ino (4.19 KB)

the "pressure.altitude(P,p0);" always returns the initial given altitude

That is the expected behavior for your code.

The code appears to be using a circular argument. You calculate p0 (the equivalent sea level pressure) from the current absolute pressure, temperature and assumed altitude, then use that p0 with the current pressure to calculate the altitude. So, you get back only what you put in.

To fix the problem, calculate p0 once, to calibrate the altimeter, and use that calculated p0 value until you have good reason to recalibrate. Unless a storm is moving through, the p0 pressure changes slowly, usually over the course of hours or days.