BME280 Temperature and Humidity Sensor

View on Amazon
Overview
About BME280 Temperature and Humidity Sensor
The BME280, developed by Bosch Sensortec, is a highly integrated environmental sensor that provides accurate temperature, humidity, and pressure measurements. Its low power consumption and compact size make it perfect for IoT, wearables, and weather monitoring applications.
⚡ Key Features
- 3-in-1 Sensing – Measures temperature (-40°C to 85°C), humidity (0–100% RH), and pressure (300–1100 hPa).
- Multiple Communication Interfaces – Supports I²C and SPI for flexible integration.
- Ultra-Low Power – Consumes as little as 1.8 µA, ideal for battery-powered devices.
- Compact Design – Small 2.5 × 2.5 × 0.93 mm form factor for space-constrained applications.
🔗 Learn more about the BME280 sensor.
Get Your BME280
💡 Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
BME280 Specifications
Complete technical specification details for BME280 Temperature and Humidity Sensor
📊 Technical Parameters
BME280 Pinout
The **BME280** supports both **I²C** and **SPI** communication protocols:
Visual Pinout Diagram

Pin Types
Quick Tips
**Dual Protocol**: Supports both I²C and SPI,📡 **I²C Address**: 0x76 or 0x77 (depends on SDO pin),⚡ **Power**: 3.3V or 5V compatible (check module specs)
**Measurements**: Temperature, humidity, and pressure,🌡️ **Temperature**: -40°C to +85°C, ±1°C accuracy,💧 **Humidity**: 0-100% RH, ±3% accuracy
**Pressure**: 300-1100 hPa, ±1 hPa accuracy,💤 **Low Power**: 1.8 µA sleep current,🎯 **Applications**: Weather stations, IoT, altitude tracking
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VIN/VCC | Power | Power input | 3.3V or 5V (depending on module) |
2 GND | Power | Ground connection | |
3 SCL/SCK | Communication | I²C clock / SPI clock | Connect to ESP32 SCL (I²C) or GPIO18 (SPI) |
4 SDA/SDI | Communication | I²C data / SPI MOSI | Connect to ESP32 SDA (I²C) or GPIO23 (SPI) |
5 SDO | Communication | SPI MISO (optional for I²C address) | GPIO19 for SPI, or use for I²C address selection |
6 CS | Communication | SPI chip select | GPIO5 for SPI (not used in I²C mode) |
Wiring BME280 to ESP32
To interface the **BME280** with an **ESP32** using **I²C**:
Visual Wiring Diagram

Connection Status
Protocol

