Source: https://mokxi.com/libraries/bme280-finitespace
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# BME280 (finitespace): pressure, temperature and humidity in one read

The BME280 is Bosch’s combined pressure, temperature and humidity sensor, and the BME280 library by Tyler Glenn (published under finitespace) is a compact driver for it. Its class for the I2C module is BME280I2C, and one read() call fills three floats at once in the units you choose: Celsius or Fahrenheit, and pascals, hectopascals, inches of mercury and more for pressure.

Open the example in the editor See the calls

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

## What BME280 does

The library ships a second header, EnvironmentCalculations.h, with the formulas weather sketches always need: altitude from pressure, dew point, sea-level pressure, absolute humidity and heat index. They are plain functions, so they work on readings from any sensor.

Two things to know. Only the I2C class is here, not the SPI one. And the SparkFun BME280 library also names its class BME280, so the two libraries cannot be included in one sketch, exactly as on a real board.

Library Manager name | BME280

Author | Tyler Glenn

Include | #include <BME280I2C.h>
#include <EnvironmentCalculations.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 <BME280I2C.h> and the sketch compiles, with no download, no zip and no Library Manager.

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

What to know in the simulator: SPI is not here. The SparkFun BME280 library also names its class BME280, so the two cannot share a sketch, as upstream.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · 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.

### BME280I2C bme

Creates the sensor with default settings at address 0x76.

### bme.begin()

Starts the sensor. Returns false when no BME280 or BMP280 answers. Call Wire.begin() first.

### bme.chipModel()

Tells a BME280 from a BMP280, which has no humidity sensor. Compare with BME280::ChipModel_BME280.

### bme.read(pres, temp, hum, tempUnit, presUnit)

Reads all three values into float variables.

### EnvironmentCalculations::Altitude(pres, EnvironmentCalculations::AltitudeUnit_Meters)

Height above sea level from pressure, against the standard 1013.25 hPa unless you pass your local sea-level pressure.

### EnvironmentCalculations::DewPoint(temp, hum, EnvironmentCalculations::TempUnit_Celsius)

The dew point from a temperature and a humidity.

### bme.setSettings(settings)

Applies a BME280I2C::Settings object: oversampling for each reading, the mode, the standby time, the filter and the I2C address (0x77 for some boards).

## Example: Temperature, humidity and pressure with BME280I2C

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 BME280 sensor!

begin() returned false. Many boards sit at 0x77 instead of 0x76: set the address in a BME280I2C::Settings object and pass it to the constructor. Check the I2C wires and that Wire.begin() ran.

### Humidity reads NaN or 0 all the time

The chip is probably a BMP280, which looks the same and has no humidity sensor. chipModel() tells you which you have.

### conflicting declaration 'class BME280'

Two BME280 libraries are in one sketch, this one and SparkFun’s, and both define a class called BME280. Keep one library and remove the other’s include.

## Keep going

### Learn

- Arduino BME680: Air Quality, Gas and Weather
- Arduino BMP180: Pressure, Altitude and Code

### Parts

- Pressure, humidity and temperature, BME280

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- Adafruit BMP280 Library

Every built-in library · Open the editor

## Try BME280 without installing anything

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

Start building free

Open the editor
