Altimeter_v0 project BMP085

Hello! here my first public development. Basically is an altimeter for paragliding.

HOW IT WORKS
It indicates by LCD the values, and sounds when is going up or down at a defined velocity.
Currently is measuring properly 0.5m.
On the LCD are: temperature, altitude, pressure and altitude difference like next:


29.00ºC 72.50m
100.45kPa -0.05m


The buzzer have 2 alarms with two different sounds for up and down movements.

ELECTRONIC FOR TEST:
-Arduino Uno
-LCD Keypad Shield
-BMP085
-Buzzer




CODE

#include <Wire.h>
#include "Adafruit_BMP085.h"
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


/*************************************************** 
  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/
// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here
// Buzzer conected to A1 by 1k resistor
// LCD keypad shield

  // VARIABLES CONFIGURATION
int const average=10;           // average value 
float     alarm0=1;             // alarm0 level
float     alarm1=2;             // alarm1 level

//VARIABLES
int const buzzer=A1;
Adafruit_BMP085 bmp;
int t_ini,altt;
unsigned long time[average],time_;
float temp[average],pre[average],alt[average],presea[average],ralt[average];
float temp_,pre_,alt_,presea_,ralt_;
float diffAlt,preAlt;
int i;
unsigned long tcycle=0;



//CONFIGURATION

void setup() {
  
  
  
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
  tone(buzzer,300,2000);
  Serial.begin(9600);
    if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }
    Serial.println("TEMPERATURE(ºC);PRESSURE(Pa);ALTITUDE(m);PRESSUREsealevel(m);REAL ALTITUDE(m);TIME(us)");
t_ini=micros();
}

//PROGRAM
void loop() {

//READ & AVERAGE
temp_=0,pre_=0,alt_=0,presea_=0,ralt_=0;    // inicialize the variables to be read
for(i=0;i<average;i++) {
    temp_+=bmp.readTemperature(); 
    pre_+=bmp.readPressure();
    alt_+=bmp.readAltitude();
    presea_+=bmp.readSealevelPressure();
    ralt_+=bmp.readAltitude(101500);
if (i>0){                                  // variable time between readings
      time[i]=micros()-time[i-1];    
    }else {
      time[i]=micros();
    }
  }
                                           // apply the average function to the variable read.
temp_=temp_/average;
pre_=pre_/average;
alt_=alt_/average;
presea_=presea_/average;
ralt_=ralt_/average;
time_=time[average];

altround();
altitudealarm();                                // altitude alarm
LCDview(temp_,alt_,pre_,diffAlt);               // print values on LCD
serialview(temp_,alt_,pre_,presea_,ralt_);      // print values on serial
preAlt=alt_;                                    // set previous altitude
}//end loop



//++++++++++SUBROUTINES++++++++++++++
void LCDview(float temperature, float altitude, float pressure, float differenceAltitude){
 lcd.setCursor(0,0);           // move cursor to second line "1" and 9 spaces over
 lcd.print(temperature,2);      // display seconds elapsed since power-up
 lcd.print("\337C ");
 lcd.print(altitude,2);      // display seconds elapsed since power-up
 lcd.print("m");
 lcd.setCursor(0,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(float(pressure)/1000,2);      // display seconds elapsed since power-up
 lcd.print("kPa "); 
if(differenceAltitude>=0){
 lcd.print("+");
 lcd.print(differenceAltitude,2);      // display seconds elapsed since power-up
 lcd.print("m    ");
}else{
 lcd.print(differenceAltitude,2);      // display seconds elapsed since power-up
 lcd.print("m    ");
}
}//end LCDview



void serialview(float temperature, float altitude, float pressure, float pressuresea, float realaltitude){
Serial.print(temperature);
Serial.print(";");
Serial.print(pressure);
Serial.print(";");
// Calculate altitude assuming 'standard' barometric
// pressure of 1013.25 millibar = 101325 Pascal
Serial.print(altitude);
Serial.print(";");
Serial.print(pressuresea);
Serial.print(";");
// you can get a more precise measurement of altitude
// if you know the current sea level pressure which will
// vary with weather and such. If it is 1015 millibars
// that is equal to 101500 Pascals.
Serial.print(realaltitude);
Serial.print(";");
Serial.println(micros());
}//end serialview



void altitudealarm(){ 
diffAlt=alt_-preAlt;
if(diffAlt>=alarm0 && diffAlt<alarm1){          // alarm0 upper
  tone(buzzer,1000,100);
}
else if(diffAlt>=alarm1){                      // alarm1 upper
  tone(buzzer,1000,100);
  delay(500);
  tone(buzzer,1000,100);
}
else if (diffAlt<=-alarm0 && diffAlt<-alarm1){  // alarm0 lower
  tone(buzzer,100,100);
}
  else if(diffAlt<=-alarm0){                   //alarm1 upper
  tone(buzzer,100,100);
  delay(500);
  tone(buzzer,100,100);
}
}//end altitude alarm



void altround(){
// adjust altitude round to 0.5 meters
// (x,x.25] --> x    |    [x.75,x+1) --> x    |    [0.25,0.75) --> x.5
  altt=(int) alt_;             
  if((alt_-float(altt)<=0.25)){
  alt_=float(altt);
}else if (alt_-float(altt)>=0.25 && alt_-float(altt)<0.75){
  alt_=float(altt)+0.5;
}else if (alt_-float(altt)>=0.75){
  alt_=float(altt+1);
} 
}//end altround

IMPROVEMENTS
-A lot of code improvements
-Sensor accuracy (possible MS5611 or data filtering)
-Arduino Nano+LCD+2 push buttons+buzzer= small size

Any help, improvement or advise?

Happy to share my work

Super cool project.
Try the BMP180 instead of the BMP085. When used with higher accuracy it is slower, but the accuracy is very good.
Was there a question somewhere ?

Hi! thanks for information. I have now a bmp180. It's smaller. I will try the acurracy, but on the datasheet, the acurracy is not so different.

"The ultra-low power consumption down to 3 ?A makes the BMP180 the leader in power saving for your mobile devices. BMP180 is also distinguished by its very stable behavior (performance) with regard to the independency of the supply voltage."
http://www.bosch-sensortec.com/de/homepage/products_3/environmental_sensors_1/bmp180_1/bmp180

I discovered a better sensor MS5611 over 0.3m and the price is double of BMP180/085.

MY CURRENT PROBLEM:

I have a problem when the device is near to the altitud change To explain it "*" means problematic zone.


10---------10.5---------11---- [meters]

I increase the average up to 10 but the measurements are fiference +/-0.8m.

I read somthing about kalman filtering but I don't know so much about it...

Other possible problem is the sensor placement. Usually the altimeters are inside a box with a small hall (1mm)

TO DO:
-use the switch to create menu
-min, max values
-set the 0 altitude or adjust to the real altitud
-increase the alarms and simplify the code
-creat a box & smaller version arduino nanp+bmp180+lcd 5110
-...

Good news! Recently I have been working with a better sensor, the ms5611. This cost 12€ depending on the seller. This sensor is 0.1m precision and over 50 measurements each second.

With barometric sensors is very important a box, if you want use outside (because of the wind). The box require a small hole.

My work is with a arduino UNO/NANO v3 and the MS5611. I have a code ready for a 5110 screen, with a small menu.

The sensor code is based on the post about MS5611:

Other MS5611 codes are not working properly. I supose is because of the sensor comes from china and maybe is not exactly the same.

In a few days I will post the code. I need organize the code.

I did not look at your code that close, but do you have a way of entering the local altimeter setting? That will improve accuracy more than any of those devices.

I explain:
-BMP085/180, is not close, over 0.5m (my code over 1 m).
-MS5611, is the closest at 0.1m (now I obtained 0.5m outside maybe less I am wowking with this)

So, I am working only with the MS5611, step by step.

Gaspi:
I explain:
-BMP085/180, is not close, over 0.5m (my code over 1 m).
-MS5611, is the closest at 0.1m (now I obtained 0.5m outside maybe less I am wowking with this)

So, I am working only with the MS5611, step by step.

Only if the local sea level pressure is 29.92. Otherwise it could be several meters off.

Ok I am sorry! You refer the local sea level pressure? This is a future work. This will be a setting user adjusting the sea pressure or the altitude in a specific place. Any idea?

I would set up two buttons and a switch. With the switch in one position adjusts the ground altitude, and in the other adjusts the alarm altitude.