Guide for BMP180 Barometric Sensor with Arduino

This post is about how to use the BMP180 barometric sensor with the Arduino. It is also applicable for other similar barometric sensors.

Introducing the BMP180 barometric sensor

The BMP180 barometric sensor (model GY-68) is the one in  the following figure (front and back view). It is a very small module with 1mm x 1.1mm (0.039in x 0.043in).

sensor

It measures the absolute pressure of the air around it. It has a measuring range from 300 to 1100hPa with an accuracy down to 0.02 hPa. It can also measure altitude and temperature.

The BMP180 barometric sensor communicates via I2C interface. This means that it communicates with the Arduino using just 2 pins.

Where to buy?

This sensor is very cheap. You can buy one for approximately $3. Find the best price on Maker Advisor.

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Pin wiring

Wiring the sensor to the Arduino is pretty straightforward:

Pin Wiring to Arduino Uno
Vin 5V
GND GND
SCL A5
SDA A4

Schematics

Wire your sensor to the Arduino as shown in the schematics below.

bmp180-barometris-sensor_bb

Code

To control the BMP180 barometric sensor, you need to install the SFE_BMP180 Library.

Installing the SFE_BMP180 Library

  1. Click here to download the SFE_BMP180 library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get BMP180_Breakout_Arduino_Library-master folder
  3. Rename your folder from BMP180_Breakout_Arduino_Library-master to BMP180_Breakout_Arduino_Library 
  4. Move the BMP180_Breakout_Arduino_Library folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Go to File > Examples >SparkfunBMP180 > SFE_BMP180_example.

This example is very well commented and explained on how the sensor reads the pressure, temperature and computes the altitude.

/* SFE_BMP180 library example sketch

This sketch shows how to use the SFE_BMP180 library to read the
Bosch BMP180 barometric pressure sensor.
https://www.sparkfun.com/products/11824

Like most pressure sensors, the BMP180 measures absolute pressure.
This is the actual ambient pressure seen by the device, which will
vary with both altitude and weather.

Before taking a pressure reading you must take a temparture reading.
This is done with startTemperature() and getTemperature().
The result is in degrees C.

Once you have a temperature reading, you can take a pressure reading.
This is done with startPressure() and getPressure().
The result is in millibar (mb) aka hectopascals (hPa).

If you'll be monitoring weather patterns, you will probably want to
remove the effects of altitude. This will produce readings that can
be compared to the published pressure readings from other locations.
To do this, use the sealevel() function. You will need to provide
the known altitude at which the pressure was measured.

If you want to measure altitude, you will need to know the pressure
at a baseline altitude. This can be average sealevel pressure, or
a previous pressure reading at your altitude, in which case
subsequent altitude readings will be + or - the initial baseline.
This is done with the altitude() function.

Hardware connections:

- (GND) to GND
+ (VDD) to 3.3V

(WARNING: do not connect + to 5V or the sensor will be damaged!)

You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:

Any Arduino pins labeled:  SDA  SCL
Uno, Redboard, Pro:        A4   A5
Mega2560, Due:             20   21
Leonardo:                   2    3

Leave the IO (VDDIO) pin unconnected. This pin is for connecting
the BMP180 to systems with lower logic levels such as 1.8V

Have fun! -Your friends at SparkFun.

The SFE_BMP180 library uses floating-point equations developed by the
Weather Station Data Logger project: http://wmrx00.sourceforge.net/

Our example code uses the "beerware" license. You can do anything
you like with this code. No really, anything. If you find it useful,
buy me a beer someday.

V10 Mike Grusin, SparkFun Electronics 10/24/2013
*/

// Your sketch must #include this library, and the Wire library.
// (Wire is a standard library included with Arduino.):

#include <SFE_BMP180.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

#define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters

void setup()
{
  Serial.begin(9600);
  Serial.println("REBOOT");

  // Initialize the sensor (it is important to get calibration values stored on the device).

  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.

    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
  }
}

void loop()
{
  char status;
  double T,P,p0,a;

  // Loop here getting pressure readings every 10 seconds.

  // If you want sea-level-compensated pressure, as used in weather reports,
  // you will need to know the altitude at which your measurements are taken.
  // We're using a constant called ALTITUDE in this sketch:
  
  Serial.println();
  Serial.print("provided altitude: ");
  Serial.print(ALTITUDE,0);
  Serial.print(" meters, ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(" feet");
  
  // If you want to measure altitude, and not pressure, you will instead need
  // to provide a known baseline pressure. This is shown at the end of the sketch.

  // You must first get a temperature measurement to perform a pressure reading.
  
  // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.

  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print("temperature: ");
      Serial.print(T,2);
      Serial.print(" deg C, ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.println(" deg F");
      
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.

      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);

        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(" inHg");

          // The pressure sensor returns abolute pressure, which varies with altitude.
          // To remove the effects of altitude, use the sealevel function and your current altitude.
          // This number is commonly used in weather reports.
          // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
          // Result: p0 = sea-level compensated pressure in mb

          p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0,2);
          Serial.print(" mb, ");
          Serial.print(p0*0.0295333727,2);
          Serial.println(" inHg");

          // On the other hand, if you want to determine your altitude from the pressure reading,
          // use the altitude function along with a baseline pressure (sea-level or other).
          // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
          // Result: a = altitude in m.

          a = pressure.altitude(P,p0);
          Serial.print("computed altitude: ");
          Serial.print(a,0);
          Serial.print(" meters, ");
          Serial.print(a*3.28084,0);
          Serial.println(" feet");
        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
    else Serial.println("error retrieving temperature measurement\n");
  }
  else Serial.println("error starting temperature measurement\n");

  delay(5000);  // Pause for 5 seconds.
}

View raw code

Set the altitude

Before uploading the code, you need to set up your current altitude. Go to elevationmap.net, insert your address and check your altitude’s location. Set your altitude in the code. The place where you should write your altitude is commented.

set-the-altitude

Demonstration

After uploading the code, open your serial monitor at a baud rate of 9600.

You’ll be able to see your sensor readings.

serial-monitor

Wrapping up

The BMP180 is an interesting sensor to be used in your own weather station.

Because the pressure changes with the altitude, this sensor is also able to compute the altitude.

If you would like to build a complete weather station, here’s some recommended guides:

What other sensors do you found useful in a weather station?Let me know in the comments section below.

Thanks for reading



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

23 thoughts on “Guide for BMP180 Barometric Sensor with Arduino”

  1. Hi Rui,
    One seriously irritating issue with the BMP180 is that it only has a single address. To be able to use multiple boards with the same Arduino requires a multiplexer. So not impossible but a lot more complex.

    Reply
  2. Nice project Rui–been watching the barometric pressure change during our current rain storm here in California. One important note is that the BMP180 is designed to operate off 3.3 Volts not 5 Volts.

    Reply
  3. Hi Rui,
    I have the DHT22 with Oled running on UNO. Can I connect the BMP180 to the same I2C or will it clash with the DHT22 or Oled addresses? Eventually I intend to run all on a NANO.
    Thanks for all very interesting articles and regards

    Reply
    • Hi Andre.
      Yes, you can connect on the same I2C.
      We’ve made a project with those components on the past, OLED and BMP180 on the same I2C and DHT22 and everything worked well.
      Regards,
      Sara

      Reply
  4. I couldn’t get the arduino to identify my sensor. I used the I2C scanner program to check if it is actually detecting it and it wasn’t. I ordered the BMP180 from 3 different sources and none of them seemed to work. What do I do?

    Reply
    • Hi.
      Your sensor is probably not wired correctly.
      Please double check that you are connecting SDA and SCL properly.
      Otherwise, I don’t know what could be the issue.
      Regards,
      Sara

      Reply
      • Try getting a different library from a different source. After two days struggle, a new library solved my problem. Check voltage is close to 3v3 and not 5v.

        Reply
        • I may look for another library. My sensor is recognized by the scanner code, but will not work with my Arduino Uno. Strangely it works fine when connected to an esp8266.

          Reply
  5. I do not know if it’s just me or if everybody else experiencing problems with
    your site. It looks like some of the text in your
    content are running off the screen. Can someone else please
    comment and let me know if this is happening to them as well?

    This might be a problem with my browser because I’ve had this
    happen previously. Thanks

    Reply
    • Hi.
      I’m sorry you’re experiencing that issue.
      The website works well in most common browsers like Google Chrome, Microsoft Edge, etc.
      Which web browser are you using?
      Regards,
      Sara

      Reply
  6. Hi, I don’t know if you’re aware but the diagram shows the voltage input as 5V instead of the appropriate 3.3V, just letting you know!

    Reply
    • Chad: Late reply but might help others. The BMP-180 module shown here has a 3.3 volt regulator on it.That’s the black rectangle with the 3 pins. Most of those regulators will take up to 10 volts on the input, so they will definitely work with a 5 volt supply. Per the datasheet, the maximum voltage on any pins is +4.25V, so you may need some level shifting if you’re running an MCU with a 5 volt supply. The solution would be to run your MCU at 3.3 volts but with AVR’s, you’ll likely need to run it at a lower speed, say 8MHz. Your results may vary.

      BTW: If you supply 3.3 volts to the BMP-180 module, the voltage regulator will still supply 3.3 volts to the BMP-180 device. I removed the one off my board before actually checking it.

      Peace and blessings,
      JQ

      Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.