BMP280 Barometric Pressure and Temperature Sensor

View on Amazon
Overview
About BMP280 Barometric Pressure and Temperature Sensor
The BMP280, developed by Bosch Sensortec, is a high-performance digital barometric pressure and temperature sensor. As an improvement over the BMP180 and BMP085, it offers higher accuracy, lower power consumption, and expanded features, making it ideal for weather monitoring, altimetry, and indoor navigation.
⚡ Key Features
- Enhanced Accuracy & Efficiency – More precise than BMP180 and BMP085.
- Wide Pressure Range – Enables altitude tracking and weather forecasting.
- Integrated Temperature Sensor – Improves altitude calculations and environmental monitoring.
- I²C & SPI Communication – Provides flexible connectivity options for ESP32, Arduino, and other microcontrollers.
With its versatility and improved performance, the BMP280 is a top choice for precision altitude and weather applications. 🚀
Get Your BMP280
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
BMP280 Specifications
Complete technical specification details for BMP280 Barometric Pressure and Temperature Sensor
📊 Technical Parameters
BMP280 Pinout
The **BMP280** supports both **I²C** and **SPI** for temperature and pressure sensing:
Visual Pinout Diagram

Pin Types
Quick Tips
**Dual Protocol**: Supports both I²C and SPI,📡 **I²C Address**: 0x76 or 0x77 (SDO pin selects),🌡️ **Temperature**: -40°C to +85°C, ±1°C accuracy
**Pressure**: 300-1100 hPa, ±1 hPa accuracy,📏 **Altitude**: Calculate altitude from pressure,⚡ **Low Power**: 2.7µA in sleep mode
**Cost-Effective**: Budget-friendly option,🎯 **Applications**: Weather stations, altimeters, drones
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power input | 3.3V or 5V compatible |
2 GND | Power | Ground connection | |
3 SDA | Communication | I²C data line | Connect to ESP32 GPIO21 |
4 SCL | Communication | I²C clock line | Connect to ESP32 GPIO22 |
5 CSB | Communication | Chip select for SPI | Connect to GND for I²C mode |
6 SDO | Communication | SPI data out / I²C address select | GND=0x76, VCC=0x77 for I²C address |
Wiring BMP280 to ESP32
To interface the **BMP280** with an **ESP32** using **I²C**:
Pin Connections
| BMP280 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply | |
2 GND Required | GND | Ground | |
3 SDA Required | GPIO21 | I²C data line | |
4 SCL Required | GPIO22 | I²C clock line | |
5 CSB Required | GND | Set to GND for I²C mode | |
6 SDO Optional | GND or VCC | I²C address: GND=0x76, VCC=0x77 |
**I²C Address**: 0x76 (SDO→GND) or 0x77 (SDO→VCC)
**CSB Pin**: Must connect to GND for I²C mode
**Power**: Use 3.3V or 5V
**Simple Wiring**: 4-6 wires depending on configuration
**No Humidity**: Use BME280 if humidity needed
BMP280 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The BMP280 sensor provides pressure readings significantly lower than expected, such as 700 hPa when the actual pressure is around 960 hPa.
Possible causes include incorrect configuration of the sensor's registers, particularly writing unintended values to reserved bits.
Solution: Ensure that when configuring the sensor's registers, especially the configuration register (0xF5), reserved bits are set to '0' as specified in the datasheet. Writing '1' to these bits can lead to erroneous pressure readings. Review your initialization code to confirm compliance with the sensor's specifications. ([forum.arduino.cc](https://forum.arduino.cc/t/bmp280-sensor-pressure-problems-solved/479974))
Issue: The BMP280 sensor outputs static temperature and pressure values that do not change over time, indicating a lack of new measurements.
Possible causes include operating the sensor in forced mode without re-triggering measurements, leading to repeated readings of the same data.
Solution: In forced mode, the BMP280 performs a single measurement and then returns to sleep mode. To obtain continuous measurements, you must repeatedly set the sensor to forced mode before each read operation. Alternatively, configure the sensor to normal mode for continuous measurements. Ensure your code properly handles the sensor's operating modes to acquire updated data. ([esp32.com](https://esp32.com/viewtopic.php?t=10344))
Issue: The BMP280 sensor fails to initialize, resulting in error messages such as: Could not find a valid BMP280 sensor, check wiring!.
Possible causes include incorrect wiring, improper power supply, or issues with I2C communication.
Solution: Verify that the sensor's SDA and SCL lines are correctly connected to the corresponding pins on the microcontroller. Ensure that the sensor is powered with the appropriate voltage (3.3V or 5V, depending on the sensor's specifications). Use an I2C scanner to detect the sensor's address; if the sensor is not found, check for loose connections or potential damage to the sensor. Additionally, confirm that the correct I2C address is specified in your code, as some BMP280 modules may use different default addresses. ([forum.arduino.cc](https://forum.arduino.cc/t/bmp280-init-failed/1203471))
Issue: The BMP280 sensor reports temperature readings that are significantly off, such as -142.6°C, indicating potential communication or configuration issues.
Possible causes include incorrect I2C address configuration, lack of pull-up resistors on the I2C lines, or faulty sensor modules.
Solution: Ensure that the correct I2C address is used in your code, typically 0x76 or 0x77 for BMP280 sensors. Verify the presence of appropriate pull-up resistors (e.g., 4.7kΩ) on the SDA and SCL lines to facilitate proper I2C communication. Additionally, consider testing the sensor with known working code and hardware to rule out defective modules. ([forum.arduino.cc](https://forum.arduino.cc/t/bmp280-sensor-wrong-data-readings/513455))
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
BMP280 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(115200);
if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 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.0F);
Serial.println(" hPa");
delay(2000);
}This Arduino code initializes the BMP280 sensor using the Adafruit BMP280 library. It reads temperature and pressure values and prints them to the Serial Monitor every two seconds. Ensure the I²C address (0x76 or 0x77) matches your sensor's configuration.
#include <stdio.h>
#include "driver/i2c.h"
#include "esp_log.h"
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_FREQ_HZ 100000
#define BMP280_ADDR 0x76
static const char *TAG = "BMP280";
void i2c_master_init() {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_MASTER_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_param_config(I2C_MASTER_NUM, &conf);
i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0);
}
void bmp280_read_data() {
uint8_t reg = 0xF7; // BMP280 data register
uint8_t data[6];
i2c_master_write_read_device(I2C_MASTER_NUM, BMP280_ADDR, ®, 1, data, 6, 1000 / portTICK_RATE_MS);
// Process raw data
int32_t adc_pressure = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
int32_t adc_temperature = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
// Use calibration data and formulas from BMP280 datasheet to calculate actual values
// (calibration data reading not included in this snippet)
float temperature = ...; // Calculated temperature
float pressure = ...; // Calculated pressure
ESP_LOGI(TAG, "Temperature: %.2f °C", temperature);
ESP_LOGI(TAG, "Pressure: %.2f hPa", pressure);
}
void app_main() {
ESP_LOGI(TAG, "Initializing I2C...");
i2c_master_init();
ESP_LOGI(TAG, "Reading BMP280 data...");
while (1) {
bmp280_read_data();
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}This ESP-IDF code initializes the BMP280 sensor on an ESP32 via I2C. The i2c_master_init() function configures the I2C interface. The bmp280_read_data() function reads raw data from the BMP280 registers and processes it into temperature and pressure values using calibration data and formulas. The main application loop continuously reads and logs the sensor data to the console every two seconds.
sensor:
- platform: bmp280
temperature:
name: "BMP280 Temperature"
pressure:
name: "BMP280 Pressure"
address: 0x76This ESPHome configuration integrates the BMP280 sensor. It creates sensor entities for temperature and pressure, which are monitored via the I2C address 0x76. The configuration is ideal for home automation and IoT systems, enabling real-time environmental monitoring.
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit BMP280 Library
wire
monitor_speed = 115200main.cpp
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(115200);
if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 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.0F);
Serial.println(" hPa");
delay(2000);
}This PlatformIO code uses the Adafruit BMP280 library to interface with the BMP280 sensor. It reads and prints temperature and pressure values to the Serial Monitor every two seconds. Ensure the I²C address (0x76 or 0x77) is correctly set for your module.
from machine import I2C, Pin
from bmp280 import BMP280
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Initialize BMP280
bmp = BMP280(i2c)
while True:
print(f"Temperature: {bmp.temperature:.2f} °C")
print(f"Pressure: {bmp.pressure:.2f} hPa")
sleep(2)This MicroPython code interfaces with the BMP280 sensor via I2C. It reads and prints temperature and pressure data every two seconds. The BMP280 MicroPython library simplifies the integration, allowing straightforward access to sensor readings.
Wrapping Up BMP280
The ESP32 BMP280 Barometric Pressure and Temperature Sensor is a powerful environment sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the BMP280 into your ESP32 project and bring your ideas to life!








