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