Project 1.12.29
Bluetooth Phone-Controlled LED
Overview
Build a Bluetooth-controlled LED that can be switched from a phone app.
This project demonstrates Bluetooth Low Energy communication between a Pico 2 W and a smartphone.
The final result should let you send commands such as on, off, toggle, and status from a BLE app to control the LED.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() LED |
![]() 220Ω resistor |
![]() Breadboard |
![]() Jumper wires |
![]() Phone with BLE app |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| LED anode (+) | 220Ω resistor then GPIO 0 | GPIO 0 / physical pin 1 | LED long leg |
| LED cathode (-) | GND | Physical pin 38 | LED short leg |
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 2: Place the LED
Place the LED on the breadboard with its two legs in different rows.
The long leg is the anode (+). The short leg is the cathode (-).

Step 3: Add the 220Ω Resistor
Connect the LED long leg to one end of the 220Ω resistor.
The resistor protects the LED and the Pico GPIO pin.

Step 4: Connect the LED to GPIO 0
Connect the free end of the 220Ω resistor to GPIO 0.

Step 5: Connect the LED Short Leg to GND
Connect the LED short leg to GND.
Wiring Check
Pico 2W is placed correctly across the breadboard center gap
LED long leg connects through a 220Ω resistor to GPIO 0
LED short leg connects to GND
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.
LED Test
Check that the LED wiring works before adding Bluetooth code.
from machine import Pin
import time
led = Pin(0, Pin.OUT)
for _ in range(3):
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
Expected test result: The LED should blink three times.
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-LED')
print('Scan for Pico-LED in your BLE app')
while True:
time.sleep(1)
Expected test result: Your phone BLE app should find a device named Pico-LED.
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
led = Pin(0, Pin.OUT)
led.off()
ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-LED')
def on_rx(data):
command = data.decode('utf-8').strip().lower()
print('Received command:', command)
if command in ('1', 'on'):
led.on()
uart.write(b'LED is ON\n')
elif command in ('0', 'off'):
led.off()
uart.write(b'LED is OFF\n')
elif command == 'toggle':
led.value(0 if led.value() else 1)
uart.write(b'LED toggled\n')
elif command == 'status':
state = 'ON' if led.value() else 'OFF'
uart.write(('LED status: ' + state + '\n').encode())
elif command == 'help':
uart.write(b'Commands: on, off, toggle, status, help\n')
else:
uart.write(b'Unknown command. Send help.\n')
uart.on_rx(on_rx)
print('Bluetooth LED controller ready')
print('Connect with a BLE app and send commands: on, off, toggle, status, help')
while True:
time.sleep(0.1)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
| BLEUART setup | Creates a Bluetooth UART-style service named Pico-LED | This lets a phone app send text commands easily |
| LED setup | Creates the LED output on GPIO 0 | The Bluetooth commands need a physical output to control |
| on_rx() callback | Runs whenever the phone sends data | This is where incoming commands are decoded and acted on |
| status and help replies | Send text back to the phone app | Students get feedback that the command worked |
Expected Result
After running the code, your phone BLE app should find Pico-LED. Connecting and sending on should turn the LED on. Sending off should turn it off. Sending toggle should change the state, and status should return the current LED state.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Phone cannot find Pico-LED | BLE libraries are missing or Bluetooth is not active | Check the library files and rerun the advertising test |
| Phone connects but LED does not change | LED wiring or command text is wrong | Run the LED test and send simple commands like on or off |
| Unknown command reply appears | Text sent from the app does not match the supported commands | Send one of: on, off, toggle, status, help |





