Project 1.12.3
Bluetooth LED Brightness Controller
Overview
Build a Bluetooth-controlled LED brightness controller using PWM and direct GPIO output.
This project demonstrates using a phone to send brightness values to an LED controller.
The final result should let you send a brightness percentage from a BLE app and have the LED brightness change in response.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() LED |
![]() 220 ohm resistor |
![]() Breadboard |
![]() Jumper wires |
![]() Phone with BLE app |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| GPIO 0 | 220 ohm resistor then LED positive leg | GPIO 0 / physical pin 1 | PWM brightness signal |
| LED negative leg | GND | Physical pin 38 | Completes the LED circuit |
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 and Resistor
Place the LED on the breadboard.
Identify the LED positive leg and negative leg before wiring.
Place the 220 ohm resistor in series with the LED.
Keep the LED circuit powered only from the Pico GPIO and GND pins.

Step 3: Connect GPIO 0 to the Resistor
Connect GPIO 0 to one end of the 220 ohm resistor.
Connect the other end of the resistor to the LED positive leg.

Step 4: Connect the LED to GND
Connect the LED negative leg to GND.
Step 5: Check the LED Polarity
Make sure the LED positive leg receives the GPIO signal through the resistor.
Step 6: Check the Bluetooth Helper Files
Confirm ble_uart.py is saved on the Pico root folder.
Confirm ble_advertising.py is saved on the Pico root folder.
Step 7: Check the BLE App
Install or open nRF Connect or LightBlue on your phone.
Prepare to scan for the Pico-LED device after the code runs.
Step 8: Check Before Powering
Make sure the LED has a resistor in series and no bare wires are touching.
Wiring Check
Pico 2W is placed correctly across the breadboard center gap
GPIO 0 connects through a 220 ohm resistor to the LED positive leg
LED negative leg connects to GND
LED positive leg connects through the resistor
BLE helper files are saved on the Pico
Phone BLE app is ready to scan
LED positive leg receives GPIO 0 through the resistor
LED negative leg connects to GND
No loose jumper wires
Safety Note
Do not connect an LED directly to a GPIO pin without a resistor. Keep the circuit on the Pico 3.3V logic side and disconnect USB before changing wires.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring or code problems.
PWM LED Brightness Test
Check that the LED can show different brightness levels before adding Bluetooth control.
from machine import Pin, PWM
import time
led = PWM(Pin(0))
led.freq(1000)
for duty in (0, 15000, 30000, 50000, 65535, 0):
led.duty_u16(duty)
time.sleep(1)
Expected test result: The LED should change brightness at different PWM levels and then turn off.
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, PWM
import bluetooth
import time
from ble_uart import BLEUART
led = PWM(Pin(0))
led.freq(1000)
current_brightness = 0
ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-LED')
def set_brightness(percent):
global current_brightness
percent = max(0, min(100, percent))
current_brightness = percent
duty = int((percent / 100) * 65535)
led.duty_u16(duty)
def on_rx(data):
command = data.decode('utf-8').strip().lower()
print('Received command:', command)
if command in ('off', 'stop'):
set_brightness(0)
uart.write(b'LED off\n')
elif command == 'status':
uart.write(('Brightness: {}%\n'.format(current_brightness)).encode())
else:
try:
value = int(command)
set_brightness(value)
uart.write(('Brightness set to {}%\n'.format(current_brightness)).encode())
except ValueError:
uart.write(b'Send 0-100, stop, off, or status\n')
uart.on_rx(on_rx)
set_brightness(0)
print('Bluetooth LED brightness controller ready')
print('Connect with a BLE app and send a brightness from 0 to 100')
while True:
time.sleep(0.1)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
| PWM LED setup | Creates a PWM output on GPIO 0 | PWM changes the average power going to the LED |
| set_brightness() | Converts a percentage into a PWM duty value | Students can think in easy 0-100% brightness steps |
| Numeric Bluetooth command | Reads a number from the phone and uses it as brightness percent | This is the core remote brightness-control feature |
| Status reply | Sends the current brightness back to the phone app | The user can confirm what brightness is active |
Expected Result
After running the code, your phone BLE app should find Pico-LED. Sending a value such as 0, 25, 50, 75, or 100 should change the LED brightness. Sending stop or off should turn the LED off.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| LED does not turn on | LED polarity is reversed or the resistor path is open | Flip the LED direction and recheck the GPIO 0 resistor connection |
| LED always stays off or bright | PWM value is not changing or the LED is connected to the wrong pin | Rerun the PWM LED test and confirm GPIO 0 is used |
| Phone commands do nothing | The app is sending text that is not a number or supported command | Send simple values like 25 or commands like stop |





