For detecting small altitude changes, reading the barometric altitude, or for just detecting changes in pressure, you may want to use a pressure sensor. The Bosch BMP-180 is a very reasonably priced one, which is accessed over I2C. There are several nice breakout boards available from Adafruit.featuring the BMP-180. There is, for example, one featuring only the BMP-180, and another one featuring gyros and accelerometers as well.
No matter which, you would access it in a similar fashion.
Next decide in which mode you want the device to run. Check out the OperatingMode for details. The higher resolution, the longer time it takes to read values, and the higher the current draw.
If you are using the standard address and i2c bus, next create a BMPDevice:
BMPDevice bmp = new BMPDevice(OperatingMode.STANDARD);
Next, reading the pressure, altitude and temperature is done like this:
System.out.println(String.format(“Temperature: %.1fC, Pressure: %dhPa, Altitude: %.1fm”,
bmp.readPressure() / 100,
To run the standard example, which will print the above every two seconds:
sudo java -classpath .:classes:/opt/pi4j/lib/*:./bmp.jar se.hirt.pi.adafruit.bmp.test.BMPTest
The Bosh BMP-180 is an easy way to measure the barometric altitude and/or changes in pressure.