Trouble calculating difference in 2 numbers

I am new to Arduino and am working on an altimeter. I got myself a Spark Fun MS8607 temp, pressure, and humidity sensor. I am getting good altitude readings but I want to calculate altitude difference as well. I do this by finding the difference between the present altitude and the altitude from 3 seconds ago. I wrote some code that shows this below. I move the sensor up and down between readings and whenever I print values the present and past altitude readings are always the same and thus the difference is always zero.
I have been trouble shooting for the past few days and any help would be greatly appreciated!


#include <SparkFun_PHT_MS8607_Arduino_Library.h>

#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// Click here to get the library: http://librarymanager/All#SparkFun_PHT_MS8607
int chipSelect=2;
MS8607 barometricSensor;
File mysensordata;
float Velocity_past=0;

float  startingPressure=0;
int Velocity = 0;
float TimeKeeper=0;

float  Altitude_current=0;

void setup(void)
  pinMode (10, OUTPUT);
  Serial.println("Qwiic PHT Sensor MS8607 Example");


  if (barometricSensor.begin() == false)
    Serial.println("MS8607 sensor did not respond. Trying again...");
    if (barometricSensor.begin() == false)
      Serial.println("MS8607 sensor did not respond. Please check wiring.");
      while (1)

  //Set the resolution of the sensor to the highest level of resolution: 0.016 mbar

  //Take 16 readings and average them
  startingPressure = 0.0;
  for (int x = 0; x < 16; x++)
    startingPressure += barometricSensor.getPressure();
  startingPressure /= (float)16;

  Serial.print("Starting pressure=");

void loop(void)
   float currentPressure = barometricSensor.getPressure();
int altitudeDelta = barometricSensor.altitudeChange(currentPressure, startingPressure);
int (alt_past) = (altitudeDelta);


int altitude_difference = 0;
int (alt_present) = (altitudeDelta);
altitude_difference = alt_present - alt_past;

I think you are dreaming. My former company had a customer that had an aviation related product. It had an expensive barometer on their circuit board. The best they could detect was 15 feet change in altitude. I doubt your device can do that well.

Is that on a rocket or something? How much altitude change can you get in 3 seconds?

By hand?

What does "good readings" mean? If you can get good readings you should be able to subtract them.

I don't know anything about this thing but I'd be surprised if you can measure a change of a few feet (or a few meters).

Not sure what all the extraneous parenthesis are for.

You are taking the pressure reading at the start of loop, then saving the calculated altitude as the previous altitude, waiting three seconds, and comparing the same calculated altitude with that you just stored as the previous altitude. Of course it doesn't change, you did not take a 2nd pressure reading.

Thanks a lot!
That did it, thanks to everyone who replied and yes I am using this on a model rocket!

(Why) the (parentheses) here, (and) not (other) declarations?

I've detected a foot or two change with some MEMS barometers... I think it was the SCP1000-D1, which has (had) a resolution of 1.5Pa (12cm height) and a 19bit ADC.

When you are measuring real pressure values, do they change as

Tom... :grinning: :+1: :coffee: :australia: