Standalone Arduino Altimeter

24,476

47

64

Introduction: Standalone Arduino Altimeter

Here is a standalone altimeter working with Arduino that you can use in RC project, hiking, cars... where you want :)

It shows on first screen the altittude, the temperature & the air pressure, and in the second, the minimum / maximum altitude reached.

Parts needed: (~12$)

  • An arduino board like a nano, pro mini or even AtTiny85 (depends on what you want, pro mini is lighter than nano and can works with an input voltage of 3.3v to 12v, perfect for light weight RC) 3.29$ on ebay
  • BMP280 chip temperature & barometric pressure sensor 1.84$ on ebay
  • An OLED display (0.96" I2C IIC Série 128X64) 5.32$ on ebay
  • Iron solder, tin and wires
  • A plastic case to put all in 1.50$ on ebay

Step 1: The Wiring

The wiring is simple, the most "complicated" is to find the SCL and SDA pin on your arduino.

On the nano as on the photo, pin A4 is SDA and pin A5 is SCL.

On the Pro Mini, take a look at the picture, SDA is upside right to pin A2, and SCL upside right to pin A3.

Once your wiring is done, lets upload the sketch to the Arduino !

Step 2: The Program

Code explanations (full code below):

#include "U8glib.h"
#include "BMP280.h"

They are the 2 libraries you have to put inside Documents\Arduino\libraries\

#define P0 1021.97

This is where you calibrate the altimeter, changing this value. Once it's done, it's pretty accurate !

(by default it was 1013.25, i had to up it to 1021.97 to have the right altitude in my town)

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);

Here you define the Oled screen type (128x64 etc...)

  u8g.drawStr( 5, 10, "Temp: ");
u8g.drawStr( 5, 30, "Bar : "); u8g.drawStr( 5, 50, "Alt : "); u8g.drawStr( 50, 10, sT); u8g.drawStr( 50, 30, sP); u8g.drawStr( 50, 50, sA);

Here the informations you want to display on first screen and their position ( Y, X, VALUE)

  dtostrf(A_MIN, 4, 2, sA_MIN);
dtostrf(A_MAX, 4, 2, sA_MAX); u8g.drawStr( 5, 20, "A Min: "); u8g.drawStr( 60, 20, sA_MIN); u8g.drawStr( 5, 45, "A Max: "); u8g.drawStr( 60, 45, sA_MAX);

Same for second screen

      if ( A > A_MAX) {
A_MAX = A; }
      if ( A < A_MIN || A_MIN == 0) {
        A_MIN = A;
      }

Here we update the minimum and maximun altitude stored

      do {
draw(T, P, A); } while ( u8g.nextPage() ); u8g.firstPage(); delay(1000);

Here, with the delay value (1000 in this case), you will stay 1 second on the first screen before switching to the second one. So change that if you want to customize display time :)

      do {
draw2(A_MIN, A_MAX); } while ( u8g.nextPage() ); u8g.firstPage(); delay(1000);

Same for second screen !

Hope it's clear, feel free to post a question in comments if needed !

Here is the full code:

