Arduino BMP085 Tutorial

The BMP085 is a relatively cheap barometric pressure sensor from Bosch. I believe this sensor is kinda old (no information about this device is found on the Bosch site) and yet it’s still used today because of its simplicity. This Arduino BMP085 tutorial covers the basics of using this device and perhaps some short lesson on pressure and weather.

The BMP085

As mentioned, this sensor is old and has since been replaced with the BMP180. But thankfully, there is not much change between the two and thus we can use the same code. Anyway, here's is the BMP085 datasheet courtesy of Digikey.

There are a number of breakout boards out in the market featuring the BMP085:

 

I got my hands on DFRobot’s BMP085 breakout board. But again, all boards will work on the same code that I will be using here so don’t fret.

Barometric Pressure and Weather

The BMP085 delivers barometric pressures from 30 to 110 kiloPascals. It can give temperature readings too, although limited to 0 to 65 degree celsius.

Barometric or atmospheric pressure is one indicator of good or bad weather. We expect the pressure at sea level at just around 101 kiloPascals. A low pressure, specifically a rapidly lowering one, is an indication of an upcoming rain. A high pressure typically says the weather is fair. A difference of around 350 Pa indicates a drastic change in weather.

Atmospheric pressure varies with altitude so the pressure is not the same where you’re up on a mountain and when you’re on the beach. The higher the altitude, the lower the pressure. I always thought of this this way: the lower I am, the more air is above me and thus the heavier the air pushes down on me.

Temperature and humidity also affects atmospheric pressure so having the BMP085 might not be enough for a weather prediction system.

I’ve built two projects using the BMP085, one utilizing barometric pressure as weather indicator and another using the same pressure reading for altimetry.

Connecting the BMP085 to an Arduino

This sensor uses I2C and thus only uses four wires when connected to a microcontroller. We will connect the SDA line to the Arduino’s SDA line at A4, and the SCL line to the Arduino’s SCL line at A5. The board runs on 5V so will also connect the VCC pin to Arduino’s 5V and GND to Arduino’s GND.

BMP085

Arduino

SDA

A4

SCL

A5

VCC

5V

GND

GND

Below is a fritzing diagram for this tutorial. I used an Arduino Nano which is essentially the same as the UNO.

Here's my actual setup:

Arduino BMP085 Programming

The I2C address of the BMP085 is 0x77 and the pressure and temperature values are stored as 16-bit data in different registers. But it’s not that easy as there are a lot of calibrations involved.

To simplify things, we will be using Adafruit’s BMP085/BMP180 library. The library contains a single sketch that allows us to read temperature, pressure, sea level pressure and even altitude!

Adafruit_BMP085 bmp;
  
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }
}
  
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.print("Pressure at sealevel (calculated) = ");
    Serial.print(bmp.readSealevelPressure());
    Serial.println(" Pa");

    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");
    
    Serial.println();
    delay(500);
}

Upload this sketch to your Arduino, and open the serial monitor to view the data.

The sketch begins with declaring an object:

Adafruit_BMP085 bmp;

We can check if the wiring is ok by using the begin() function. If this:

if(!bmp.begin()){}

Returns false, then the BMP085 is not detected by the Arduino.

Reading the pressure only requires

bmp.readPressure();

For temperature, it’s just:

bmp.readTemperature();

and for altitude:

bmp.readAltitude();

Now I mentioned that atmospheric pressure is dependent on altitude. Of course, it’s true the other way around. The altitude reading might not be too accurate because it assumes a 101.325 kPa pressure at sea level. You can determine the current sea level pressure (SLP) on your area through Accuweather.

For example, the SLP in my city is 29.80 inHg which is equivalent to 100944 Pa. Then the true altitude can be acquired using

bmp.readAltitude(100944);

I hope you learned something from this tutorial. Check out two Arduino projects I created using the BMP085, an altimeter and an IoT environment monitor.

Leave a Reply

Your email address will not be published. Required fields are marked *