Python with Arduino LESSON 12: Approximating Changes in Height from Changes in Pressure

In LESSON 9 we learned how to hook up a BMP180 Pressure Sensor and make pressure and temperature readings. Then in LESSON 11 we learned how to stream that data to Matplotlib and create live graphs and charts of our data that update in real time. We could see that as we moved the pressure sensor up and down, we could see the pressure change, as the pressure decreases with increasing elevation.

This leads to the interesting question of whether we can use our circuit developed in LESSON 9 to create a Height-O-Meter . . . a simple device that will measure the height above the floor.

The math to calculate altitude vs. pressure turns out to be very complex. Particularly, if we wanted something for our high altitude balloon flights, or for model rocketry. It turns out that for the case of measuring height inside and for relatively small changes in height we can make simplifying assumptions that make things much easier. The assumption we will make is that temperature does not change much over the range of our experiment. With this assumption, we can create our own Height-O-Meter. To do this though, we do need to to through some math. I show my math below, and go through it step-by-step in the video. Remember, this simplified approach is only valid for playing around with small changes in height. We will have to do the more complicated math when we make our high altitude balloon probe. For now though, this math will work pretty well.

Height and Pressure
Calculate Changes in Height from Changes in Pressure

We can rearrange the equation to solve for height as a function of pressure.

Height Pressure
Calculating Height from Pressure Changes

7 thoughts on “Python with Arduino LESSON 12: Approximating Changes in Height from Changes in Pressure”

  1. Hi Paul,

    Your lessons are a gem for practical use in sensors. On high school, which was a long time ago for me (1976-1981), they used very expensive measurement equipment and not available the common people to have. Now it easy to get very good sensors for a reasonable price. It is now a piece of cake to make your own sophisticated measurement devices. I like working with Arduino and now with Raspberry Pi. Thanks for your interesting lessons, I learned a lot from you. Now my goal is to learn more about Python. With your lessons an eye-opener.

    Maybe one remark about your calculation, because I checked the formula on wikipedia.
    I was a bit confused about EXP (10 to the power) and LN (natural logarithm) . In wikipedia they use LOG (exponent of 10) in the formula to calculate altitude z, (eLOG =LN and 10LOG =LOG). But in your formula they seemed to be mixed up together according to the wikipedia formula:

    z = c *T* LOG(P_zero/P_measured)

    Anyhow a correction constant may be used to get the height-scale, but I am not sure.

    Greeting from The Netherlands,
    Sjaak (or Jack in English)

    1. There are different ways to do the same thing. Mine utilizes the base pressure P0 on the ground where height, h0 is zero. Then my height represents the height off the ground. I think if you try my way, it will work. Others might do it differently, but give mine a try and I think you will find it is correct.

  2. Hello Paul,

    Great site, great lessons, clear and concise. I have an offbeat question about your presentations and achieving that split screen/tiled effect. I’m in the process of developing some training video’s of my own and would love to have the multiple visual shots (code, hardware, perhaps my pretty face). What software and/or techniques did you use to achieve that?

    Thank you for what you do. Keep on teaching!


    1. Probably the easiest way is to get wirecast and a green screen. That is what I am doing now. On the old stuff I was just using screen capture software and putting all the windows on the screen and just recording the screen. Problem if you look careful, the audio is always a little out of sync with video. Wirecast is the way to go.

Comments are closed.