#include "U8glib.h"
#include "BMP280.h" #include "Wire.h" #define P0 1021.97 //1013.25 BMP280 bmp; // OLED Type U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); char sT[20]; char sP[9]; char sA[9]; char sA_MIN[9]; char sA_MAX[9]; double A_MIN = 0; double A_MAX = 0; void draw(double T, double P, double A) { u8g.setFont(u8g_font_unifont); dtostrf(T, 4, 2, sT); dtostrf(P, 4, 2, sP); dtostrf(A, 4, 2, sA); u8g.drawStr( 5, 10, "Temp: "); u8g.drawStr( 5, 30, "Bar : "); u8g.drawStr( 5, 50, "Alt : "); u8g.drawStr( 50, 10, sT); u8g.drawStr( 50, 30, sP); u8g.drawStr( 50, 50, sA); } void draw2(double A_MIN, double A_MAX) { u8g.setFont(u8g_font_unifont); dtostrf(A_MIN, 4, 2, sA_MIN); dtostrf(A_MAX, 4, 2, sA_MAX); u8g.drawStr( 5, 20, "A Min: "); u8g.drawStr( 60, 20, sA_MIN); u8g.drawStr( 5, 45, "A Max: "); u8g.drawStr( 60, 45, sA_MAX); } void setup() { Serial.begin(9600); if (!bmp.begin()) { Serial.println("BMP init failed!"); while (1); } else Serial.println("BMP init success!"); bmp.setOversampling(4); u8g.setColorIndex(1); u8g.setFont(u8g_font_unifont); } void loop(void) { double T, P; char result = bmp.startMeasurment(); if (result != 0) { delay(result); result = bmp.getTemperatureAndPressure(T, P); if (result != 0) { double A = bmp.altitude(P, P0); if ( A > A_MAX) { A_MAX = A; } if ( A < A_MIN || A_MIN == 0) { A_MIN = A; } // Serial.print("T = \t"); Serial.print(T, 2); Serial.print(" degC\t"); // Serial.print("P = \t"); Serial.print(P, 2); Serial.print(" mBar\t"); // Serial.print("A = \t"); Serial.print(A, 2); Serial.println(" m"); u8g.firstPage(); do { draw(T, P, A); } while ( u8g.nextPage() ); u8g.firstPage(); delay(1000); do { draw2(A_MIN, A_MAX); } while ( u8g.nextPage() ); u8g.firstPage(); delay(1000); } else { Serial.println("Error."); } } else { Serial.println("Error."); } delay(100); }

Step 3: Now It's Up to You !

You can move form the breadboard to the plastic case with soldering all.

Then, put it on RC plane, RC quadcopter, RC helicopter..... or a water rocket !

Hope it was helpful and that you will send me a pic once it's done =)

Sensors Contest 2016

Participated in the
Sensors Contest 2016

Make It Fly Contest 2016

Participated in the
Make It Fly Contest 2016

5 People Made This Project!

Recommendations

  • Origami Speed Challenge

    Origami Speed Challenge
  • Stick It Challenge

    Stick It Challenge
  • Woodworking Contest

    Woodworking Contest

64 Comments

0
jonathan.evan.welch
jonathan.evan.welch

Question 9 months ago

Hello! I followed the instructions, wiring and all (with several same-color wires) and when the program is uploaded and powered on, the screen seems to be mapping some sort of data points, which is what the photo attached depicts. Is there a way to solve this?

PXL_20210803_220346604.jpg
0
RobertG179
RobertG179

Question 9 months ago on Step 2

Does this record into a log at all?

0
Shoyun
Shoyun

Answer 9 months ago

While powered it will save in memory the altitude max (and min) and display in real time the other values.
If you shut it off, you lose values. So no, it doesn't log anything as it would require more stuff like a sd card reader and more code.

Not too hard to code however if you need this feature.

0
RobertG179
RobertG179

Reply 9 months ago

No worries, I'll have a 360 camera next to it so it will be on the footage. This is going into a weather balloon.

0
Shoyun
Shoyun

Reply 9 months ago

Perfect then :)

0
OscarG11
OscarG11

Question 11 months ago

Hello, can this be displayed on a:
Display Lcd 16x02 + Serie I2c instead the OLED?

Thanks!

0
unboxperfection
unboxperfection

Question 11 months ago

Hi may I know if a 0.66" Oled display work with this

0
Wookie01
Wookie01

Question 3 years ago

Hi, I am really keen to complete this project but I am very new to Arduino and C++.

No doubt this is something that experienced coders see every day, and I am sorry if it is frustrating that newbies don't understand it. :(
I have researched for days trying to solve this without reaching out, but it has defeated me.

I have downloaded the .ino file and libraries, and imported the libraries into my Arduino system.

When I try to compile the sketch I get the following error messages and I cannot determine where or why they are being generated?

In function 'void setup()':
standalone_altimeter.ino:56:7: error: 'class BMP280' has no member named 'setOversampling'
bmp.setOversampling(4);

