Skip to content

Project 1.12.28

Bluetooth Environmental Monitor

Overview

Build a Bluetooth environmental monitor that sends temperature and humidity data from a BME280 sensor to a phone app.

This project demonstrates BLE monitoring with a real I2C sensor.

The final result should let a phone request the latest temperature and humidity values from the Pico.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
BME280 module
BME280 module
Breadboard
Breadboard
Jumper wires
Jumper wires
Phone with BLE app
Phone with BLE app

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
BME280 VCC 3.3V Physical pin 36 —
BME280 GND GND Physical pin 38 —
BME280 SDA GPIO 8 GPIO 8 / physical pin 11 I2C0 SDA
BME280 SCL GPIO 9 GPIO 9 / physical pin 12 I2C0 SCL

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2W

Place the Raspberry Pi Pico 2W on the breadboard so it sits across the center gap. Keep the USB port facing outward so you can easily connect it to your computer.

Step 1

Step 2: Place the BME280 Module

Place the BME280 module on the breadboard.

Identify VCC, GND, SDA, and SCL before wiring.

Check the printed pin labels on your module because pin order can vary.

Step 2

Step 3: Connect BME280 Power

Connect BME280 VCC to 3.3V.

Connect BME280 GND to GND.

Step 3

Step 4: Connect BME280 I2C Pins

Connect BME280 SDA to GPIO 8.

Connect BME280 SCL to GPIO 9.

Step 3


Wiring Check

Pico 2W is placed correctly across the breadboard center gap

BME280 VCC connects to 3.3V

BME280 GND connects to GND

BME280 SDA connects to GPIO 8

BME280 SCL connects to GPIO 9

No loose jumper wires


Testing Individual Components

Before running the full project, test each part separately. This makes it easier to find wiring or code problems.

I2C Scanner Test

Check that the BME280 appears on the I2C bus.

from machine import I2C, Pin
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
print([hex(addr) for addr in i2c.scan()])

Expected test result: You should usually see the BME280 address 0x76 or 0x77.

BME280 Sensor Test

Check that the BME280 library works and returns values.

from machine import I2C, Pin
import BME280

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)

try:
    bme = BME280.BME280(i2c=i2c, address=0x76)
except OSError:
    bme = BME280.BME280(i2c=i2c, address=0x77)

print('Temperature:', bme.temperature)
print('Humidity:', bme.humidity)

Expected test result: The Shell should print temperature and humidity values.

BLE Advertising Test

Check that the Pico advertises as a BLE device your phone can see.

import bluetooth
import time
from ble_uart import BLEUART

ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Weather')

print('Scan for Pico-Weather in your BLE app')

while True:
    time.sleep(1)

Expected test result: Your phone BLE app should find a device named Pico-Weather.


Full Project Code

Upload and run this code after the individual tests work correctly.

from machine import I2C, Pin
import bluetooth
import time
from ble_uart import BLEUART
import BME280

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)

try:
    bme = BME280.BME280(i2c=i2c, address=0x76)
except OSError:
    bme = BME280.BME280(i2c=i2c, address=0x77)

ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Weather')


def on_rx(data):
    command = data.decode('utf-8').strip().lower()
    print('Received command:', command)

    if command in ('read', 'status', 'env'):
        uart.write(('Temperature: {}\n'.format(str(bme.temperature))).encode())
        uart.write(('Humidity: {}\n'.format(str(bme.humidity))).encode())
    elif command == 'help':
        uart.write(b'Commands: read, status, env, help\n')
    else:
        uart.write(b'Unknown command. Send help.\n')


uart.on_rx(on_rx)

print('Bluetooth environmental monitor ready')
print('Connect with a BLE app and send read, status, env, or help')

while True:
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
BME280 setup Creates the I2C sensor object and checks common addresses The project needs real environmental data to send by Bluetooth
BLEUART service Creates the Bluetooth link to the phone app This is the communication channel for the readings
Command handling Lets the phone request the latest temperature and humidity The app receives sensor data only when asked
help response Lists the supported commands Beginners can recover quickly if they forget the command names

Expected Result

After running the code, your phone BLE app should find Pico-Weather. Sending read, status, or env should return the latest BME280 temperature and humidity readings.


Troubleshooting

Problem Possible Cause Solution
No BME280 readings Wrong I2C pins or wrong address Use GPIO 8/9 and test 0x76 or 0x77
Phone cannot find Pico-Weather BLE libraries are missing or Bluetooth is not active Check the library files and rerun the advertising test
Only one value appears The app may only show one line at a time depending on the BLE terminal Scroll in the app or resend the command