ESP32 With BMP180 Barometric Sensor - Guide
ESP32 With BMP180 Barometric Sensor - Guide
This guide shows you how to use the BMP180 barometric sensor with the ESP32 to read pressure, temperature and
estimate altitude. We’ll show you how to wire the sensor to the ESP32, install the needed library, and how to write the
sketch in the Arduino IDE.
The BMP180 is a digital pressure sensor and it measures the absolute pressure of the air around it.
It features a measuring range from 300 to 1100hPa with an accuracy down to 0.02 hPa.
Because temperature affects the pressure, the sensor comes with a temperature sensor to give temperature
compensated pressure readings.
Additionally, because the pressure changes with altitude, you can also estimate the altitude based on the current
pressure measurement.
The BMP180 barometric sensor uses I2C communication protocol. So, you need to use the SDA and SCL pins of the
ESP32.
Parts required
ESP32 Module (ESP32 DOIT DEVKIT V1 Board) – read ESP32 development boards comparison
BMP180 barometric sensor
Jumper wires
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!
Schematic
Wire the BMP180 barometric sensor to the ESP32 as shown in the following schematic diagram.
In order to upload code to your ESP32 using Arduino IDE, you should install an add-on for the Arduino IDE that allows
you to program the ESP32 using the Arduino IDE and its programming language. Follow one of the next tutorials to
prepare your Arduino IDE:
One of the easiest ways to read pressure, temperature and altitude with the BMP180 sensor is using the BMP_085
library by Adafruit. This library is compatible with the BMP085 and the BMP180 sensors. Follow the next steps to install
the library in your Arduino IDE:
Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.
Search for “BMP085” on the Search box and install the BMP085 library from Adafruit.
After installing, restart your Arduino IDE.
Code
The library provides an example showing how to get temperature, pressure, and altitude. Go to File > Examples >
Adafruit BMP085 Library > BMP085test.
/*
* Rui Santos
*/
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
while (1) {}
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print("Altitude = ");
Serial.print(bmp.readAltitude());
Serial.println(" meters");
Serial.print(bmp.readSealevelPressure());
Serial.println(" Pa");
Serial.print(bmp.readAltitude(102000));
Serial.println(" meters");
Serial.println();
delay(500);
#include <Wire.h>
#include <Adafruit_BMP085.h>
Serial.begin(9600);
if (!bmp.begin()) {
while (1) {}
Reading Temperature
To read the temperature you just need to use the readTemperature() method on the bmp object:
bmp.readTemperature()
Reading Pressure
Reading the pressure is also straighforward. You use the readPressure() method.
bmp.readPressure()
Reading Altitude
Because the pressure changes with altitude, you can estimate your current altitude by comparing it with the pressure at
the sea level.
1. The first assumes a standard barometric pressure of 10132 Pascal at the sea level. You get the altitude as follows:
bmp.readAltitude()
2. The second method assumes the current pressure at the sea level. For example, if at the moment the pressure at the
sea level is 101500 Pa, you just need to pass 101500 as an argument to the readAltitude() method as follows:
bmp.readAltitude(101500)
Demonstration
Upload the code to your ESP32. Make sure you have the right board and COM port selected.
Then, open the Serial Monitor at a baud rate of 9600. You should get the sensor readings, as shown in the following
figure.