Pin Connections
| BME280 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply | |
2 GND Required | GND | Ground | |
3 SCL Required | GPIO22 | I²C clock line | |
4 SDA Required | GPIO21 | I²C data line |
**I²C Address**: Default 0x76 or 0x77 (check with I²C scanner)
**Pull-up Resistors**: Usually included on breakout boards
**Power**: Use 3.3V for most modules
**Speed**: I²C supports up to 3.4 MHz
**Simple Wiring**: Only 4 wires needed
BME280 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The I2C scanner detects the BME280 sensor, but example sketches fail to initialize it.
`I2C device found at addres 0x76`
`Could not find a valid BME280 sensor, check wiring, address, sensor ID!`
Some cheeap BME280 named sensors does not actually work with the Adafruit library, due to the I2C Bus Timing - different libraries configure I2C clock speeds differently, which might cause issues with sensors that cannot keep up with faster communication.
Solution: Try using different library instead of Adafruit_BME280.h, such as the BME280.h
Issue: The sensor is identified incorrectly, leading to initialization failures..
`SensorID was: 0x0`
`ID of 0xFF probably means a bad address, a BMP 180 or BMP 085`
`ID of 0x56-0x58 represents a BMP 280,`
`ID of 0x60 represents a BME 280.`
`ID of 0x61 represents a BME 680.`
Some modules labeled as BME280 are actually `BMP280`, which lacks the humidity sensor.
Solution: If the sensor is a BMP280, use the BMP280 library (`Adafruit_BMP280.h`) instead of the BME280 library.
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
BME280 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
/* Uncomment these lines if using SPI interface
#include <SPI.h>
#define SPI_CLK 18
#define SPI_MISO 19
#define SPI_MOSI 23
#define SPI_CS 5
*/
#define SEA_LEVEL_PRESSURE (1013.25) // Standard sea level pressure
Adafruit_BME280 environmentSensor; // Using I2C for communication
//Adafruit_BME280 environmentSensor(SPI_CS); // Use for hardware SPI
//Adafruit_BME280 environmentSensor(SPI_CS, SPI_MOSI, SPI_MISO, SPI_CLK); // Use for software SPI
unsigned long refreshInterval;
void setup() {
Serial.begin(9600);
Serial.println(F("Initializing BME280 Sensor"));
bool initSuccess;
// Initialize sensor with default settings (I2C address 0x76)
initSuccess = environmentSensor.begin(0x76);
if (!initSuccess) {
Serial.println("Sensor initialization failed. Verify wiring and connections.");
while (1); // Halt execution if sensor is not found
}
Serial.println("-- Running Default Configuration --");
refreshInterval = 1000; // Data refresh every 1000 ms
Serial.println();
}
void loop() {
displaySensorData();
delay(refreshInterval);
}
void displaySensorData() {
Serial.print("Temperature: ");
Serial.print(environmentSensor.readTemperature());
Serial.println(" °C");
// Optional: Uncomment for Fahrenheit conversion
/*Serial.print("Temperature: ");
Serial.print(1.8 * environmentSensor.readTemperature() + 32);
Serial.println(" °F");*/
Serial.print("Pressure: ");
Serial.print(environmentSensor.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Estimated Altitude: ");
Serial.print(environmentSensor.readAltitude(SEA_LEVEL_PRESSURE));
Serial.println(" meters");
Serial.print("Humidity: ");
Serial.print(environmentSensor.readHumidity());
Serial.println(" %");
Serial.println();
}#include <stdio.h>
#include "esp_log.h"
#include "bme280.h" // BME280 driver for ESP-IDF (you need to include this library)
#define I2C_MASTER_SCL_IO 22 // GPIO number for I2C SCL
#define I2C_MASTER_SDA_IO 21 // GPIO number for I2C SDA
#define I2C_MASTER_NUM I2C_NUM_0 // I2C port number
#define I2C_MASTER_FREQ_HZ 100000 // I2C frequency
#define BME280_I2C_ADDR 0x76 // BME280 I2C address
void app_main(void)
{
static i2c_bus_handle_t i2c_bus = NULL;
static bme280_handle_t bme280 = NULL;
//Step1: Init I2C bus
i2c_config_t conf1 = {
.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_bus = i2c_bus_create(I2C_MASTER_NUM, &conf1);
//Step2: Init bme280
bme280 = bme280_create(i2c_bus, BME280_I2C_ADDRESS_DEFAULT);
bme280_default_init(bme280);
//Step3: Read temperature, humidity and pressure
float temperature = 0.0, humidity = 0.0, pressure = 0.0;
bme280_read_temperature(bme280, &temperature);
bme280_read_humidity(bme280, &humidity);
bme280_read_pressure(bme280, &pressure);
}sensor:
- platform: bme280_i2c
temperature:
name: "BME280 Temperature"
pressure:
name: "BME280 Pressure"
humidity:
name: "BME280 Humidity"
# Example configuration entry SPI
sensor:
- platform: bme280_spi
temperature:
name: "BME280 Temperature"
pressure:
name: "BME280 Pressure"
humidity:
name: "BME280 Humidity"
cs_pin: GPIOXXThe following YAML configuration sets up two sensor platforms for a BME280 sensor:
bme280_i2c:Configures the BME280 sensor using the I2C interface.The temperature, pressure, and humidity readings are named accordingly.bme280_spi:Configures the BME280 sensor using the SPI interface.It includes an additional parametercs_pinto specify the chip select pin.
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
adafruit/Adafruit BME280 Library @ ^2.2.2
adafruit/Adafruit Unified Sensor @ ^1.1.7
build_flags =
-DBME280_I2C ; Define if using I2C
; -DBME280_SPI ; Uncomment if using SPImain.cpp
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
// Define I2C address or SPI pins
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
void setup() {
Serial.begin(115200);
if (!bme.begin(0x76)) { // Replace 0x76 with your I2C address
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
delay(2000);
}This program configures a BME280 sensor using PlatformIO. Key steps include:
- Library Inclusions: Include
Wire.h,Adafruit_Sensor.h, andAdafruit_BME280.hfor I2C communication and sensor interfacing. - PlatformIO Setup: Add required libraries in
platformio.iniunderlib_deps:lib_deps = adafruit/Adafruit BME280 Library @ ^2.2.2 adafruit/Adafruit Unified Sensor @ ^1.1.7 - Sensor Initialization: Use
bme.begin(0x76)for I2C (replace with0x77if needed). - Data Reading: Read temperature, pressure, and humidity with
bme.readTemperature(),bme.readPressure(), andbme.readHumidity().
import time
from machine import I2C, Pin
from bme280 import BME280
# Initialize I2C
i2c = I2C(1, scl=Pin(22), sda=Pin(21)) # Adjust pins as needed (e.g., SCL=22, SDA=21)
# Initialize BME280
bme = BME280(i2c=i2c)
while True:
# Read data from the BME280
temperature = bme.temperature
pressure = bme.pressure
humidity = bme.humidity
# Print data to the console
print("Temperature:", temperature)
print("Pressure:", pressure)
print("Humidity:", humidity)
print("-" * 30)
time.sleep(2) # Wait 2 seconds before the next readingThis MicroPython code reads data from a BME280 sensor using I2C. Key steps:
from machine import I2C, Pin: Initializes I2C communication with the specified pins (e.g., SCL=22, SDA=21).
from bme280 import BME280: Imports the BME280 library, which must be in the same directory.
bme = BME280(i2c=i2c): Creates a BME280 object to interact with the sensor.
The main loop reads temperature, pressure, and humidity using bme.temperature, bme.pressure, and bme.humidity, printing the results every 2 seconds.
Wrapping Up BME280
The ESP32 BME280 Temperature and Humidity 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 BME280 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the BME280? Check out these similar sensors that might fit your project needs.

AHT10 Temperature and Humidity Sensor
The AHT10 is an advanced, fully calibrated, and highly integrated temperature and humidity sensor that provides reliable, precise...

SHT20 Temperature and Humidity Sensor
The SHT20 sensor is a digital temperature and humidity sensor that utilizes Sensirion's CMOSens® technology. It provides calibrated,...

SHT25 Temperature and Humidity Sensor
The SHT25 sensor is a high-accuracy digital temperature and humidity sensor that utilizes Sensirion's CMOSens® technology. It provides...





