What does the BME280 measure?
The Bosch BME280 combines temperature, relative humidity and barometric pressure sensing. It communicates over I²C or SPI and relies on factory calibration data stored on the chip. It is not a gas, CO₂, VOC or particulate-matter sensor.
Wiring & code
Setting up BME280 with ESP32
Library
Adafruit BME280 Library by Adafruit
Library Manager: search "Adafruit BME280" and accept its dependencies (Unified Sensor, BusIO)
The BME280 measures temperature, relative humidity and air pressure in one tiny Bosch chip, and talks over I²C. This guide wires it to an ESP32, reads all three values with the Adafruit library, checks that the chip really is a BME280, and then builds a comfort monitor that works out the dew point and the pressure trend.
Wiring
| Component pin | ESP32 pin | Note |
|---|---|---|
| VIN | 3V3 | The ESP32 is a 3.3 V board, so no level shifter is needed |
| GND | GND | |
| SDA | GPIO21 | Default Wire SDA |
| SCL | GPIO22 | Default Wire SCL |
| SDO (6-pin boards) | GND | Address 0x76; tie to 3V3 for 0x77 |
| CSB (6-pin boards) | 3V3 or open | HIGH selects I²C |
Install the library
In the Arduino IDE open Tools → Manage Libraries, search for Adafruit BME280 and install Adafruit BME280 Library. Accept the prompt to install its dependencies too: Adafruit Unified Sensor and Adafruit BusIO.
Read temperature, humidity and pressure
/*
BME280: temperature, humidity, pressure and altitude with the Adafruit BME280 library
VIN -> 3V3, GND -> GND, SDA -> GPIO21, SCL -> GPIO22
Address 0x76 (SDO to GND); use 0x77 if SDO is tied HIGH
*/
#include <Wire.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 sensor;
const float SEA_LEVEL_HPA = 1013.25; // set to today's sea-level pressure for an accurate altitude
void setup() {
Serial.begin(115200);
if (!sensor.begin(0x76)) {
Serial.println("BME280 not found at 0x76: check the wiring, try 0x77, check the chip ID");
while (true) delay(10);
}
Serial.print("BME280 found, chip ID 0x");
Serial.println(sensor.sensorID(), HEX); // 0x60 = BME280, 0x58 = BMP280
}
void loop() {
Serial.print("Temperature: ");
Serial.print(sensor.readTemperature(), 1);
Serial.println(" C");
Serial.print("Humidity: ");
Serial.print(sensor.readHumidity(), 1);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(sensor.readPressure() / 100.0, 1); // Pa -> hPa
Serial.println(" hPa");
Serial.print("Altitude: ");
Serial.print(sensor.readAltitude(SEA_LEVEL_HPA), 0);
Serial.println(" m");
Serial.println();
delay(2000);
}What the numbers mean. readPressure() returns pascals, so divide by 100 for hPa (the same as millibars). The altitude is calculated from pressure, so it is only as good as the sea-level value you give it: look up today's sea-level pressure for your nearest weather station and put it in SEA_LEVEL_HPA, or expect an error of tens of metres. The chip ID tells you what you really have: 0x60 is a BME280, 0x58 a BMP280 with no humidity sensor. Boards are often mislabelled, and a BMP280 makes begin() fail here.
Self-heating. In the library's default mode the BME280 measures continuously and warms itself slightly, and the board around it warms it more. Keep it away from the ESP32 module and its regulator, on a short cable if you can, and expect the temperature to read a little high indoors.
Try it in the simulator
This is the circuit above with the first sketch loaded. Press Run and open the Serial Monitor, then change temperature, humidity and pressure from the BME280's Settings and watch each reading follow.
Try this circuit in the SolderHub Simulator
Run this exact circuit in your browserReady-wired, code loadedConfirm simulator behavior against the real wiring and the sensor datasheet before connecting hardware.
Comfort monitor: dew point and pressure trend
Relative humidity on its own says little about how a room feels, because it depends on the temperature. The dew point does not: below about 10 °C the air feels dry, above about 16 °C it starts to feel humid, and above 21 °C it is muggy. This sketch calculates it with the Magnus formula and also compares the pressure with the reading from a minute ago. Change TREND_MS to three hours for a real weather trend: falling pressure usually means unsettled weather is coming.
/*
BME280 comfort monitor: dew point, a comfort label and the pressure trend
Same wiring as the first sketch.
*/
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <math.h>
Adafruit_BME280 bme;
float lastPressure = 0;
unsigned long lastTrend = 0;
const unsigned long TREND_MS = 60000; // compare pressure once a minute (use 3 hours for a weather trend)
// Magnus formula: good to about ±0.4 °C between -45 and 60 °C
float dewPoint(float t, float rh) {
const float a = 17.62, b = 243.12;
float g = log(rh / 100.0) + a * t / (b + t);
return b * g / (a - g);
}
void setup() {
Serial.begin(115200);
if (!bme.begin(0x76)) {
Serial.println("BME280 not found");
while (true) delay(10);
}
lastPressure = bme.readPressure() / 100.0;
lastTrend = millis();
}
void loop() {
float t = bme.readTemperature();
float rh = bme.readHumidity();
float p = bme.readPressure() / 100.0;
float dp = dewPoint(t, rh);
const char *comfort = dp < 10 ? "dry" : dp < 16 ? "comfortable" : dp < 21 ? "humid" : "muggy";
Serial.print(t, 1); Serial.print(" C ");
Serial.print(rh, 0); Serial.print(" % dew point ");
Serial.print(dp, 1); Serial.print(" C (");
Serial.print(comfort); Serial.println(")");
if (millis() - lastTrend >= TREND_MS) {
float change = p - lastPressure;
Serial.print("Pressure ");
Serial.print(p, 1);
Serial.print(" hPa, ");
Serial.println(change > 0.5 ? "rising" : change < -0.5 ? "falling" : "steady");
lastPressure = p;
lastTrend = millis();
}
delay(2000);
}Troubleshooting
| Symptom | Fix |
|---|---|
BME280 not found | Run an I²C scanner. Nothing found: check SDA/SCL and GND. Found at 0x77: change begin(0x76) to begin(0x77) |
Found at 0x76 but begin() still fails | It is probably a BMP280 (chip ID 0x58). Use the Adafruit BMP280 library instead; it has no humidity reading |
| Humidity always 0 or 100 % | A BMP280 sold as a BME280, or a damaged sensor. Check the chip ID |
| Temperature reads 2–3 °C high | Self-heating: move the sensor away from the board and regulator, or use forced mode with a slow sample rate |
| Altitude is tens of metres off | Set SEA_LEVEL_HPA to today's local sea-level pressure |
| Works on USB, fails on battery | Check the 3.3 V rail under Wi-Fi load; add a 10 µF capacitor near the sensor |









