Adafruit BME280 Library
by Adafruit
This is Adafruit's driver for the BME280 combined pressure/humidity/temperature sensor, wrapping the chip's factory calibration coefficients and register reads behind simple `readTemperature()`, `readHumidity()`, and `readPressure()` calls. It supports both I2C and SPI, auto-detecting which you're using based on which `begin()` overload you call. It also includes `readAltitude(seaLevelHPa)`, which converts the raw pressure reading into an estimated altitude using the standard barometric formula — handy for weather stations, but remember it needs an accurate local sea-level pressure reference to be precise, since altitude-from-pressure drifts with weather changes if you just hardcode 1013.25 hPa.
Installation
Arduino IDE — Library Manager
Sketch → Include Library → Manage Libraries → search Adafruit BME280 Library
PlatformIO
lib_deps = adafruit/Adafruit BME280 LibrarySupported boards
Examples
Basic temperature read
Minimal setup shared across every BME280 board integration on this site.
#include <Wire.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
bme.begin(0x76);
}
void loop() {
Serial.println(bme.readTemperature());
delay(1000);
}Estimate altitude from pressure
Converts barometric pressure to altitude — accuracy depends on an up-to-date local sea-level pressure reference.
float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
Serial.print("Altitude: ");
Serial.print(altitude);
Serial.println(" m");