Project 1.12.7
Bluetooth Motion Alert
Project 1.12.7: Bluetooth Motion Alert
Beginner Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
Build a Bluetooth motion alert that sends a message to your phone when the PIR sensor detects movement.
This project demonstrates event-based Bluetooth messages from a sensor.
The final result should let a phone connect to the Pico and receive a MOTION DETECTED alert when a new movement event happens.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() PIR motion sensor |
![]() Breadboard |
![]() Jumper wires |
![]() Phone with BLE app |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| PIR VCC | 3.3V or module-safe supply | Physical pin 36 | Use 3.3V if your module supports it |
| PIR GND | GND | Physical pin 38 | Common ground |
| PIR OUT | GPIO 1 | GPIO 1 / physical pin 2 | 3.3V logic only |
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 PIR Motion Sensor
Place the PIR motion sensor so the white dome faces the area you want to test.
Identify VCC, OUT, and GND before wiring.
Check the printed pin labels on your PIR module.

Step 3: Connect PIR Power
Connect PIR VCC to 3.3V if your module supports it.
Connect PIR GND to GND.

Step 4: Connect the PIR OUT Pin
Connect PIR OUT to GPIO 1.
The OUT signal going into the Pico must be 3.3V safe.

Wiring Check
-
- Pico 2 W is placed correctly across the breadboard center gap
-
- PIR VCC connects to 3.3V or a module-safe supply
-
- PIR GND connects to GND
-
- PIR OUT connects to GPIO 1
-
- No loose jumper wires
Beginner Note
PIR sensors need a warm-up time after power-on. Wait briefly before testing motion readings.
Safety Note
If your PIR module outputs 5V on OUT, use a level shifter or voltage divider before connecting it to the Pico GPIO pin.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring or code problems.
PIR Motion Test
Check that the PIR sensor detects motion before using Bluetooth alerts.
from machine import Pin
import time
pir = Pin(1, Pin.IN)
print('Wait 15 seconds for PIR warm-up')
time.sleep(15)
while True:
print('Motion' if pir.value() else 'Clear')
time.sleep(0.5)
Expected test result: The Shell should print Motion when movement is detected after the warm-up period.
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-Motion')
print('Scan for Pico-Motion in your BLE app')
while True:
time.sleep(1)
Expected test result: Your phone BLE app should find a device named Pico-Motion.
Full Project Code
Upload and run this code after the individual tests work correctly.
from machine import Pin
import bluetooth
import time
from ble_uart import BLEUART
pir = Pin(1, Pin.IN)
ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Motion')
last_motion = 0
motion_count = 0
def on_rx(data):
command = data.decode('utf-8').strip().lower()
print('Received command:', command)
if command == 'status':
uart.write(('Motion count: {}\n'.format(motion_count)).encode())
elif command == 'help':
uart.write(b'Commands: status, help\n')
else:
uart.write(b'Unknown command. Send help.\n')
uart.on_rx(on_rx)
print('Bluetooth motion alert ready')
print('Wait 15 seconds for PIR warm-up')
time.sleep(15)
print('Connect with a BLE app and wait for alerts or send status')
while True:
motion = pir.value()
if motion == 1 and last_motion == 0:
motion_count += 1
uart.write(b'MOTION DETECTED!\n')
print('Motion detected! Count:', motion_count)
last_motion = motion
time.sleep(0.1)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
| PIR input | Reads whether motion is currently detected | This is the event source for the Bluetooth alert |
| Edge detection | Sends an alert only when motion starts | This prevents one long motion event from repeating constantly |
motion_count |
Stores how many motion events have happened | The phone can request this total later |
| BLE status reply | Lets the phone ask for the current motion count | This adds useful feedback beyond the automatic alert |
Expected Result
After running the code and waiting for PIR warm-up, your phone BLE app should find Pico-Motion. When a new movement event happens, the app should receive a MOTION DETECTED! message. Sending status should return the motion count.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No motion alerts appear | PIR is still warming up or wiring is wrong | Wait longer and recheck the PIR OUT pin on GPIO 1 |
| Too many alerts | One movement is causing repeated triggers | Keep the edge detection code and reduce nearby constant motion |
| Phone cannot find Pico-Motion | BLE libraries are missing or Bluetooth is not active | Check the library files and rerun the advertising test |




