Help with my project

I’m part of the high altitude balloon project. And I want to trigger the buzzer when the balloon is dropping. That’s why I want temperature, pressure and altitude should be factors that turns on the alarm. I mentioned this before.

Can anyone check the code I changed and tell me if it looks nice (I delete the lcd part). If you guys see the part that I can delete, then tell me. Also, because I want the buzzer to be turn on by 3 factors, I believe that this code have to be changed. In this code, the buzzer turns on by altitude difference. However, I want to be turn on by three factors. Can anyone help me with it?

#include <Wire.h>
#include "Adafruit_BMP180.h"

/*************************************************** 
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_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 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
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(";");
// 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

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

To make it controlled by more than one factor, you'll just need to modify the code in altitudealarm() to check those other conditions as well. What form those changes will take depends on your needs, of course.

ytuenci:
I mentioned this before.

Where, When? if it was on another Forum Thread post a link to it.

Can anyone check the code I changed and tell me if it looks nice

Have you tested it?
Does it do what you want?
If not, what does it do, and what should it do?

…R

PS it looks lovely.

"t_ini" should be 'unsigned long', not 'int'.

" time_ = time[average];" references off the end of the array.

The measurements are not scheduled so the "diffAlt" is an unknown rate of altitude change. Say your loop() runs in 3 milliseconds. That means your first alarm (1 meter in 3 milliseconds) would be about 333 meters per second or 1200 km/h!

It is probably not necessary to round the altitude to the nearest half meter BEFORE you check for the alarm. It's OK to do it afterward if you want to display the rounded data.

http://forum.arduino.cc/index.php?topic=313809.0

This is the link from another forum

Johnwasser: So can you fix some of mine and give specific examples? Do you think I can just delete the altround part? Robin2: I didn't test yet, because I need to connect the sensor to Arduino. Some of errors comes out that deals with my sensor. Do you know the reason for it?

I also realized that the buzzer turns on without considering the altitude difference. It's just changing the frequency and the speed of alarm. What do I need to do with it?

Can I delete this part?

lcd.begin(16, 2); // start the library lcd.setCursor(0,0);

I fixed the code. This is my new code. Check it and give me some suggestion for it. click the link to know more information.

#include <Wire.h>
#include "Adafruit_BMP180.h"

/*************************************************** 
 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_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;
float diffPre,prePre;
float diffTemp,preTemp;
int i;
unsigned long tcycle=0;



//CONFIGURATION

void setup() {
 
 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();
alarm();                                // alarm
serialview(temp_,alt_,pre_,presea_,ralt_);      // print values on serial
preAlt=alt_;    // set previous altitude
prePre=pre_;
preTemp=temp_;

}

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 alarm(){ 
diffAlt=alt_-preAlt;
diffPre=pre_-prePre;
diffTemp=pre_-preTemp;
if(diffAlt>=alarm0 && diffAlt<alarm1 && diffPre<=alarm0 && diffPre>alarm1 && diffTemp<=alarm0 && diffTemp>alarm1){          // alarm0 upper
 tone(buzzer,1000,100);
}
else if(diffAlt>=alarm1 && diffPre<=alarm1 && diffTemp<=alarm1){                      // alarm1 upper
 tone(buzzer,1000,100);
 delay(500);
 tone(buzzer,1000,100);
}
else if (diffAlt<=-alarm0 && diffAlt<-alarm1 && diffPre>=alarm0 && diffPre<alarm1 && diffTemp>=alarm0 && diffTemp<alarm1){  // alarm0 lower
 tone(buzzer,100,100);
}
 else if(diffAlt<=-alarm0 && diffPre>=alarm1 && diffTemp>=alarm1){                   //alarm1 upper
 tone(buzzer,100,100);
 delay(500);
 tone(buzzer,100,100);
}
}//end 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

Also this the error when I check it
High_Balloon_Project.ino:2:29: error: Adafruit_BMP180.h: No such file or directory
High_Balloon_Project:24: error: ‘Adafruit_BMP180’ does not name a type
High_Balloon_Project.ino: In function ‘void setup()’:
High_Balloon_Project:41: error: ‘lcd’ was not declared in this scope
High_Balloon_Project:45: error: ‘bmp’ was not declared in this scope
High_Balloon_Project.ino: In function ‘void loop()’:
High_Balloon_Project:59: error: ‘bmp’ was not declared in this scope

ytuenci: I fixed the code.

Also this the error when I check it High_Balloon_Project.ino:2:29: error: Adafruit_BMP180.h: No such file or directory High_Balloon_Project:24: error: 'Adafruit_BMP180' does not name a type

It doesn't look "fixed". Looks like your next step should be to download and install the Adafruit_BMP180 library.

Johnwasser: I don't understand the comment that you wrote before. Can you show me the example by fixing some of the codes?

ytuenci: Can you show me the example by fixing some of the codes?

The way I fix my own code is by trying it out, making a careful note of what happens (or does not happen). And then sitting back and thinking hard about "why is it doing that" and "where is my mistake". I put in lots of Serial.print() instructions so I can see the values changing. Often I write a separate short program to test something.

...R

ytuenci: Johnwasser: I don't understand the comment that you wrote before. Can you show me the example by fixing some of the codes?

It isn't feasible for us to remotely install a library correctly on your machine, so that's down to you - it's not a code fix.

Talk to these guys - they look to be working on something similar, and judging by their address, are very close to you.

 #include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP180.h>

// Connect VIN of the BMP180 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

 // 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;
float diffPre,prePre;
float diffTemp,preTemp;
int i;
unsigned long tcycle=0;

//CONFIGURATION

void setup() {
   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)");
  int 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];

alarm();                                // alarm
serialview(temp_,alt_,pre_,presea_,ralt_);      // print values on serial
preAlt=alt_;    // set previous altitude
prePre=pre_;
preTemp=temp_;

}

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 alarm(){ 
diffAlt=alt_-preAlt;
diffPre=pre_-prePre;
diffTemp=pre_-preTemp;
if(diffAlt>=alarm0 && diffAlt<alarm1 && diffPre<=alarm0 && diffPre>alarm1 && diffTemp<=alarm0 && diffTemp>alarm1){          // alarm0 upper
 tone(buzzer,1000,100);
}
else if(diffAlt>=alarm1 && diffPre<=alarm1 && diffTemp<=alarm1){                      // alarm1 upper
 tone(buzzer,1000,100);
 delay(500);
 tone(buzzer,1000,100);
}
else if (diffAlt<=-alarm0 && diffAlt<-alarm1 && diffPre>=alarm0 && diffPre<alarm1 && diffTemp>=alarm0 && diffTemp<alarm1){  // alarm0 lower
 tone(buzzer,100,100);
}
 else if(diffAlt<=-alarm0 && diffPre>=alarm1 && diffTemp>=alarm1){                   //alarm1 upper
 tone(buzzer,100,100);
 delay(500);
 tone(buzzer,100,100);
}
}//end alarm

I built the hardware and tried to run the code. However, the error came up.
Can Anyone help me with fixing the error?

High_Balloon_Project:20: error: ‘Adafruit_BMP180’ does not name a type
High_Balloon_Project.ino: In function ‘void setup()’:
High_Balloon_Project:36: error: ‘bmp’ was not declared in this scope
High_Balloon_Project.ino: In function ‘void loop()’:

That sounds like you have not installed the Adafruit library correctly.

...R

ytuenci, I offer no other help that pointing out that you posted on the :

Project Guidance Advice on general approaches or feasibility

forum.

This is were we point out the simple things you could miss on the feasibility of a project.

in the

Programming Questions Understanding the language, error messages, etc.

forum, you will get a great many more eyes from people who work with programming every day. this forum has some great guys who do it all, but it also has hardware guys, for programming... not so much.