Using the BMP (API v1)

This page applies to the old sensor driver, and is provided here for reference sake. We recommend using the new 'Unified' BMP085 driver (API v2) for any future projects.
To use this sensor and calculate the altitude and barometric pressure, there's a lot of very hairy and unpleasant math. You can check out the math in the datasheet but really, its not intuitive or educational - its just how the sensor works. So we took care of all the icky math and wrapped it up into a nice Arduino library.

You can find the Arduino library repository on github To install it, click this button to download the compressed ZIP file then install it. This guide will help you with the install process if you have never installed an Arduino library.

The same driver is used for both the BMP085 and BMP180!

Restart the IDE

Now you can run this first example sketch

#include "Wire.h"
#include "Adafruit_BMP085.h"
 
Adafruit_BMP085 bmp;
 
void setup() {
  Serial.begin(9600);
  bmp.begin();  
}
 
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
 
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
 
    Serial.println();
    delay(500);
}
Then open up the serial monitor at 9600 baud. The sketch will continuously print out the temperature in °C and pressure in Pa (Pascals). You can test that the sensor is measuring variations in temperature and pressure by placing your fingertip over the open port hole in the top of the sensor. The temperature and pressure will increase as you can see here:

Altitude Measurements

Since we know that pressure drops as we gain altitude (that's why air is so thin on mountain-tops) we can compute the current altitude knowing the pressure and temperature. Again, there's a bit of hairy math involved, you can read about the calculations on wikipedia (where this graph is from).
With the Arduino library, we take care of that for you! Simply run this sketch which will return the current altitude based on the pressure.
#include "Wire.h"
#include "Adafruit_BMP085.h"
 
Adafruit_BMP085 bmp;
 
void setup() {
  Serial.begin(9600);
  bmp.begin();  
}
 
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
 
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
 
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");
 
    Serial.println();
    delay(500);
}
Run the sketch to see the calculated altitude.
For example, according to the sensor we are 21.5m below sea level. Only problem is, I know for a fact that our current location is not below sea level! So what's wrong with the sensor? Turns out the sensor is just fine. The problem is that the pressure at sea level changes with the weather. So we need to 'normalize' the sensor, and let it know what the sea-level pressure is. You can look up the current sea level pressure on any weather site.
Unfortunately there are half-dozen different units of pressure. here we see it in inches, that's technically "Mercury Inches" or "Hg Inches We need it in Pascals, so we'll convert it!
OK so that's 101,964 Pascals. Open up the Examples->BMP085test example from the Arduino IDE menubar and edit the line where you pass in the 'corrected' altitude.
Now it will print out the correct altitude! 30 meters which is a lot better.
Last updated on 2016-09-19 at 01.06.30 PM Published on 2012-07-29 at 11.58.38 AM