In function 'void loop()':
standalone_altimeter.ino:65:21: error: 'class BMP280' has no member named 'startMeasurment'
char result = bmp.startMeasurment();

In the loop section I also have similar errors for
'getTemperatureAndPressure' and
'altitude'

If anyone is able to advise how to fix these errors I would be extremely grateful.

Thanks,
Graham

0
Wookie01
Wookie01

Answer 3 years ago

I have solved this, the problem was that the system was not loading the libraries supplied above, but was drawing them from the arduino stock library.

I was able to force the correct libraries and now it is completing verification.

Next step is to source an I2C OLED to complete the hardware setup, then it should be up and running hopefully

0
dantestellarjr
dantestellarjr

Reply 1 year ago

Hi Wooki,
I know its been some time, but how exactly did you do that? I am having the same errors as Graham stated above and don't quite know what you mean in terms of forcing the correct libraries.

Thanks
Dante

0
Wookie01
Wookie01

Reply 1 year ago

Hi Dante,
From memory the problem was because 'my' library had the same name as the arduino stock library. To fix it I gave each of my libraries a different name (for example put _GM) on the end of each library and make sure that you use the name of your customised library in your code where you call the libraries. Once you have uploaded your libraries to the project this will force the correct libraries to load.
Hope that helps,
Graham :)

0
dantestellarjr
dantestellarjr

Reply 1 year ago

Thank you Graham! To clarify cause I too am relatively new to arduino, if I upload a library, where it says include, is where I should modify the name as you stated?

0
Wookie01
Wookie01

Reply 1 year ago

Yes the include statements should use the modified library name that you have uploaded.
Good luck with it. :)

0
steveflora
steveflora

Question 2 years ago on Step 3

Question about the barometric pressure.

I'm assuming the 1013.25 is the nominal pressure at sea level. I live at 2800 feet. Is there a table or something you reference to get the nominal pressure for where I live?

Also

I'm interested in the feed back you go how the whole thing was mounted. My plan is to make a couple of these to mount in my land cruiser and 73 chevy pickup. I'm looking for what is available off the shelf that could mount nicely in both vehicles

Steve Flora
Middleton, Idaho (USA)

0
dpairplanes48
dpairplanes48

Answer 1 year ago

Hi,

I am doing the same thing. I think the best bet is to 3D print something. I dont have a 3D printer so I went on ebay and found a little stand for the screen. Hopefully that does the trick for now.

0
arooster1
arooster1

Answer 2 years ago

the local pressure readings will change over time due to weather fluxuaitons (high pressure systems, low pressure systems, etc.). You can get updated settings for your area from weather reports or search for the local airport's "METAR" (it's a condensed weather report for pilots). All aircraft set their alitimeters using the local pressure reading for the airport that they're taking off from or landing at.

0
Gangesh Tomar

Hi
You have solved my great problem
I don't know how much should I thank you
Basically I wanted a altimeter for model rockets
Altimeters available are very costly and the One you made is very cheap
Only one problem that I'M new to ardunio
I will copy the code but I did not understand code line 1 and 2
How we will insert library ?
Please tell me.
Thank you very much

0
dpairplanes48
dpairplanes48

Reply 1 year ago

Hi,

I am new as well. This is my first project. You basically have to extract the two ".rar" files, and place them in the arduino library.

In your computer, you go to Documents, find the folder named Arduino, and then in that folder is one called Libraries. Just drag the folders you got from the .rar files and put them in there. They should be called U8glib and BMP280.

Hope that helps

0
dpairplanes48
dpairplanes48

Question 1 year ago

Hi,

Love this, my first project as well and I am quite proud of myself haha. Works great.

Question: I was able to convert the altitude to feet. However, how do I change the temperature to Fahrenheit?

Thanks!

0
Tailspin9
Tailspin9

Question 1 year ago

If i want to display the Alt in feet instead of Meters - How do i change that Formula - or where.
Thanks For a nice project.