What is the BMP280?
The BMP280 from Bosch measures air pressure and temperature, and because air pressure falls as you climb, it can also estimate altitude. It's sensitive enough to notice you lifting it from the floor to a table, and stable enough to show the slow pressure changes that come before a change in the weather. That makes it the standard part for weather stations, drone and rocket altimeters, and step or floor counters.
This page explains what the numbers mean, how pressure turns into altitude, which of the many BMP280 boards you have (they are not all wired the same), and the mistakes that trip beginners up. For working builds, follow the Arduino Uno guide, with a relative altimeter, or the ESP32 guide, with a weather page that shows the 3-hour pressure trend.
Specifications
- Measures
- Barometric pressure and temperature (no humidity)
- Pressure range
- 300–1100 hPa (about +9,000 m to −500 m)
- Relative accuracy
- ±0.12 hPa, about ±1 m of height (700–900 hPa, 25 °C)
- Absolute accuracy
- About ±1 hPa (950–1050 hPa, 0–40 °C)
- Pressure resolution
- 0.16 Pa (0.0016 hPa) at the highest oversampling
- Pressure noise
- 1.3 Pa RMS unfiltered; about 0.2 Pa with the IIR filter
- Temperature
- −40 to +85 °C range; ±1 °C accuracy (0–65 °C), 0.01 °C resolution
- Supply (chip)
- VDD 1.71–3.6 V, VDDIO 1.2–3.6 V. Not 5 V tolerant
- Current
- 2.7 µA at one reading per second; 0.1 µA asleep
- Interfaces
- I²C up to 3.4 MHz (address 0x76 or 0x77) and SPI up to 10 MHz
- Chip ID
- 0x58 (BME280 is 0x60)
- Package
- 8-pin LGA, 2.0 × 2.5 × 0.95 mm
From the Bosch BMP280 datasheet. Breakout boards add pull-up resistors and sometimes a regulator; check yours.
Pinout (6-pin board)
| Pin | Name | Connection for I²C |
|---|---|---|
| VCC | Power | 3.3 V (or 5 V only if the board has a regulator) |
| GND | Ground | Board ground |
| SCL | I²C clock (SPI: SCK) | Uno A5, ESP32 GPIO22 |
| SDA | I²C data (SPI: SDI) | Uno A4, ESP32 GPIO21 |
| CSB | Chip select | Leave as is: the board pulls it HIGH for I²C. Pulling it LOW at power-up switches to SPI |
| SDO | Address select (SPI: data out) | GND or open = 0x76 on most boards; to 3.3 V = 0x77 |
Wiring & code
Setting up BMP280 with ESP32
Library
Adafruit BMP280 Library by Adafruit
Library Manager: Adafruit BMP280 Library
In this guide you'll connect a BMP280 pressure sensor to an ESP32 and read temperature, pressure and altitude. You'll start with a scanner that finds the sensor's I²C address and tells you whether it's really a BMP280, then read the sensor, set it up for accurate altitude, and finish with a weather page on your phone showing pressure, temperature and the 3-hour trend that hints at what the weather will do.
Allow about 30 minutes. For how the sensor works and which board you have, see the BMP280 overview.
What you need
| Part | Qty | Notes |
|---|---|---|
| ESP32 DevKit | 1 | Powered from USB |
| BMP280 module | 1 | Purple GY-BMP280 (3.3 V) or a 5 V-ready board |
| Breadboard and jumper wires | 1 + 4–8 |
Wiring
The ESP32 is a 3.3 V board, the same as the BMP280, so it connects directly with no level shifter. Use the ESP32's default I²C pins: GPIO21 (SDA) and GPIO22 (SCL).
Wiring: BMP280 to ESP32
| From | To | Note |
|---|---|---|
| BMP280 VCC | ESP32 3V3 | Never 5V on a 3.3 V-only board |
| BMP280 GND | ESP32 GND | |
| BMP280 SDA | ESP32 GPIO21 | I²C data |
| BMP280 SCL | ESP32 GPIO22 | I²C clock |
| BMP280 SDO | Leave open (or GND) | 0x76; to 3V3 for 0x77 |
| BMP280 CSB | Leave open | The board keeps it HIGH for I²C |
- 1Unplug the ESP32.
- 2Connect VCC to 3V3 and GND to GND.
- 3Connect SDA to GPIO21 and SCL to GPIO22.
- 4Leave CSB and SDO unconnected. Mount the sensor a few centimetres from the ESP32, which gets warm.
- 5Plug in USB.
Set up the IDE and library
- In Arduino IDE 2, install esp32 by Espressif Systems from the Boards Manager and select ESP32 Dev Module.
- In the Library Manager, install Adafruit BMP280 Library and accept its dependencies (Adafruit Unified Sensor and BusIO).
Step 1: find the address and identify the chip
This sketch lists every I²C device and reads the chip-ID register of anything at 0x76 or 0x77. It catches the two most common problems before you write any real code: the wrong address, and a "BMP280" that's actually a BME280.
// BMP280 - Step 1: find the I2C address and identify the chip
// Prints every I2C device and, for 0x76/0x77, what the chip really is.
#include <Wire.h>
byte chipId(byte addr) {
Wire.beginTransmission(addr);
Wire.write(0xD0); // chip-ID register
if (Wire.endTransmission() != 0) return 0;
Wire.requestFrom(addr, (byte)1);
return Wire.available() ? Wire.read() : 0;
}
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // ESP32: SDA = GPIO21, SCL = GPIO22
delay(200);
Serial.println(F("Scanning I2C..."));
for (byte a = 1; a < 127; a++) {
Wire.beginTransmission(a);
if (Wire.endTransmission() == 0) {
Serial.print(F("Found device at 0x"));
Serial.print(a, HEX);
if (a == 0x76 || a == 0x77) {
byte id = chipId(a);
Serial.print(F(" chip ID 0x"));
Serial.print(id, HEX);
if (id == 0x58) Serial.print(F(" -> BMP280 (use this guide)"));
else if (id == 0x60) Serial.print(F(" -> BME280! Use the BME280 library"));
else if (id == 0x55) Serial.print(F(" -> BMP180"));
else if (id == 0x56 || id == 0x57) Serial.print(F(" -> BMP280 sample, works the same"));
}
Serial.println();
}
}
Serial.println(F("Done."));
}
void loop() {}Scanning I2C...
Found device at 0x76 chip ID 0x58 -> BMP280 (use this guide)
Done.Reading Step 1
| Result | What to do |
|---|---|
| 0x76, chip ID 0x58 | A BMP280 at 0x76: the most common case. Use 0x76 in Step 2 |
| 0x77, chip ID 0x58 | A BMP280 at 0x77 (Adafruit, or SDO to 3.3 V). Use 0x77 |
| Chip ID 0x60 | It's a BME280: it also measures humidity. Use the BME280 guide |
| No device found | Wiring: check power, ground, and that SDA and SCL aren't swapped |
Step 2: read temperature, pressure and altitude
Set BMP_ADDR to the address from Step 1 and upload. The sketch uses Bosch's low-noise settings: pressure oversampling ×16 and the IIR filter at ×16.
// BMP280 + ESP32 - Step 2: temperature, pressure and altitude
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
const byte BMP_ADDR = 0x76; // from Step 1: 0x76 (most purple boards) or 0x77
const float SEA_LEVEL_HPA = 1013.25; // replace with today's local sea-level pressure
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA = GPIO21, SCL = GPIO22
if (!bmp.begin(BMP_ADDR)) {
Serial.println(F("BMP280 not found - check wiring and BMP_ADDR"));
while (true) delay(10);
}
// Low-noise settings: one filtered reading every 0.5 s
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2, // temperature oversampling
Adafruit_BMP280::SAMPLING_X16, // pressure oversampling
Adafruit_BMP280::FILTER_X16, // IIR filter smooths gusts
Adafruit_BMP280::STANDBY_MS_500);
}
void loop() {
float tempC = bmp.readTemperature();
float hPa = bmp.readPressure() / 100.0; // library gives pascals
float metres = bmp.readAltitude(SEA_LEVEL_HPA);
Serial.print(F("Temp: ")); Serial.print(tempC, 2);
Serial.print(F(" C Pressure: ")); Serial.print(hPa, 2);
Serial.print(F(" hPa Altitude: ")); Serial.print(metres, 1);
Serial.println(F(" m"));
delay(1000);
}Temp: 27.84 C Pressure: 908.62 hPa Altitude: 908.9 m
Temp: 27.85 C Pressure: 908.61 hPa Altitude: 909.0 m
Temp: 27.85 C Pressure: 908.63 hPa Altitude: 908.8 mHow Step 2 works
| Line | What it does |
|---|---|
bmp.begin(BMP_ADDR) | Starts the sensor at your address and loads its factory calibration |
setSampling(...) | Normal mode, temperature ×2, pressure ×16, IIR filter ×16, a new reading every 0.5 s |
readPressure() / 100.0 | The library returns pascals; 100 Pa = 1 hPa |
readAltitude(SEA_LEVEL_HPA) | Converts pressure to altitude using today's sea-level pressure |
That example was taken in Bengaluru, at about 920 m. Pressure near 908 hPa is normal there. Near the coast you'd see 1000–1020 hPa.
Make the altitude correct. Look up today's sea-level pressure (QNH) for your city: airport METAR reports and many weather sites give it. Put it in SEA_LEVEL_HPA. Or, if you know your exact elevation, work backwards: P0 = P / pow(1 - h / 44330.0, 5.255) gives the sea-level pressure that makes the sensor read your known height.
Project: weather page with a 3-hour trend
Weather forecasters care less about the pressure itself than about how it's changing. A fall of more than about 1.6 hPa in three hours often means unsettled weather is coming; a steady rise usually means it's clearing. This sketch stores a reading every 10 minutes, compares now with three hours ago, and shows the result on a page you open on your phone.
// BMP280 + ESP32 - Project: weather page with a 3-hour pressure trend
#include <WiFi.h>
#include <WebServer.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
const char* WIFI_SSID = "YourWiFi";
const char* WIFI_PASS = "YourPassword";
const byte BMP_ADDR = 0x76;
Adafruit_BMP280 bmp;
WebServer server(80);
const int SLOTS = 19; // one reading every 10 min: 18 gaps = 3 hours
float history[SLOTS];
int stored = 0;
float tempC, hPa;
void sample() {
tempC = bmp.readTemperature();
hPa = bmp.readPressure() / 100.0;
}
void remember() { // shift the window, newest last
if (stored < SLOTS) history[stored++] = hPa;
else { memmove(history, history + 1, (SLOTS - 1) * sizeof(float)); history[SLOTS - 1] = hPa; }
}
String trend(float &change) {
if (stored < SLOTS) { change = 0; return "Collecting (needs 3 hours)"; }
change = history[SLOTS - 1] - history[0];
float a = fabs(change);
String dir = change > 0 ? "rising" : "falling";
if (a < 0.5) return "Steady";
if (a < 1.6) return "Slowly " + dir;
if (a < 3.6) return change > 0 ? "Rising: improving weather" : "Falling: unsettled weather likely";
return change > 0 ? "Rising quickly: clearing, windy" : "Falling quickly: storm risk";
}
const char PAGE[] PROGMEM = R"html(<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<style>body{font-family:system-ui;text-align:center}b{font-size:2.6em;display:block}</style>
<h3>BMP280 weather</h3><p>Pressure<b id=p>-</b></p><p>Temperature<b id=t>-</b></p><p id=r></p>
<script>async function u(){const j=await (await fetch('/data')).json();
p.textContent=j.p.toFixed(1)+' hPa';t.textContent=j.t.toFixed(1)+' °C';
r.textContent=j.trend+(j.ready?' ('+(j.d>0?'+':'')+j.d.toFixed(1)+' hPa in 3 h)':'')}u();setInterval(u,5000)</script>)html";
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!bmp.begin(BMP_ADDR)) { Serial.println("BMP280 not found"); while (true) delay(10); }
// Bosch's "weather monitoring" idea: low oversampling, filter off, slow updates
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, Adafruit_BMP280::SAMPLING_X1,
Adafruit_BMP280::SAMPLING_X1, Adafruit_BMP280::FILTER_OFF,
Adafruit_BMP280::STANDBY_MS_4000);
sample(); remember();
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(250);
Serial.print("Open http://"); Serial.println(WiFi.localIP());
server.on("/", [] { server.send_P(200, "text/html", PAGE); });
server.on("/data", [] {
float d; String t = trend(d);
String json = "{\"p\":" + String(hPa, 2) + ",\"t\":" + String(tempC, 2) +
",\"d\":" + String(d, 2) + ",\"ready\":" + (stored == SLOTS ? "true" : "false") +
",\"trend\":\"" + t + "\"}";
server.send(200, "application/json", json);
});
server.begin();
}
void loop() {
server.handleClient();
static unsigned long lastRead = 0, lastStore = millis();
if (millis() - lastRead > 5000) { lastRead = millis(); sample(); }
if (millis() - lastStore > 600000) { lastStore = millis(); remember(); } // every 10 min
}How the weather page works
| Part of the code | What it does |
|---|---|
setSampling(... FILTER_OFF, STANDBY_MS_4000) | Weather settings: low oversampling, no filter, a reading every 4 s. Weather is slow; this saves power |
history[19] | Stores one reading every 10 minutes: 19 readings span exactly 3 hours |
trend() | Compares the newest and oldest stored readings and describes the change |
/data | Returns the latest pressure, temperature and trend as JSON for the page |
Reading the trend. For the first three hours the page says "Collecting". After that:
| 3-hour change | Page shows |
|---|---|
| less than ±0.5 hPa | Steady |
| 0.5–1.5 hPa | Slowly rising / falling |
| 1.6–3.5 hPa | Rising: improving, or Falling: unsettled |
| more than 3.5 hPa | Rising quickly, or Falling quickly: storm risk |
These are rules of thumb, not a forecast; local geography matters. Leave the ESP32 running for a day or two and compare with what the sky does.
Going further. Publish the readings to Home Assistant over MQTT, log them for a week-long pressure graph, or run the ESP32 on a battery with deep sleep between readings: the BMP280 itself draws just 2.7 µA at one reading per second.
Try it in the simulator
The circuit below is the wiring from this guide with the Adafruit BMP280 sketch loaded. Press Run and open the Serial Monitor, then change the temperature and pressure from the BMP280's Settings: lower the pressure by 12 hPa and the altitude rises by about 100 m, the same relation the chart on the main BMP280 page shows.
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.
Troubleshooting
Common problems and fixes
"BMP280 not found"
- Likely cause
- Address mismatch (library default is 0x77)
- Fix
- Use the address from Step 1 in BMP_ADDR
Scanner finds nothing
- Likely cause
- SDA/SCL swapped, no power, bad solder joint
- Fix
- Check wiring; re-solder the header if needed
Chip ID 0x60
- Likely cause
- It's a BME280
- Fix
- Use the BME280 library and guide
Altitude far from your real height
- Likely cause
- Sea-level pressure not set
- Fix
- Enter today's QNH, or calculate P0 from a known height
Temperature reads several degrees high
- Likely cause
- Heat from the ESP32 or regulator
- Fix
- Move the sensor away on short wires
Values jump when people move nearby
- Likely cause
- Draughts
- Fix
- Shield the sensor; keep the IIR filter on
Readings stop when Wi-Fi starts
- Likely cause
- Power dip on a weak USB supply
- Fix
- Use a better cable or supply
Frequently asked questions
Can I use other I²C pins?
Yes: call Wire.begin(SDA, SCL) with any free GPIOs before bmp.begin(). Avoid input-only GPIO34–39.
Can I use two BMP280s?
Yes. Wire one board's SDO to 3.3 V to make it 0x77, and create two objects: bmp1.begin(0x76) and bmp2.begin(0x77).
Why is my pressure lower than the weather forecast? The forecast shows pressure corrected to sea level. The sensor shows the real pressure where it is, which is lower the higher you live.
Do I need to calibrate the BMP280? Not for pressure: each chip carries its own factory calibration. You only set the sea-level reference for altitude.
What to build next
- Weather station: add humidity with a BME280 or a DHT22.
- Display it: show readings on an LCD1602 I²C sharing the same two I²C pins.
- Altimeter: the Uno guide has a relative altimeter; the same code runs on the ESP32.









