Skip to content

Project 1.12.4

Bluetooth RGB LED Controller

Overview

Build a Bluetooth-controlled RGB LED that changes color when commands are sent from a phone.

This project demonstrates using PWM on three color channels and sending color data wirelessly.

The final result should let the phone set named colors or send red, green, and blue values like 255,0,0.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
RGB LED (common cathode)
RGB LED (common cathode)
220Ω resistors
220Ω resistors
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
RGB red leg GPIO 0 GPIO 0 / physical pin 1 PWM channel
RGB green leg GPIO 1 GPIO 1 / physical pin 2 PWM channel
RGB blue leg GPIO 2 GPIO 2 / physical pin 4 PWM channel
RGB common cathode GND Physical pin 38 Common leg to GND

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 Common Cathode RGB LED

Place the RGB LED on the breadboard with each leg in a different row.

Identify the red, green, blue, and common cathode legs.

This project uses a common cathode RGB LED, so the common leg connects to GND.

Step 2

Step 3: Connect the Red Leg

Connect the R pin to GPIO 0 through a 220Ω resistor.

Step 3

Step 4: Connect the Green Leg

Connect the G pin to GPIO 1 through a 220Ω resistor.

Step 4

Step 5: Connect the Blue Leg

Connect the B pin to GPIO 2 through a 220Ω resistor.

Step 5

Step 6: Connect the Common Cathode

Connect the RGB LED common cathode leg to GND.


Wiring Check

Pico 2W is placed correctly across the breadboard center gap

RGB red leg connects through a 220Ω resistor to GPIO 0

RGB green leg connects through a 220Ω resistor to GPIO 1

RGB blue leg connects through a 220Ω resistor to GPIO 2

RGB common cathode connects to GND

No loose jumper wires


Beginner Note

If your RGB LED is common anode, the wiring and code logic are different. Use a common cathode RGB LED for this project.


Testing Individual Components

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

RGB LED Test

Check that each color channel works before adding Bluetooth control.

from machine import Pin, PWM
import time

red = PWM(Pin(0))
green = PWM(Pin(1))
blue = PWM(Pin(2))

for pwm in (red, green, blue):
    pwm.freq(1000)

for channel in (red, green, blue):
    red.duty_u16(0)
    green.duty_u16(0)
    blue.duty_u16(0)
    channel.duty_u16(65535)
    time.sleep(1)

red.duty_u16(0)
green.duty_u16(0)
blue.duty_u16(0)

Expected test result: The RGB LED should show red, then green, then blue.

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-RGB')

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

while True:
    time.sleep(1)

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


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

red = PWM(Pin(0))
green = PWM(Pin(1))
blue = PWM(Pin(2))

for pwm in (red, green, blue):
    pwm.freq(1000)

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


def set_rgb(r, g, b):
    red.duty_u16(r * 257)
    green.duty_u16(g * 257)
    blue.duty_u16(b * 257)


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

    if command == 'red':
        set_rgb(255, 0, 0)
        uart.write(b'Red set\n')
    elif command == 'green':
        set_rgb(0, 255, 0)
        uart.write(b'Green set\n')
    elif command == 'blue':
        set_rgb(0, 0, 255)
        uart.write(b'Blue set\n')
    elif command == 'white':
        set_rgb(255, 255, 255)
        uart.write(b'White set\n')
    elif command == 'off':
        set_rgb(0, 0, 0)
        uart.write(b'LED off\n')
    else:
        try:
            parts = command.split(',')
            if len(parts) == 3:
                r = max(0, min(255, int(parts[0])))
                g = max(0, min(255, int(parts[1])))
                b = max(0, min(255, int(parts[2])))
                set_rgb(r, g, b)
                uart.write(b'Custom color set\n')
            else:
                uart.write(b'Send red, green, blue, white, off, or R,G,B\n')
        except ValueError:
            uart.write(b'Send red, green, blue, white, off, or R,G,B\n')


uart.on_rx(on_rx)
set_rgb(0, 0, 0)

print('Bluetooth RGB controller ready')
print('Send red, green, blue, white, off, or values like 255,0,0')

while True:
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
PWM RGB setup Creates three PWM channels for red, green, and blue An RGB LED needs separate control for each color
set_rgb() Converts 0-255 color values into PWM duty values This makes color commands easier to understand
Named color commands Support quick commands like red, green, blue, white, and off These are easy for beginners to test
Custom R,G,B input Lets the phone send exact color values such as 255,0,0 Students can experiment with color mixing

Expected Result

After running the code, your phone BLE app should find Pico-RGB. Sending red, green, blue, white, or off should change the LED color. Sending values like 255,0,0 should also set a custom color.


Troubleshooting

Problem Possible Cause Solution
Wrong color appears RGB legs are wired to different pins or the LED type is different Recheck the leg order and confirm the LED is common cathode
Custom color command fails The phone did not send the values in R,G,B format Send values like 255,0,0 with commas and no extra words
One color is missing That resistor or color leg is not connected correctly Test each color again with the RGB LED test code