Source: https://mokxi.com/libraries/adafruit-bme280
Updated: 2026-11-17

Libraries / Sensors

Arduino library · Sensors

# Adafruit BME280 library: temperature, humidity and pressure on I2C

Yes. You can use the Adafruit BME280 Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Pressure, humidity and temperature, BME280). The example below, "Temperature, pressure, altitude and humidity from a BME280", runs on the Arduino Uno R3.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <Adafruit_BME280.h> and it builds, with nothing to install. Free, and no account needed.

## What Adafruit BME280 Library does

The BME280 is a small Bosch sensor that measures temperature, relative humidity and air pressure, and the Adafruit BME280 library is the usual way to read it from an Arduino or ESP32. It talks over I2C with just four wires (power, ground, SDA and SCL), so on an Uno the data lines are A4 and A5.

The address is the first thing to get right. begin() with no argument looks at 0x77, which is where Adafruit’s own board puts the sensor. Most of the purple modules sold for Arduino are strapped to 0x76, and so is the sensor in Mokxi by default, so tutorials written for them say bme.begin(0x76). When begin() returns false, the address is the first thing to check.

A reading is one call: readTemperature() in degrees Celsius, readHumidity() in percent and readPressure() in pascals, so the sketches divide by 100.0F to print hectopascals. readAltitude() works the height out from the pressure and needs the sea-level pressure for your day, 1013.25 hPa being the standard value.

Library Manager name | Adafruit BME280 Library

Author | Adafruit

Include | #include <Adafruit_BME280.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Pressure, humidity and temperature, BME280

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_BME280.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit BME280 Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit BME280 Library to lib_deps in PlatformIO. Mokxi follows the calls of release 2.3.0, so a sketch written here builds there too.

What to know in the simulator: The SPI constructors build, and begin() says on Serial that the SPI module is not simulated: Mokxi’s BME280 is the I2C module.

- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### Adafruit_BME280 bme

Makes the sensor object for the I2C version. Everything else is a call on it.

### bme.begin(0x76)

Starts the sensor at the given I2C address and returns false if nothing answers there. With no argument it uses 0x77.

### bme.readTemperature()

Temperature in degrees Celsius, to the hundredth.

### bme.readHumidity()

Relative humidity in percent.

### bme.readPressure()

Air pressure in pascals. Divide by 100.0F for hectopascals.

### bme.readAltitude(SEALEVELPRESSURE_HPA)

Altitude in meters, worked out from the pressure and the sea-level pressure you give it in hectopascals.

### bme.sensorID()

The chip ID the sensor reports, which is how you tell a BME280 from a look-alike when begin() fails.

### bme.setSampling(Adafruit_BME280::MODE_NORMAL)

Chooses the measuring mode, the oversampling of each reading and the filter. The defaults suit most sketches.

## Example: Temperature, pressure, altitude and humidity from a BME280

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 A4 to Pressure, humidity and temperature, BME280 SDA
- Arduino Uno R3 A5 to Pressure, humidity and temperature, BME280 SCL
- Arduino Uno R3 5V to Pressure, humidity and temperature, BME280 VIN
- Arduino Uno R3 GND to Pressure, humidity and temperature, BME280 GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### Could not find a valid BME280 sensor, check wiring, address, sensor ID!

This is the example sketch’s own message when begin() returns false. Try bme.begin(0x76) if you used the default and bme.begin(0x77) if you used 0x76, check that SDA goes to A4 and SCL to A5 on an Uno, and that the module has power and ground.

### SensorID was: 0x58

The chip is a BMP280, not a BME280. It measures temperature and pressure only, so it has no humidity. Use the Adafruit BMP280 library for it, or buy a module that really says BME280 on the chip.

### The pressure reads about 101325 instead of 1013

readPressure() returns pascals, not hectopascals. Divide it by 100.0F before printing it as hPa, as the example does.

### Altitude is hundreds of meters wrong

readAltitude() compares the pressure with the sea-level pressure you pass. The standard 1013.25 is only right on an average day, so use today’s local sea-level pressure from a weather report for a better number.

## Projects that use Adafruit BME280 Library

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Indoor and outdoor thermometer on two OLEDs Two BME280s and two SSD1306 OLEDs share their addresses, so a TCA9548A puts each pair on its own channel: each screen shows its own weather. ESP32 async web server: BME280, slider and relay ESPAsyncWebServer serves a page with BME280 temperature, humidity and pressure, a slider that dims an LED and a button that switches a relay. LoRa weather station with acknowledgments A BME280 node sends temperature, humidity and pressure over LoRa with RadioHead, and a gateway acknowledges each reading and shows it on an I2C LCD.

## Keep going

### Parts

- Pressure, humidity and temperature, BME280

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- BME280
- Adafruit DPS310
- ClosedCube OPT3001
- GyverDS18
- microDS18B20
- arduino-sht
- Sensirion I2C SHT3x

Every built-in library · Open the editor

## Try Adafruit BME280 Library without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
