Altimeter Gauge using the new Barometric Sensor

The new HiTechnic Barometric Sensor can be used to measure altitude since air pressure varies with altitude. The NXT-G block for this sensor includes actions to read altitude as well as to adjust the altitude base pressure and to set the altitude pressure using a known altitude. The NXT-G programs presented in this blog post shown an airplane style altimeter on the NXT screen. Like a real altimeter, the altitude pressure can be adjusted to account for different meteorological conditions.

About the new HiTechnic Barometric Sensor

The NXT can read two types of data from the new Barometric sensor: pressure and temperature. Pressure is measured in units of 1/1000th inch of mercury while temperature is measured in 1/10th degree Celsius. With the Barometer NXT-G Block, you can read these data values as well as the alternative units of 1/10th hectopascals for pressure and temperature in 1/10th degree Fahrenheit.

Note that the reason these vales are in 1/10th or 1/1000ths of the actual units is because the block uses integer math. For example, the average sea-level air pressure is 29.921 inHg (inches of mercury). If this value was rounded to the nearest integer then it would be 30, which would give you very poor resolution. By using 1/1000th inHg, the value is instead 29921.

About Barometric Pressure

Here on the surface of the earth we live at the bottom of a giant ocean of air. Just like the oceans of water below sea-level, the air is in constant motion and even has a slight variation in depth, almost like the ocean tides. The air pressure at the earth’s surface is the result of the weight of all the air above. Due to the motion and variation in depth, the pressure at the surface of the earth varies. This is one of the key pieces of data that meteorologists use to understand and predict weather.

Since the air pressure is the result of the weight of the air above, the air pressure changes as you change altitude. When you go up, you have less air above you and the air pressure goes down. This is what airplane altimeters use to determine altitude and also how the Barometer block for the Barometric sensor does it.

Measuring Altitude

The Barometer block includes several actions that have to do with altitude calculations. First of all there is the Read Altitude action that lets you read the altitude in either feet or meters. A simple program to display altitude the based on pressure would look like this:

This program will display the altitude in ft. Note that the Text block is used to both add a caption “Alt: “ and to clear the space after the number with a few spaces in the C field.

This program will only display an approximate altitude because the altitude calculation will use the default altitude pressure of 29.921 inHg, which is the average sea-level pressure. Chances are, the actual sea-level pressure for where you are is either higher or lower depending on the weather and the altitude can be off by several hundred feet.

To improve the altitude calculation, you need to adjust the altimeter by by either providing the Altitude Pressure, which is the current sea-level atmospheric pressure, or your current altitude. For example, let’s say you know that your current altitude is 100ft above sea-level. You can then add the following commands to your program:

In this program the first block uses the “Set Altitude” action to set the altitude to 100 ft. This will set the altitude pressure for the Barometer block so that the altitude calculations done later in the program will be relative to this known starting altitude. This program has also been setup to display the Altitude Pressure that is the result of the Set Altitude action. When this program is run, the display may look like this:

The number displayed on the bottom here is the “Altitude Pressure”. This is the calculated air pressure for sea-level at the current location. Now the number displayed on line 4 is the current altitude based on this altitude pressure.

This program would only be practical if you always start the program at the known altitude, in my case 100 ft. Let’s say I want the ability to stop my program. Go to a different altitude, perhaps the top of a hill, and then run the program again to check the new altitude. If I start with setting the altitude to 100ft, then I clearly won’t know how many feet I just went up. The solution is to use the Set Altitude Pressure action. Since I now know that the start altitude pressure is 30.213 inHg, I can make a new program where I start of by setting this altitude pressure. This program will look like this:

This program can now be stopped and started and will be accurate as long as the altitude pressure is around 30.252 inHg. Of course, during the day the meteorological conditions may change and you need to adjust the altitude pressure.

The Altimeter Program

