Determining the Pressure and Altitude Using GY-68 BMP180 and © GPL3+

In this tutorial, you’ll learn how to use the BMP180 sensor, which is one of the most commonly used sensors for measuring the pressure.

  • 997 views
  • 0 comments
  • 4 respects

Components and supplies

Apps and online services

About this project

Overview

In many projects such as flying robots, weather stations, improving routing performance, sports and etc. measuring pressure and altitude is very important. In this tutorial, you’ll learn how to use the BMP180 sensor, which is one of the most commonly used sensors for measuring the pressure.

What You Will Learn

  • What the barometric pressure is.
  • What the BOSCH BMP180 pressure sensor is.
  • How to use the BOSCH BMP180 pressure sensor with Arduino.

What Is the Barometric Pressure?

Barometric pressure or atmospheric pressure results from the weight of the air on the earth. This pressure is about 1 kg per square centimeter at the sea level.

There are several units to express the atmospheric pressure, that can easily be converted to each other. The SI unit for measuring the pressure is Pascal (Pa).

The barometric pressure has an approximately linear inverse ratio with the altitude from the sea level so if we measure the barometric pressure of a place, we can calculate the altitude from the sea level using a simple mathematical operation.

GY-68 BOSCH BMP180 Pressure Sensor Features

One of the most common sensors for measuring the pressure and altitude is BOSCH BMP180. The most important features of this module are as follow:

  • Pressure measurement range of 300 to 1100hPa
  • -0.1hPa measuring accuracy for absolute pressure
  • 12hPa measuring accuracy for relative pressure
  • Low power consumption (5μA in standard mode and one sample per second)
  • Internal temperature sensor with a precision of 0.5 °C
  • Supporting I2C protocol for communication
  • Fully calibrated

Required Materials

How to Use GY-68 BMP180 Pressure Sensor with Arduino?

This sensor is available as a module for easy use. The main parts of the BMP180 sensor module are:

  • BMP180 sensor
  • A 3.3-volt regulator. This regulator lets you connect the module to 5V.
  • Required pull up resistors to communicate I2C properly

Circuit

Download the BMP180_Breakout_Arduino_Library to use the BMP180 sensor module.

BMP180_Breakout_Arduino_Library

Calculation of Absolute Pressure with Different Units and Altitude from the Sea Level

*/
BMP180
modified on 23 Apr 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn
*/
#include <SFE_BMP180.h>
#include <Wire.h?
SFE_BMP180 pressure;
#define ALTITUDE 943.7 // Altitude of Electropeak Co. in meters
void setup() {
Serial.begin(9600);
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
Serial.println("BMP180 init fail\n\n");
Serial.println("Check connection");
while (1);
}
}
void loop() {
char status;
double T, P, p0, a;
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
Serial.print("temperature: ");
Serial.print(T, 2);
Serial.println(" deg C ");
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(" hpa = ");
Serial.print(P * 100, 2);
Serial.print(" pa = ");
Serial.print(P * 0.000986923, 2);
Serial.print(" atm = ");
Serial.print(P * 0.750063755, 2);
Serial.print(" mmHg = ");
Serial.print(P * 0.750061683, 2);
Serial.print(" torr = ");
Serial.print(P * 0.014503774, 2);
Serial.println(" psi");
p0 = pressure.sealevel(P, ALTITUDE); // we're at 943.7 meters
Serial.print("relative (sea-level) pressure: ");
Serial.print(p0, 2);
Serial.println(" hpa ");;
a = pressure.altitude(P, p0);
Serial.print("your altitude: ");
Serial.print(a, 0);
Serial.println(" meters ");
}
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");
Serial.println("==========================================================================");
delay(5000);
}

Let’s check the process of pressure and altitude calculation more accurately:

According to the above algorithm, first we start to calculate the temperature using startTemperature(), then we store the temperature in variable T using getTemperature(T). After that, we calculate the pressure with startPressure(3). The number 3 is the maximum resolution that can be changed between 0 and 3. using getPressure(P) we store the absolute pressure in variable P. The amount of this pressure is in hPa, which can be converted to different units according to the previous table. The absolute pressure changes with altitude. To remove the effect of the altitude on the calculated pressure, we should use the sealevel(P, ALTITUDE) function according to the altitude stored in the ALTITUDE variable, and store the measured value in an arbitrary variable, such as p0.Use altitude(P, p0) to calculate your altitude. This function calculates the altitude in the meter.

Notethat you can insert your altitude from the sea level for the ALTITUDE variable defined at the beginning of the code

Make an Altimeter!

The BMP180 pressure sensor, like many other pressure sensors, measures the absolute pressure, and the absolute pressure changes with the change of the altitude. So you can calculate the relative altitude by measuring the pressure.

