ESP32 BMP085 Barometric Pressure Sensor
The BMP085 is a high-precision digital barometric pressure and temperature sensor, ideal for weather monitoring, altimetry, and navigation. It uses an I²C interface for communication and offers low power consumption, making it suitable for battery-powered devices.
Jump to Code Examples
Quick Links
About BMP085 Barometric Pressure Sensor
The BMP085 is a high-precision barometric pressure sensor from Bosch Sensortec. It provides atmospheric pressure and temperature measurements, making it ideal for weather monitoring, altimetry, and GPS enhancement. With a pressure range of 300 hPa to 1100 hPa, it covers altitudes from -500 to 9000 meters above sea level. The BMP085 operates via an I²C interface, ensuring easy integration with microcontrollers and embedded systems.
BMP085 Sensor Technical Specifications
Below you can see the BMP085 Barometric Pressure Sensor Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.
- Protocol: I2C
- Interface: I2C
- Pressure Range: 300 hPa to 1100 hPa
- Temperature Range: 0°C to +65°C
- Operating Voltage: 1.8V to 3.6V
- Resolution: Up to 0.01 hPa
- Accuracy: ±0.1 hPa
- Power Consumption: 3 µA in sleep mode
- Output: Temperature and Pressure (Digital)
- Package Dimensions: 3.6 mm × 3.8 mm × 0.93 mm
- Weight: 1.0 g
BMP085 Sensor Pinout
Below you can see the pinout for the BMP085 Barometric Pressure Sensor. The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32!
The BMP085 module has the following pins: VIN
: Supplies power to the module, typically 3.3V or 5V. GND
: Ground pin for the module. SDA
: Serial Data pin for I2C communication. Connect to the microcontroller's SDA pin. SCL
: Serial Clock pin for I2C communication. Connect to the microcontroller's SCL pin.
BMP085 Wiring with ESP32
Below you can see the wiring for the BMP085 Barometric Pressure Sensor with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.
To wire the BMP085 module with an ESP32 (I2C mode): VIN
: Connect to 3.3V pin on ESP32. GND
: Connect to GND pin on ESP32. SDA
: Connect to GPIO21 (default SDA). SCL
: Connect to GPIO22 (default SCL).
Code Examples
Below you can find code examples of BMP085 Barometric Pressure Sensor with ESP32 in several frameworks:
ESP32 BMP085 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the BMP085 Barometric Pressure Sensor:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
void setup() {
Serial.begin(115200);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1);
}
}
void loop() {
sensors_event_t event;
bmp.getEvent(&event);
if (event.pressure) {
Serial.print("Pressure: ");
Serial.print(event.pressure);
Serial.println(" hPa");
}
float temperature;
bmp.getTemperature(&temperature);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
delay(2000);
}
This Arduino code initializes the BMP085 sensor using the Adafruit_BMP085_Unified
library. In the loop()
function, the code reads and prints atmospheric pressure and temperature values every two seconds. The sensor's event-based API ensures efficient data handling.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.
ESP32 BMP085 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
If you're using ESP-IDF to work with the BMP085 Barometric Pressure Sensor, here's how you can set it up and read data from the sensor. Fill in this code in the main
ESP-IDF file:
#include "bmp085.h"
#include "esp_log.h"
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_FREQ_HZ 100000
#define BMP085_ADDR 0x77
static const char *TAG = "BMP085";
void app_main() {
ESP_LOGI(TAG, "Initializing BMP085...");
bmp085_dev dev;
bmp085_init(&dev, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO, I2C_MASTER_FREQ_HZ, BMP085_ADDR);
while (1) {
bmp085_data data;
bmp085_read(&dev, &data);
ESP_LOGI(TAG, "Temperature: %.2f°C", data.temperature);
ESP_LOGI(TAG, "Pressure: %.2f hPa", data.pressure);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
This ESP-IDF code configures the ESP32 to interface with the BMP085 sensor over I2C. The bmp085_init
function initializes the sensor, while the bmp085_read
function fetches pressure and temperature readings, which are logged to the console every two seconds.
Update the I2C pins (I2C_MASTER_SDA_IO
and I2C_MASTER_SCL_IO
) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.
ESP32 BMP085 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the BMP085 Barometric Pressure Sensor
sensor:
- platform: bmp085
temperature:
name: "BMP085 Temperature"
pressure:
name: "BMP085 Pressure"
address: 0x77
This ESPHome configuration integrates the BMP085 sensor. It creates sensor entities for temperature and pressure, which are monitored via the I2C address 0x77
. The setup is ideal for weather monitoring and IoT systems.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.
ESP32 BMP085 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit BMP085 Unified Library
wire
monitor_speed = 115200
ESP32 BMP085 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the BMP085 Barometric Pressure Sensor:
#include <Wire.h>
#include "Adafruit_BMP085.h"
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(115200);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature: ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print("Pressure: ");
Serial.print(bmp.readPressure() / 100.0);
Serial.println(" hPa");
delay(2000);
}
This PlatformIO code integrates the Adafruit BMP085 library to read temperature and pressure values. The data is fetched and printed to the Serial Monitor every two seconds using simple function calls.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.
ESP32 BMP085 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the BMP085 Barometric Pressure Sensor with your ESP32.
from machine import I2C, Pin
from bmp085 import BMP085
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Initialize BMP085
bmp = BMP085(i2c)
while True:
print(f"Temperature: {bmp.temperature:.2f} °C")
print(f"Pressure: {bmp.pressure / 100:.2f} hPa")
sleep(2)
This MicroPython code initializes the BMP085 sensor using I2C. The sensor reads and prints temperature and pressure values to the console every two seconds. It uses the BMP085 MicroPython library for easy integration.
Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy
.
Conclusion
We went through technical specifications of BMP085 Barometric Pressure Sensor, its pinout, connection with ESP32 and BMP085 Barometric Pressure Sensor code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.