Airplane altimeters have hands that function almost like the hands on a clock. The short wide hand indicates the altitude in 1000s of feet while the long skinny hand indicates the altitude in 100s. Airplane altimeters also typically have a third hand that shows 10,000s feet. For example, the altimeter below is showing an altitude of 10,180 ft.

Also notice the small window on the right side of the gauge, this is called the Kollsman window and shows the current altitude pressure. That is, the pressure at sea-level that is used as the basis of the altitude measurement. The knob on the lower left of the gauge is used to adjust the altitude pressure.

The NXT-G Altimeter program displays a similar gauge:

Here the altitude displayed is just under 100 ft and the altitude pressure is 30.20 inHg. To adjust this altitude pressure use the left and right arrow buttons on the NXT. Note that the program automatically saves the altitude pressure in a file on the NXT so you don’t have to worry about manually recording the altitude pressure.

There are two version of the Altimeter program. Both version look the same on the NXT screen but work slightly differently internally. The 2.0 version is a little simpler because it takes advantage of the floating point math that is available in the 2.0 software. The NXT-G 1.0 version has to do all the math using just integers which makes the program a little more complicated to understand.

After you have installed those two blocks, you will need to download and expand the Altimeter program for NXT-G 2.0. The zip file contains the file Altimeter.rbtx. When you open this program in the LEGO Mindstorms software, it will automatically create two MyBlocks that are used by the program and the background AltGauge.ric image file.

After you have installed this block, you will need to manually install the program and the MyBlocks and background AltGauge.ric image that it uses. First download and expand the zip file for the 1.0 Altimeter program.

Locate the documents for that the LEGO software uses. This will most likely be something like: Documents\LEGO Creations\MINDSTORMS Projects\Profiles\Default. If you want to use a profile other then Default, then select the profile folder you want to use. From the zip file, copy the file Altimeter1.rbt to the selected profile folder. Next, locate the MyBlocks that are used in the program, you will find these in the sub folder Blocks\My Blocks. You will find three MyBlocks. Copy these files to the proper MyBlocks sub-folder in your profile folder.

The last file you need to install is the AltGauge.ric file. This is the background image for the altimeter gauge. This file needs to be installed into the main LEGO Mindstorms software installation folder where the other .ric picture files are kept. Most likely this folder will be something like: C:\Program Files\LEGO Software\LEGO MINDSTORMS NXT\engine\Pictures

Copy the file AltGauge.ric to this folder.

You should now be able to load and then download the Altimeter program to the NXT.

Using the Altimeter Program

The first time your run the program the Altitude Pressure will be the default average sea-level pressure. The easiest way to set the Altitude Pressure is to find out what your current altitude is and the use the arrow buttons on the NXT until the altitude shown is close to the known altitude. For example, I know that my office is at an altitude of around 25 feet above sea-level. But the first time I run the program I got something like this:

This means that my altitude pressure value is too low since the calculated altitude is more than 200ft lower than my actual altitude. To adjust I simply press the right arrow button until the altitude is close to 25ft.

Here I was able to adjust it until it was exactly 25 but I was a bit lucky. The program only allows setting the altitude pressure to the 1/100ths inch of mercury which only give you about 10ft resolution in altitude. When setting the altitude pressure, you should only expect to get the altitude reading to within +/- 5 ft of the actual altitude.

Note that the Altitude Pressure from the Kollsman window is automatically saved in a file on the NXT so if you stop the program and then later restart the program, the altimeter will continue to use the same altitude pressure.

Now you are ready to take the NXT Altimeter for a walk or a drive and see how the altitude changes as you go up and down hills. Or take the Altimeter on a balloon ride.

The Barometer block supports data logging with the Education edition of the NXT-G software so you can also setup the sensor to log the altitude, pressure or temperature.

Leave a Reply

Lightbricks, Hitechnic are registered trademarks of Dataport Systems, Inc.
All product specifications and prices are subject to change at any time.
LEGO, MINDSTORMS, Robotics Invention System, RCX are trademarks of the LEGO Group.