Complete Tutorial: Environmental Sensing with Bosch's All-in-One Sensor
The BME280 is a precision environmental sensor manufactured by Bosch Sensortec. Unlike single-function sensors, the BME280 measures three environmental parameters simultaneously: temperature, humidity, and barometric pressureβmaking it an ideal choice for weather stations, indoor climate monitoring, and altitude estimation projects.
This sensor is particularly popular in IoT applications due to its small size, low power consumption, and high accuracy. It communicates via I2C or SPI, making it compatible with virtually any microcontroller.
| Parameter | Specification |
|---|---|
| Operating Voltage | 1.8V β 3.6V (module: 3.3V β 5V) |
| Interface | I2C (up to 3.4MHz) / SPI (up to 10MHz) |
| Temperature Range | -40Β°C to +85Β°C |
| Temperature Accuracy | Β±1.0Β°C (typical Β±0.5Β°C) |
| Humidity Range | 0% β 100% RH |
| Humidity Accuracy | Β±3% RH |
| Pressure Range | 300 β 1100 hPa |
| Pressure Accuracy | Β±1.0 hPa |
| Current Consumption | 3.6 Β΅A @ 1Hz sampling |
The BME280 contains three separate sensing elements:
The internal ADC converts all readings to digital values, and an integrated compensation engine applies factory-calibrated corrections for maximum accuracy.
The BME280 can estimate altitude using the barometric pressure formula. At sea level, pressure is approximately 1013.25 hPa. For every 8.5 meters of elevation gain, pressure drops by about 1 hPa.
| Feature | BMP280 | BME280 | BME680 |
|---|---|---|---|
| Temperature | β | β | β |
| Pressure | β | β | β |
| Humidity | β | β | β |
| Gas/VOC | β | β | β |
| Price | ~$2-4 | ~$4-8 | ~$10-15 |
| Best For | Altitude only | Weather stations | Air quality |
The BME280 module uses I2C for communication, requiring only 4 wires.
| BME280 Pin | Description | ESP32 | Arduino Uno |
|---|---|---|---|
| VIN / VCC | Power (3.3V-5V) | 3.3V | 3.3V |
| GND | Ground | GND | GND |
| SCL | I2C Clock | GPIO 22 | A5 |
| SDA | I2C Data | GPIO 21 | A4 |
Figure 1: BME280 I2C wiring with ESP32
The default I2C address is 0x76. If your sensor has an SDO pin and it's connected to VCC, the address changes to 0x77. Update your code accordingly.
Let's build a Weather Station Monitor that reads temperature, humidity, and pressure from the BME280, calculates altitude, and displays weather conditions.
Install via Arduino Library Manager:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
// ========== CONFIGURATION ==========
#define SEALEVELPRESSURE_HPA (1013.25) // Standard sea level pressure
Adafruit_BME280 bme; // Create BME280 object (I2C)
// ========== SETUP ==========
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("========================================");
Serial.println(" Weather Station Monitor v1.0");
Serial.println(" BME280 Environmental Sensor");
Serial.println("========================================");
Serial.println();
// Initialize BME280 at I2C address 0x76
if (!bme.begin(0x76)) {
Serial.println("β ERROR: BME280 not found!");
Serial.println(" Check wiring or try address 0x77");
while (1) delay(10);
}
Serial.println("β
BME280 initialized successfully!");
Serial.println();
delay(1000);
}
// ========== MAIN LOOP ==========
void loop() {
// Read all sensor values
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F; // Convert Pa to hPa
float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
// Display formatted output
Serial.println("ββββββββββββββββββββββββββββββββββββββββ");
Serial.print("π‘οΈ Temperature: ");
Serial.print(temperature, 1);
Serial.print("Β°C (");
Serial.print(temperature * 9.0 / 5.0 + 32, 1);
Serial.println("Β°F)");
Serial.print("π§ Humidity: ");
Serial.print(humidity, 1);
Serial.println("% RH");
Serial.print("π Pressure: ");
Serial.print(pressure, 1);
Serial.println(" hPa");
Serial.print("β°οΈ Altitude: ");
Serial.print(altitude, 1);
Serial.println(" m");
// Weather prediction based on pressure
Serial.print("π€οΈ Forecast: ");
if (pressure > 1022) {
Serial.println("βοΈ Clear skies");
} else if (pressure > 1009) {
Serial.println("β
Fair weather");
} else if (pressure > 1000) {
Serial.println("βοΈ Cloudy");
} else {
Serial.println("π§οΈ Rain likely");
}
delay(3000); // Update every 3 seconds
}
========================================
Weather Station Monitor v1.0
BME280 Environmental Sensor
========================================
β
BME280 initialized successfully!
ββββββββββββββββββββββββββββββββββββββββ
π‘οΈ Temperature: 24.3Β°C (75.7Β°F)
π§ Humidity: 48.2% RH
π Pressure: 1015.4 hPa
β°οΈ Altitude: 18.2 m
π€οΈ Forecast: β
Fair weather
The BME280 supports different operating modes for power optimization:
| Mode | Description | Use Case |
|---|---|---|
| Sleep | No measurements, minimal power | Battery-powered standby |
| Forced | Single measurement, then sleep | Periodic readings |
| Normal | Continuous measurements | Real-time monitoring |
The BME280 is an excellent all-in-one environmental sensor for weather monitoring, altitude estimation, and indoor climate control. Its combination of temperature, humidity, and pressure sensing in a single low-power package makes it ideal for IoT and battery-powered applications.