/*
BMP180 - altimeter
modified on 23 Apr 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn
*/
#include <SFE_BMP180.h>
#include <Wire.h>
SFE_BMP180 pressure;
double baseline;
void setup()
{
Serial.begin(9600);
Serial.println("REBOOT");
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
Serial.println("BMP180 init fail (disconnected?)\n\n");
while (1);
}
baseline = readPressure();
Serial.print("baseline pressure: ");
Serial.print(baseline);
Serial.println(" hpa");
}
void loop()
{
double a, P;
P = readPressure();
a = pressure.altitude(P, baseline);
Serial.print("relative altitude: ");
if (a >= 0.0) Serial.print(" ");
Serial.print(a, 1);
Serial.println(" meters, ");
delay(500);
}
double readPressure()
{
char status;
double T, P, p0, a;
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
status = pressure.startPressure(3);
if (status != 0)
{
delay(status);
status = pressure.getPressure(P, T);
if (status != 0)
{
return (P);
}
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");
}

The startPressure(3) function calculates the absolute pressure value. Since the pressure changes with the change of the temperature and humidity, we store the initial pressure in baseline variable. According to this value and instantaneous pressure, the altitude(P, baseline) function calculates the relative altitude in meter.

What's Next?

  • Try to calculate the pressure in case of unstable temperatures.

Code

Code 1Arduino
*/

  BMP180 

  modified on 23 Apr 2019
  by Saeed Hosseini @ Electropeak
  https://electropeak.com/learn

*/

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

SFE_BMP180 pressure;

#define ALTITUDE 943.7 // Altitude of Electropeak Co. in meters

void setup() {
  Serial.begin(9600);
  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {

    Serial.println("BMP180 init fail\n\n");
    Serial.println("Check connection");
    while (1);
  }

}

void loop() {

  char status;
  double T, P, p0, a;

  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0)
    {

      Serial.print("temperature: ");
      Serial.print(T, 2);
      Serial.println(" deg C ");

      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(" hpa = ");
          Serial.print(P * 100, 2);
          Serial.print(" pa = ");
          Serial.print(P * 0.000986923, 2);
          Serial.print(" atm = ");
          Serial.print(P * 0.750063755, 2);
          Serial.print(" mmHg = ");
          Serial.print(P * 0.750061683, 2);
          Serial.print(" torr = ");
          Serial.print(P * 0.014503774, 2);
          Serial.println(" psi");


          p0 = pressure.sealevel(P, ALTITUDE); // we're at 943.7 meters 
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0, 2);
          Serial.println(" hpa ");;


          a = pressure.altitude(P, p0);
          Serial.print("your altitude: ");
          Serial.print(a, 0);
          Serial.println(" meters ");
        }
        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");
Serial.println("==========================================================================");
  delay(5000);
}
Code2Arduino
/*

  BMP180 - altimeter

  modified on 23 Apr 2019
  by Saeed Hosseini @ Electropeak
  https://electropeak.com/learn

*/

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


SFE_BMP180 pressure;

double baseline;

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

  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {

    Serial.println("BMP180 init fail (disconnected?)\n\n");
    while (1);
  }

  baseline = readPressure();

  Serial.print("baseline pressure: ");
  Serial.print(baseline);
  Serial.println(" hpa");
}

void loop()
{
  double a, P;


  P = readPressure();

  a = pressure.altitude(P, baseline);

  Serial.print("relative altitude: ");
  if (a >= 0.0) Serial.print(" ");
  Serial.print(a, 1);
  Serial.println(" meters, ");
  delay(500);
}


double readPressure()
{
  char status;
  double T, P, p0, a;
  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0)
    {
      status = pressure.startPressure(3);
      if (status != 0)
      {
        delay(status);
        status = pressure.getPressure(P, T);
        if (status != 0)
        {
          return (P);
        }
        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");
}

Comments

Similar projects you might like

Pressure Pad Interfacing with Arduino

Project tutorial by Ashish Kumar Senapati

  • 17,419 views
  • 2 comments
  • 17 respects

Autonomous High Altitude Glider

Project in progress by Abdullah Tarik Agcayazi and kemfic

  • 21,913 views
  • 10 comments
  • 73 respects

Automated Simple Pendulum

Project tutorial by Team CodersCafe

  • 3,358 views
  • 0 comments
  • 13 respects

Autonomous Arduino Mega Track Robot

Project in progress by mikesoniat

  • 5,136 views
  • 1 comment
  • 22 respects

The Vibrating Pressure Temperature Altitude Tilt Detector

Project tutorial by Kutluhan Aktar

  • 2,426 views
  • 0 comments
  • 6 respects

Line Follower Robot

Project tutorial by Shubham Shinganapure

  • 9,175 views
  • 3 comments
  • 21 respects
Add projectSign up / Login