Friday, August 19, 2011

Barometer - Altimeter


For some reason I've thought for a while that it would be fun to build (or even buy) a barometer.  A friend had this cool military surplus altimeter he put on the seat of his car while driving through the mountains and you could see the elevation go up and down. That was pretty cool.  Barometric pressure is interesting too.  Can you predict a storm by seeing a rapid drop?

So I finally ran across this chip, or sensor on a chip, by Freescale, the MP3H6115A pressure sensor chip. It cost $9.15 from Mouser. The chip is SMT, 8-pin SSOP package.  It has 0.05” pin spacing, but the row-to-row width is wider than SOIC packages, so a different adapter or board pattern is needed.
It has an output of 15 to 115kPa or 2.2 to 16.7 psia. Supply voltage is 2.7 to 3.3 VDC, typically 3.0 VDC.  Output is in ratio to supply voltage, so it must be known and regulated.

In the photo you see I soldered the chip to a little adapter board and glued that to a scrap piece of PC board on which I also mounted a 3.3V regulator.

Only three pins are used: supply, ground, and output. So you just take that output to the ADC input of your micro and Bob's-your-uncle, instant barometer.  Altimeter.  Whatever.

You'll need some floating point routines in the program.  I used my Arduino board which has an ATmega168 MCU, I think.  You program it in C.  I'm trying to expand beyond assembler so this is a good project for me. The formula for pressure from output voltage is:

P = (Vout/Vs +0.095)/0.009 kPa  (Vs is the supply voltage.)

Since the output is in kPa or kilo-Pascals, I did a further conversion to inches of mercury (inHg), more familiar to me.  BTW, normal barometric pressure is about 101.3kPa.

I first just hooked the thing to my DMM and converted voltage readings to inHg with Excel or my calculator.  I pulled up the local airport's data on the web and compared readings.  They were off a bit more than I expected, but then I learned that airports convert their reading to sea level equivalent, making it somewhat higher.  After compensating for the difference between sea level and our airport's altitude of about 380 ft. I was closer.  In the end I did a small fudge factor to get closer yet. I also have access to atmospheric pressure at my friendly local power plant for calibration purposes.

Converting to altitude is more complicated. Rigorous formulas are complex and factor in a number of things like ambient temperature and relative humidity.  I opted for one that was simpler:

Z = (1-(P/29.9247)^0.19)/22.558E-6

Where Z is altitude in meters and P is pressure in inHg.  I converted the result to feet for display.

My display is a 4-digit 7-segment display surplus from a set-top box, BTW.  I like the look of red 7-segment numerals, but it has a few issues:  No decimal point, hard to see in outdoor light, can't make many alphabetic characters.

I make my program display pressure in inHg for about 1.5s, then text approximating "inHg" for 0.75s, then feet altitude for 1.5s and text "ASL" for 0.75s and repeat.

One curious result I noticed initially was that the display would show 380 feet for a while, then jump to 350 feet, alternating between the two.  I finally realized that this is the limitation of my 10 bit ADC.  One part in 1024 is equivalent to about 30 feet of elevation here in Russellville.  I tricked my way out of that a bit by putting in an averaging routine that uses the average of 5 readings taken over a 5 second period.  Now I get smoother changes and some artificial interpolation but my response time to a step change has been reduced to the 5 seconds it takes to fill the buffer.

Today I gave it a trial run in the Miata to the top of Mt. Nebo.  My local elevation is 380 feet.  When I got to the sign at the top of the mountain saying "Elevation 1800 feet", my altimeter was displaying 1749 ASL.  So, pretty good.  

BTW, I looked at a week's worth of barometic data and saw that the equivalent elevation change between the high and low readings was 186 feet.  So I might reasonably expect extremes to make my altitude reading off by up to +/- 93 feet if I haven't entered any compensation.

Will this project ever make it into a box with a dedicated MCU chip?  Maybe.

The answer to that question is YES. In fact, I'd forgotten I started the thing on the Arduino. But the final version uses a bare ATmega chip programmed in AVR-GCC.  Also that 7-segment display looked great but was a current hog do I went with a regular Hitachi type dot matrix LCD. Still red.

Updated 2/22/2018

No comments: