What is a BMP180 temperature sensor?

The BMP180 sensor is a high precision digital pressure sensor of the BMPXXX series that is used for both educational and commercial purposes. It is based on piezo-resistive technology in order to achieve EMC robustness, high accuracy and linearity, and long term stability. It is used to measure Atmospheric pressure or barometric pressure. The barometric pressure or atmospheric pressure is a pressure applied by the weight of the air above us. The BMP180 sensor measures that pressure and output it as a digital signal that can be further read by any microcontroller like Arduino UNO by interfacing the sensor using the I2C bus. In order to get a highly precise pressure reading, it uses an inbuilt temperature measuring sensor. So, the BMP180 can also be used as a very good temperature measuring sensor. Here, we will be interfacing this sensor with the Arduino UNO using a library. Further, we will be writing a code to make an altitude meter.

Features of the BMP180 sensor

·       Pressure range: 300-1000hPa(-500m to +9000m releating to sea level)

·       Supply voltage(standlone sensor): 1.8-3.6V DC

·       Current consumption: 1000µA(Peak).

·       Uses I2C interface

·       Fully calibrated

·       Inbuilt temperature measuring sensor

Applications of BMP180 sensor

·       Weather forecast

·       Smartwatches

·       Mobile phones

·       GPS navigation

·       Vertical velocity indication

Modes of using BPM180 sensor

There are a total of four modes using a BMP180 that can be selected by the variable oversampling_setting (0, 1, 2, 3) in the C code. These modes are;

·       Ultra-low-power mode

·       Standard mode

·       High mode

·       Ultra-high-resolution mode

Each mode has different values for sampling, conversion time, and current consumption. Like, the first mode is the ultra lower power mode. In this mode, the current consumption is very low but conversion time is more. Here are the values for all other modes.

ModeCodeInternal no. of samplesConversion time(ms)Current consumption(max)
Ultra-low power014.53
Standard127.55
High2413.57
Ultra-high resolution3825.512

How to interface the BMP180 sensor with the Arduino UNO board?

In order to interface the BMP180 sensor, we will be using a BMP180 sensor module that consists of a BMP180 sensor and some necessary electronics components. Further, we will be using an Arduino library for reading the data from the sensor using the I2C interface.

Pin diagram of the BMP180 sensor module

The VCC pin is used for connecting 3.3-5V to the module.
The GND pin is used for connecting GND to the module.
The SCL and SDA pins are used for I2C interfacing.

Interfacing BMP180 sensor module with Arduino UNO board

We need an Arduino library for this. Download the library from this link https://github.com/sparkfun/BMP180_Breakout_Arduino_Library and install it in the Arduino IDE. If you do not know how to install the library in Arduino IDE then visits this link(Give the link of another article based on how to install libraries in Arduino IDE). After you have finished installing the library, you can proceed further. Follow this circuit.

Flow diagram of measuring air pressure, temperature, and altitude

#include <SFE_BMP180.h>
#include <Wire.h>
 
SFE_BMP180 pressure;
 
#define ALTITUDE 1655.0 //replace 1655.0 with your current city altitude
 
void setup()
{
  Serial.begin(9600);
  Serial.println("REBOOT");
 
  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    Serial.println("BMP180 init fail\n\n");
    while(1); 
  }
}
 
void loop()
{
  char status;
  double T,P,p0,a;  
  Serial.println();
  Serial.print("Provided Altitude: ");
  Serial.print(ALTITUDE,0);
  Serial.print(" meters, ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(" feet");
 
  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
 
    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print("Temperature: ");
      Serial.print(T,2);
      Serial.print(" °C, ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.println(" °F");
      
      status = pressure.startPressure(3);
      if (status != 0)
      {
        delay(status);
        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          Serial.print("Absolute Pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(" inHg");
 
          p0 = pressure.sealevel(P,ALTITUDE); 
          Serial.print("Relative Pressure(Sea Level): ");
          Serial.print(p0,2);
          Serial.print(" mb, ");
          Serial.print(p0*0.0295333727,2);
          Serial.println(" inHg");
          
          a = pressure.altitude(P,p0);
          Serial.print("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);  
}

Working of code

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

First, include the library for the BMP180 sensor and the library for the I2C interface. These two libraries will include all the necessary functions in order to interface the sensor with Arduino UNO.

SFE_BMP180 pressure;

create an object of class SFE_BMP180. We will be using this object to access all the functions of the library.

#define ALTITUDE 1655.0

Define a constant of name ALTITUDE to store the current altitude of your city. Replace 16655.0 with your city altitude. You can find your city altitude on google.

void setup()
{
  Serial.begin(9600);

Start the setup() function and first define the baud rate for serial communication. We will be using this serial communication in order to receive sensor data from the Arduino UNO and display it on the Serial monitor.

if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
  }
}

Using the if statement we will initiate the BMP180 sensor. If it is successfully initiated then you will see a message “BMP180 init success”. Otherwise, you will see the message “BMP180 init fail”. The setup() function is finished here.

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

Start loop() function. First, define all the variables needed for calculation. ‘status’ for storing the status of the sensor, ‘T’ for temperature, ‘P’ for pressure, ‘p0’ for relative pressure, and ‘a’ for altitude.

 

  Serial.println();
  Serial.print("provided altitude: ");
  Serial.print(ALTITUDE,0);
  Serial.print(" meters, ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(" feet");

First, we will print Altitude provide by you in meters and then in inches.

status = pressure.startTemperature();

Start measuring the temperature using the startTemperature() function and store the status in ‘status’ variable. If the measurement is started then ‘5’ will be stored in the ‘status’ variable and if the measurement is not started ‘0’ will be stored in the ‘status’ variable.

status = pressure.startTemperature();

  Check whether the status is equal to 0 or not. If the status is not equal to 0 then the code inside the if statement will be executed. Otherwise, “error starting temperature measurement” will be printed on the serial monitor.

delay(status);

If the status is not 0 then will give a delay equal to the status that is 5 ms because the value of status is 5. This is the time taken by the sensor to calculate the temperature.

status = pressure.getTemperature(T);

Get temperature value from the sensor using the getTemperature() function and store it in the variable ‘T’. And store the status in the ‘status’ variable. I have already mentioned above what will be the value of status.

if (status != 0)
    {
      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");

If the status is not equal to 0 then first print the temperature in °Celsius and then print the temperature in °Fahrenheit.

status = pressure.startPressure(3);

Start measuring pressure using the startPressure() function, where 3 is the mode in which you are using the sensor. 3 means you are using the sensor in ultra-high-resolution mode. The status is also stored in the ‘status variable’. If measuring is not started then the value stored in ‘status’ is 0. Otherwise, it will be 5 for mode 0, 8 for mode 1, 14 for mode 2 and 26 for mode 3.

if (status != 0)
{
delay(status);

If the status is not equal to 0 execute all the statements inside the if. First, give a delay equal to the status value. We are using mode 3 so, the value of delay will be 24. This is the time taken by the sensor to calculate the pressure.

status = pressure.getPressure(P,T);

Get the pressure data from the sensor using the getPressure() function and store the pressure data in the variable ‘P’. In order to get the accurate value of pressure, we have also passed the value of temperature inside the function by using the ‘T’ variable.

if (status != 0)
        {
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(" inHg");

If the status is not equal to 0 then first print the pressure value in ‘mb’ millibar and then print the pressure value in ‘inHg’ inch of mercury.

          p0 = pressure.sealevel(P,ALTITUDE); 

Calculate the pressure with respect to sea level by using the selevel() function and store the value in the ‘p0’ variable. In order to do so, you have to pass the value of pressure and altitude given by you in the function. For passing the value we are using the variable ‘P’ and ‘ALTITUDE’.

Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0,2);
          Serial.print(" mb, ");
          Serial.print(p0*0.0295333727,2);
          Serial.println(" inHg");

          Print the relative pressure readings on the serial monitor in ‘mb’ then prin the values in inHG.

a = pressure.altitude(P,p0);

Get the altitude reading by using the altitude() function. In order to get the altitude reading, you have to both pressure(P) and absolute pressure(p0) values in the function.

Serial.print("computed altitude: ");
          Serial.print(a,0);
          Serial.print(" meters, ");
          Serial.print(a*3.28084,0);
          Serial.println(" feet");

         
First, print the altitude in meters and then print the altitude in inch by multiplying meters with 3.28084.

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");

You the sensor get stuck at any of the stage, you will get the error depending on the stage.

delay(5000);

In last give a delay of 5000ms.

Output Screen

So we have finished interfacing BMP180 pressure sensor to Arduino. If you have any doubts regarding the project, please feel free to send us an email.


Author

Comments are closed.