Help with my project


i'm part of high altitude balloon project. , want trigger buzzer when balloon dropping. that's why want temperature, pressure , altitude should factors turns on alarm. mentioned before.

can check code changed , tell me if looks nice (i delete lcd part). if guys see part can delete, tell me. also, because want buzzer turn on 3 factors, believe code have changed. in code, buzzer turns on altitude difference. however, want turn on 3 factors. can me it?

code: [select]
#include <wire.h>
#include "adafruit_bmp180.h"

/***************************************************
written limor fried/ladyada adafruit industries.  
bsd license, text above must included in redistribution
****************************************************/
// connect vcc of bmp085 sensor 3.3v (not 5.0v!)
// connect gnd ground
// connect scl i2c clock - on '168/'328 arduino uno/duemilanove/etc thats analog 5
// connect sda i2c data - on '168/'328 arduino uno/duemilanove/etc thats analog 4
// eoc not used, signifies end of conversion
// xclr reset pin, not used here
// buzzer conected a1 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_bmp180 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 library
lcd.setcursor(0,0);
tone(buzzer,300,2000);
serial.begin(9600);
  if (!bmp.begin()) {
serial.println("could not find 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 variables 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 average function variable read.
temp_=temp_/average;
pre_=pre_/average;
alt_=alt_/average;
presea_=presea_/average;
ralt_=ralt_/average;
time_=time[average];

altround();
altitudealarm();                                // altitude alarm
serialview(temp_,alt_,pre_,presea_,ralt_);      // print values on serial
prealt=alt_;                                    // set previous altitude
}

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(";");
// can more precise measurement of altitude
// if know current sea level pressure will
// vary weather , such. if 1015 millibars
// equal 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 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


moderator edit:
[code]
[/code]
tags added.

to make controlled more 1 factor, you'll need modify code in altitudealarm() check other conditions well. form changes take depends on needs, of course.


Arduino Forum > Using Arduino > Project Guidance > Help with my project


arduino

Comments