Project 1.12.25
Bluetooth Sensor Data Logger
Project 1.12.25: Bluetooth Sensor Data Logger
Beginner Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
Build a Bluetooth sensor data logger that sends numbered BME280 readings to your phone.
This project demonstrates how to count readings and stream them over Bluetooth in a simple logging session.
The final result should let a phone start logging, stop logging, and receive numbered temperature, humidity, and pressure samples.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() BME280 Sensor Module |
![]() Breadboard |
![]() Jumper Wires |
![]() Phone with BLE App |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| BME280 VIN / VCC | 3.3V | Physical Pin 36 | Use 3.3V |
| BME280 GND | GND | Physical Pin 38 | Common ground |
| 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 2 W
Place the Raspberry Pi Pico 2 W 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 2: Place the BME280 Module
Place the BME280 module on the breadboard.
Identify the following pins before wiring:
- VIN / VCC
- GND
- SDA
- SCL
Check the printed pin labels on your module because pin order may vary.

Step 3: Connect BME280 Power
Connect:
- BME280 VIN / VCC -> 3.3V
- BME280 GND -> GND

Step 4: Connect BME280 I2C Pins
Connect:
- BME280 SDA -> GPIO 8
- BME280 SCL -> GPIO 9

Wiring Check
-
- Pico 2 W is placed correctly across the breadboard center gap
-
- BME280 VIN / 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 Pico can detect the BME280 on the I2C bus.
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=100000)
print('I2C devices:', i2c.scan())
Expected Test Result
The Shell should print at least one I2C address, commonly 118 or 119.
BME280 Sensor Test
Check that the weather values can be read before adding Bluetooth code.
from machine import Pin, I2C
import time
import BME280
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=100000)
bme = BME280.BME280(i2c=i2c)
while True:
print(
'Temp:', bme.temperature,
'Humidity:', bme.humidity,
'Pressure:', bme.pressure
)
time.sleep(1)
Expected Test Result
The Shell should print changing temperature, humidity, and pressure 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-Logger')
print('Scan for Pico-Logger in your BLE app')
while True:
time.sleep(1)
Expected Test Result
Your phone BLE app should find a device named Pico-Logger.
Full Project Code
from machine import Pin, I2C
import bluetooth
import time
import BME280
from ble_uart import BLEUART
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=100000)
bme = BME280.BME280(i2c=i2c)
ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Logger')
logging_on = False
sample_count = 0
last_log_time = time.ticks_ms()
log_interval_ms = 2000
def send_one_sample():
global sample_count
sample_count += 1
line = '#{} Temp:{} Hum:{} Press:{}'.format(
sample_count,
bme.temperature,
bme.humidity,
bme.pressure
)
uart.write((line + '\n').encode())
print(line)
def on_rx(data):
global logging_on, sample_count
command = data.decode('utf-8').strip().lower()
if command == 'start':
logging_on = True
uart.write(b'Logging started\n')
elif command == 'stop':
logging_on = False
uart.write(b'Logging stopped\n')
elif command == 'read':
send_one_sample()
elif command == 'reset':
sample_count = 0
uart.write(b'Log counter reset\n')
elif command == 'status':
state = 'ON' if logging_on else 'OFF'
uart.write(
('Logging: {} Count:{}\n'.format(state, sample_count)).encode()
)
elif command == 'help':
uart.write(
b'Commands: start, stop, read, reset, status, help\n'
)
else:
uart.write(b'Unknown command. Send help.\n')
uart.on_rx(on_rx)
print('Bluetooth sensor data logger ready')
print('Send start, stop, read, reset, status, or help')
while True:
if (
logging_on and
time.ticks_diff(time.ticks_ms(), last_log_time) >= log_interval_ms
):
send_one_sample()
last_log_time = time.ticks_ms()
time.sleep(0.1)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
logging_on variable |
Stores whether logging is currently active | The Pico knows when it should send repeated samples |
sample_count |
Numbers each logged reading | Students can see the order of samples |
send_one_sample() |
Builds one data line containing temperature, humidity, and pressure | Keeps the logging format consistent |
| Timed main loop | Sends a new sample every few seconds while logging is active | Creates automatic logging without blocking Bluetooth commands |
Expected Result
After running the code, your BLE app should find Pico-Logger.
Sending:
startstopreadresetstatus
should allow you to control the logging session.
Example Behavior
start-> Begins streaming numbered sensor readings.stop-> Stops logging.read-> Sends one sensor sample immediately.reset-> Resets the sample counter.status-> Shows whether logging is active and how many samples have been sent.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No I2C device found | SDA and SCL are reversed or the BME280 is not powered | Verify GPIO 8, GPIO 9, 3.3V, and GND connections |
No samples appear after start |
Logging is off or the BLE app disconnected | Use status to verify the logger state and keep the BLE connection open |
| Phone cannot find Pico-Logger | BLE helper files are missing or Bluetooth is inactive | Verify ble_uart.py and ble_advertising.py are installed and rerun the BLE advertising test |




