BMP180 is a digital pressure sensor designed for low power and low voltage operation in mobile phones, navigation devices and personal digital assistants. The sensor has an I2C interface to communicate sensor data. It can operate at 2.5~3.6V and consumes only 12uA even in ultra-high resolution mode. The sensor can be used for a variety of applications, including measuring altitude from sea level, measuring altitude from the ground, measuring vertical speed, and detecting weather conditions.
In this project, we developed an altitude meter using the BMP180 sensor and our favorite microcontroller board – Arduino. This altitude meter displays real-time altitude from sea level on a small OLED display. The OLED display used for current altitude is SSD1306.
Required components
- Arduino UNO/any Arduino board x1
- Pressure sensor BMP180 x1
- SSD1306 OLEDx1
- Connecting wires/jumper wires
Circuit Connections
The altitude meter is designed by connecting SSD1306 OLED and BMP180 pressure sensor with Arduino UNO. The BMP180 sensor has four terminals – Vin, Gnd, SCL and SDA. The sensor's Vin and Gnd pins are connected to the 3.3V output and a ground pin of the Arduino UNO. The sensor's SCL and SDA pins can be connected to any of the I2C ports on the Arduino board. The I2C ports on Arduino UNO are shown in the image below.
The SSD1306 OLED is connected to the Arduino using a physical SPI port. To interface the SSD1306 OLED via physical SPI port, connect the D0/SCK and D1/MOSI pins of the SSD1306 OLED to the D13 and D11 pins of the Arduino, respectively. Connect the DC, RESET and CS pins of the SSD1306 to the D9, D10 and D8 pins of the Arduino respectively. The final circuit is as follows.
Arduino Sketch
How the circuit works
BMP180 is a piezoresistive sensor used to detect atmospheric pressure. The sensor measures temperature and pressure, as both factors affect air density. Temperature is measured to compensate pressure readings according to changes in air density. The sensor generates atmospheric pressure in Pascals through its I2C interface.
There are Arduino libraries available for BMP180 sensors from Adafruit and Sparkfun. In this project, we are using the Sparkfun library, and this library converts the sensor output in Pascal to hectoPascal.
The sensor first reads the uncompensated temperature reading and then the uncompensated pressure reading. Finally, it does some complex calculations with both readings, involving a series of coefficients stored in its EEPROM to provide accurate barometric pressure and temperature. Barometric pressure varies with altitude, and atmospheric pressure decreases with increasing altitude and vice versa. A change of 1 Hectopascal corresponds to about 8 meters in altitude. The BMP180 is a very sensitive sensor and responds to even minute changes in actual atmospheric pressure. The following equation gives the sea level altitude.
altitude = 44330 * (1 – (P current /P sea level )^(1/5,255))
The sensor itself is responsible for carrying out all these complex calculations and directly outputs the current true barometric pressure.
The Arduino listens to the barometric pressure from the BMP180 sensor through its I2C interface. The Sparkfun library provides temperature, pressure and altitude reading functions, and the Arduino reads the altitude reading and displays the reading on the SSD1306 OLED.
The OLED display is connected to the physical SPI port of the Arduino. Thus, the OLED communicates with the controller via the SPI interface while the BMP180 sensor relays pressure readings via the I2C interface. The Arduino reads the altitude from the BMP180 via I2c and displays it on the OLED display via SPI. The displayed output reading is in meters.
The code
Firstly, SPI and Wire libraries are imported for data communication via SPI and I2C interfaces. The Adafruit_GFX and Adafruit_SSD1306 libraries are imported to work with the SSD1306 OLED display. The Sparkfun BMP180 library is imported to work with the BMP180 sensor. Constants and pin assignments for the OLED display are defined. A 'display' object of class 'Adafruit_SSD1306' is instantiated to handle the OLED display, and a 'pressure' object of class 'SFE_BMP180' is instantiated to handle the BMP180 sensor. A variable 'baseline' is defined to store the reference atmospheric pressure at sea level. Next, a bitmap array is defined to store the EEWORLDONLINE logo.
In the setup function, the baud rate for data communication is set to 9600 bps. The display is initialized using the display.begin method. If the pressure detects the BMP180 sensor.begin method, the logo will flash on the OLED display. Otherwise, the message “Device does not work” will flash on the OLED.
In the loop function variables are declared to store pressure and altitude readings. The pressure is read by calling the user-defined function getPressure . The base atmospheric pressure for the current location is set. This is set to 1013 as altitude is read relative to sea level here. Altitude is measured by calling the altitude method overpressure object with the given baseline. The OLED display is cleared using the display.clearDisplay method. The cursor is configured to start the screen using display. setCursor method. The text size is set to 2 using display. setTextSize method. The text color is set to white using the setTextColor method. The reading altitude is printed on the OLED using the display.print and display.println methods. Readings flash on the OLED when the display.display(0 method is called. A 1500 ms delay is provided by calling the delay function before the next iteration of the loop function.
The getPressure function reads the barometric pressure from the BMP180 sensor. It uses the startTemperature , getTemperature , and startPressure methods from the Sparkfun library.
Result