altitude pressure calculation per arduino function (till 80 km)

For everybody who's toying around with weather balloons...
Have fun! :slight_smile:

/* *** Pressure altitude calculation ***
 * Original equation by Steve Randall (http://randomaerospace.com):
 * a [m] = ln(p0 [Pa] / p [Pa]) * 7238,3 [m]
 * a [m]:   altitude;                          unit: Meter
 * p0 [Pa]: pressure at sea level;             unit: Pascal
 * p [Pa]:  pressure at altitude to calculate; unit: Pascal
 * 7238,3:  correcture factor, found by Steve; unit: must be in Meter to do it mathematically correct.
 * In this sketch equation is adapted to Arduino's language.
 * You always have to use long-variables because integer will fail at altitudes above 32.768 km resp. pressure less than 1096 Pa.
 * Suggested pressure sensor: MS5607 ... MS5611 Series
 */

long pressureInPascal;
long druckhoehe;

void setup() {
  Serial.begin(9600);
  delay(2000);
  Serial.println("Demonstration der Druckhoehenkalkulation.\nDie hier verwendete Gleichung ist bis 80 km gueltig.");
}

void loop() {
  Serial.println("Eingabe (Druck in Pascal):");
  pressureInPascal = longInput();
  druckhoehe = calcPressureAltitude(pressureInPascal);
  Serial.println("Der Druck von " + String(pressureInPascal) + " Pa entspricht einer Hoehe von " + String(druckhoehe) + " Metern.");
}

// Function calculation of pressure altitude
long calcPressureAltitude(long _PressureInPascal) {
  long _Temp = (log(101325.0 / _PressureInPascal) * 72383.0);
  long _PressureAltitude = 0;
  if (_Temp % 10 > 5) {
    _PressureAltitude = 1;
  }
  _PressureAltitude = _PressureAltitude + long(_Temp / 10);
  return _PressureAltitude;
}

// input function
long longInput() {
  long _Result;
  char _Space = ' ';  
  while (Serial.available() == 0); {
    delay(3);
    _Result = Serial.parseFloat();
    while (Serial.available() > 0) {
      _Space = Serial.read();
    };
  };
  return _Result;
};
Serial.println("Demonstration der Druckhoehenkalkulation.\nDie hier verwendete Gleichung ist bis 80 km gueltig.");

sp.Serial.println(F("Demonstration der Druckhoehenkalkulation.\nDie hier verwendete Gleichung ist bis 80 km gueltig."));

Sorry, I already have seen it too.

Okay, translated...

/* *** Pressure altitude calculation ***
 * Original equation by Steve Randall (http://randomaerospace.com):
 * a [m] = ln(p0 [Pa] / p [Pa]) * 7238,3 [m]
 * a [m]:   altitude;                          unit: Meter
 * p0 [Pa]: pressure at sea level;             unit: Pascal
 * p [Pa]:  pressure at altitude to calculate; unit: Pascal
 * 7238,3:  correcture factor, found by Steve; unit: must be in Meter to do it mathematically correct.
 * In this sketch equation is adapted to Arduino's language.
 * You always have to use long-variables because integer will fail at altitudes above 32.768 km resp. pressure less than 1096 Pa.
 */

long pressureInPascal;
long altitudePressure;

void setup() {
  Serial.begin(9600);
  delay(2000);
  Serial.println("Demonstration of pressure altitude calkulation.\nEquation used here is valid until 80 km.");
}

void loop() {
  Serial.println("Input (Pressure in Pascal):");
  pressureInPascal = longInput();
  altitudePressure = calcPressureAltitude(pressureInPascal);
  Serial.println("A pressure of " + String(pressureInPascal) + " Pa equals to an altitude of " + String(altitudePressure) + " Meters.");
}

// Function calculation of pressure altitude
long calcPressureAltitude(long _PressureInPascal) {
  long _Temp = (log(101325.0 / _PressureInPascal) * 72383.0);
  long _PressureAltitude = 0;
  if (_Temp % 10 > 5) {
    _PressureAltitude = 1;
  }
  _PressureAltitude = _PressureAltitude + long(_Temp / 10);
  return _PressureAltitude;
}

// input function
long longInput() {
  long _Result;
  char _Space = ' ';  
  while (Serial.available() == 0); {
    delay(3);
    _Result = Serial.parseFloat();
    while (Serial.available() > 0) {
      _Space = Serial.read();
    };
  };
  return _Result;
};

No, you missed my RAM-saving addition

Sorry I'm just a beginner.
What means that "F(blabla)"?
Can you give me some explantations or a link I can read about?

Thank you AWOL.

Final Version: Feel free to modify/optimize...

/* *** Pressure altitude calculation ***
 * Original equation by Steve Randall (http://randomaerospace.com):
 * a [m] = ln(p0 [Pa] / p [Pa]) * 7238,3 [m]
 * a [m]:   altitude;                          unit: Meter
 * p0 [Pa]: pressure at sea level;             unit: Pascal
 * p [Pa]:  pressure at altitude to calculate; unit: Pascal
 * 7238,3:  correcture factor, found by Steve; unit: must be in Meter to do it mathematically correct.
 * In this sketch equation is adapted to Arduino's language.
 * You always have to use long-variables because integer will fail at altitudes above 32.768 km resp. pressure less than 1096 Pa.
 * Suggested pressure sensor: MS5607 ... MS5611 Series.
 */

long pressureInPascal;
long altitudePressure;

void setup() {
  Serial.begin(9600);
  delay(2000);
  Serial.println(F("Demonstration of pressure altitude calkulation.\nEquation used here is valid until 80 km."));
}

void loop() {
  Serial.println(F("Input (Pressure in Pascal):"));
  pressureInPascal = longInput();
  altitudePressure = calcPressureAltitude(pressureInPascal);
  Serial.println("A pressure of " + String(pressureInPascal) + " Pa equals to an altitude of " + String(altitudePressure) + " Meters.");
}

// Function calculation of pressure altitude
long calcPressureAltitude(long _PressureInPascal) {
  long _Temp = (log(101325.0 / _PressureInPascal) * 72383.0);
  long _PressureAltitude = 0;
  if (_Temp % 10 > 5) {
    _PressureAltitude = 1;
  }
  _PressureAltitude = _PressureAltitude + long(_Temp / 10);
  return _PressureAltitude;
}

// input function
long longInput() {
  long _Result;
  char _Space = ' ';  
  while (Serial.available() == 0); {
    delay(3);
    _Result = Serial.parseFloat();
    while (Serial.available() > 0) {
      _Space = Serial.read();
    };
  };
  return _Result;
};