Suggestion for my project

I'm the student who is currently working for high altitude balloon. I'm trying to create buzzer that turns on by temperature difference, pressure difference, and altitude difference. I believe that when the temperature (new) - temperature (old) is positive or zero, altitude (new) - altitude (old) is negative or zero, and pressure (new) - pressure (old) is positive or zero, then the buzzer will turn on. I want to have some suggestion for sensors for this project and some guide code for it.

Please stop cross-posting. Multiple other threads removed.

The BMP085 barometric pressure sensor would work for you if the sample rate doesn't need to be over about 10 samples per second. There are libraries available and they have functions that return pressure , altitude and temperature.

groundfungus: The BMP085 barometric pressure sensor would work for you

Superseded by BMP180 in fact, but essentially the same. Full details including tutorial here at ada.

How are you going to measure altitude, I ask because you are making decisions about both changes in pressure and altitude? You state "altitude (new) - altitude (old) is negative or zero, and pressure (new) - pressure (old) is positive or zero" which is the same things assuming the pressure you refer to is atmospheric pressure. Most altimeters rely on atmospheric pressure to determine altitude so as altitude goes up pressure goes down.

Use a BMP180 to measure pressure and temperature in a well proven and rock solid interface at a great price and you will be set. Be careful going with the freescale MPLXXXX line as some of them do not provide temperature measurements that can be used for measuring ambient temperature. The temperature value from some of the MPLXXX's are used strictly for internal compensation and calibration and is not calibrated for external use.

wade

I’m trying to measure the altitude with the sensor that could measure altitude, temperature and pressure. I’m trying to turn the alarm as the altitude is decreasing, which means that both temperature and pressure is increasing.
I’m a beginner with Arduino. So I’m kind of confused with how to write code. That’s why I need a guide code for this project

Thank you guys for your suggestion.

tlfcp: I'm trying to measure the altitude with the sensor that could measure altitude, temperature and pressure.

Many sensors don't measure altitiude as such, they measure pressure and convert it. GPS is another way of finding altitude.

wwbrown: How are you going to measure altitude, I ask because you are making decisions about both changes in pressure and altitude? You state "altitude (new) - altitude (old) is negative or zero, and pressure (new) - pressure (old) is positive or zero" which is the same things assuming the pressure you refer to is atmospheric pressure. Most altimeters rely on atmospheric pressure to determine altitude so as altitude goes up pressure goes down.

Use a BMP180 to measure pressure and temperature in a well proven and rock solid interface at a great price and you will be set.

Pressure is converted to altitude based on either the standard sea-level pressure of 1013.25hPa or the actual local pressure adjusted to sea-level. Yesterday I happened to be comparing the altitudes at home as measured by my adafruit gps and adafruit bmp180. With the bmp code changed to use the QNH from local airport FAGM, the two values were within 4 metres of each other. That's about the height of my house, at almost 1800masl.

The adafruit library (see my link a few posts above) has all the maths built in.

(But yes, it's a bit chicken and eggy.....)

I’m trying to use BMP180 for my sensor.

So do you guys think my factor could be pressure and temperature for a trigger that turns the alarm?

Also, I got my guide code. However, this code has things that I don’t need like showing on the LCD, the sensor is different. Can anyone help me with it?

#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

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

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

For my project, i don’t need the lcd part.

What do I need to delete in the program?

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¶;ALTITUDE(m);PRESSUREsealevel(m);REAL ALTITUDE(m);TIME(us)”);
t_ini=micros();
}

Also, this code only turns on the buzzer by altitude difference. However, I want to turn the buzzer with pressure, altitude, and temperature measurement as I mentioned. Do you guys have any suggestion?

Do I need to delete this code too?

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

No, serialview() looks useful. You need to be able to see on your computer what the Arduino is sensing, while you are testing this. This function looks very helpful for testing.

Yes, to answer the original question, you can use temperature and pressure to trigger an alarm. But you didn't say why. Why do you need an alarm (who will hear it?) and what are the conditions for the alarm to be triggered?

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.

#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.

Can anyone please help me? I cannot do this by myself.