Skip to content

BME280 Temperature, Humidity, and Pressure Sensor

Welcome to the BME280 Sensor Lab

Monty waving welcome The BME280 is a tiny sensor that measures three things at once: temperature, humidity, and air pressure. One small chip — three readings! Let's build something amazing!

What Is the BME280?

The BME280 is a precision environmental sensor made by Bosch. It measures:

  • Temperature — in degrees Celsius, accurate to ±1°C
  • Relative humidity — as a percentage, accurate to ±3%
  • Air pressure — in hectopascals (hPa), accurate to ±1 hPa

It connects to the Pico using I2C — just four wires. The sensor costs about $2–$4.

BME280 sensor module

Key Idea

Monty thinking The BMP280 is a similar but cheaper sensor that only measures temperature and pressure — it does not measure humidity. Make sure your module says BME280, not BMP280, if you need humidity readings.

Parts You Need

Part Quantity Approximate Cost
Raspberry Pi Pico 1 $4
BME280 I2C module 1 $2–$4
Solderless breadboard 1 $3
Jumper wires 4

Wiring Steps

The BME280 module has four pins. Connect them to the Pico like this:

  1. Connect GND on the BME280 to any GND pin on the Pico.
  2. Connect VCC on the BME280 to the 3.3 V (pin 36) on the Pico.
  3. Connect SCL on the BME280 to GP1 on the Pico.
  4. Connect SDA on the BME280 to GP0 on the Pico.
BME280 Pin Pico Pin Signal
GND GND Ground
VCC 3V3 (pin 36) 3.3 V power
SCL GP1 I2C clock
SDA GP0 I2C data

Install the BME280 Library

The Pico does not include a BME280 library by default. You need to copy the driver file to your Pico before running the sample code.

  1. Download bme280.py from the micropython-bme280 repository.
  2. Open Thonny and connect your Pico.
  3. Use File → Save as to save bme280.py directly onto the Pico.

I2C Scanner (Check Your Wiring)

Run this first to confirm the sensor is connected correctly:

1
2
3
4
5
6
7
8
from machine import Pin, I2C

# Set up I2C bus 0 on GP0 (SDA) and GP1 (SCL)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)

# Scan for connected I2C devices
devices = i2c.scan()
print("I2C devices found at addresses:", [hex(d) for d in devices])

You should see 0x76 (decimal 118) or 0x77 (decimal 119) in the output. If you see nothing, check your wiring and make sure VCC is connected to 3.3 V.

Reading the Sensor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from machine import Pin, I2C
import bme280  # the driver file you saved to the Pico

# Set up I2C and the BME280 sensor
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
sensor = bme280.BME280(i2c=i2c)

# Read all three values
temperature, pressure, humidity = sensor.read_compensated_data()

# The raw values need scaling
temperature = temperature / 100      # convert to degrees Celsius
pressure = pressure / 256 / 100      # convert to hPa
humidity = humidity / 1024           # convert to percent

print(f"Temperature: {temperature:.1f} °C")
print(f"Humidity:    {humidity:.1f} %")
print(f"Pressure:    {pressure:.1f} hPa")

What Each Line Does

Line Purpose
I2C(0, sda=Pin(0), scl=Pin(1)) Creates I2C bus 0 on GP0 and GP1
bme280.BME280(i2c=i2c) Connects to the BME280 at its default address
sensor.read_compensated_data() Reads all three measurements at once
temperature / 100 Scales the raw integer to degrees Celsius
pressure / 256 / 100 Scales the raw integer to hectopascals
humidity / 1024 Scales the raw integer to a percentage

Monty's Tip

Monty giving a tip Air pressure changes with altitude. If you carry the sensor upstairs, the pressure reading will drop slightly. This is how smartphones know which floor of a building you are on!

Logging Sensor Data

This loop reads the sensor every 5 seconds and prints a timestamp with each reading — useful for tracking weather changes over time:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from machine import Pin, I2C
import bme280
import time

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
sensor = bme280.BME280(i2c=i2c)

reading_number = 0

while True:
    reading_number += 1
    t, p, h = sensor.read_compensated_data()
    temp = t / 100
    hum  = h / 1024
    pres = p / 256 / 100
    print(f"#{reading_number:04d}  {temp:.1f}°C  {hum:.0f}%  {pres:.1f} hPa")
    time.sleep(5)  # wait 5 seconds between readings

Great Work!

Monty celebrating You are now reading three environmental measurements with one tiny sensor! Next, try displaying the readings on an OLED screen so you can build your own portable weather station.

References

  1. Bosch BME280 Product Page
  2. micropython-bme280 library (robert-hh)
  3. MicroPython I2C Documentation
  4. DIY Projects Lab – Pico W Web Server with BME280