Project 1.12.2
Bluetooth Relay Switch
Overview
Build a Bluetooth-controlled relay switch that can be turned on or off from a phone.
This project demonstrates how BLE control can switch a low-voltage external device through a relay module.
The final result should let your phone turn the relay on or off and receive a text reply showing the relay state.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() 1-channel relay module |
![]() Optional low-voltage test load |
![]() Breadboard |
![]() Jumper wires |
![]() Phone with BLE app |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| Relay VCC | 5V / VSYS | Physical pin 40 | Module power |
| Relay GND | GND | Physical pin 38 | — |
| Relay IN | GPIO 0 | GPIO 0 / physical pin 1 | Usually active-low |
| Optional low-voltage load | Relay output side only | Not a GPIO pin | Use a safe low-voltage test load if desired |
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 Relay Module
Place the 1-channel relay module on the breadboard or beside it where the pins are easy to reach.
Identify VCC, GND, IN, COM, NO, and NC before wiring.
Keep the relay load side separate from the Pico logic side.

Step 3: Connect Relay Power
Connect relay VCC to 5V / VSYS.
Connect relay GND to GND.

Step 4: Connect the Relay IN Pin
Connect relay IN to GPIO 0.
This is the Bluetooth-controlled relay signal.
Step 5: Optional Low-Voltage Load
If you connect a test load, use only a safe low-voltage load.
Wire the load through the relay output side according to the load's power supply.
Do not connect mains AC power in this beginner project.
Wiring Check
Pico 2W is placed correctly across the breadboard center gap
Relay VCC connects to 5V / VSYS
Relay GND connects to GND
Relay IN connects to GPIO 0
Optional load uses only safe low-voltage relay wiring
No loose jumper wires
Safety Note
Do not connect mains AC power. Use an external supply for loads that need more current than the Pico can provide.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring or code problems.
Relay Click Test
Check that the relay changes state before adding Bluetooth code.
from machine import Pin
import time
relay = Pin(0, Pin.OUT)
relay.value(1)
time.sleep(1)
relay.value(0)
time.sleep(1)
relay.value(1)
Expected test result: You should hear the relay click on and 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-Relay')
print('Scan for Pico-Relay in your BLE app')
while True:
time.sleep(1)
Expected test result: Your phone BLE app should find a device named Pico-Relay.
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
relay = Pin(0, Pin.OUT)
relay.value(1)
ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Relay')
def relay_state_text():
return 'ON' if relay.value() == 0 else 'OFF'
def on_rx(data):
command = data.decode('utf-8').strip().lower()
print('Received command:', command)
if command in ('1', 'on'):
relay.value(0)
uart.write(b'Relay ON\n')
elif command in ('0', 'off'):
relay.value(1)
uart.write(b'Relay OFF\n')
elif command == 'toggle':
relay.value(0 if relay.value() else 1)
uart.write(('Relay ' + relay_state_text() + '\n').encode())
elif command == 'status':
uart.write(('Relay status: ' + relay_state_text() + '\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 relay 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 |
|---|---|---|
| Active-low relay setup | Starts the relay in the OFF state | This avoids turning on a load unexpectedly at startup |
| relay_state_text() | Creates a readable ON or OFF message | The phone app receives clear text feedback |
| BLEUART service | Provides a text-based Bluetooth link to the phone | This is the control channel for the relay |
| on_rx() callback | Processes incoming control commands | This is where the relay state changes happen |
Expected Result
After running the code, your phone BLE app should find Pico-Relay. Sending on should turn the relay on. Sending off should turn it off. Sending toggle should switch the state, and status should report the current state.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Relay does not click | Wrong power wiring or active-low logic is misunderstood | Check VCC, GND, and remember many modules turn ON when the input goes low |
| Phone cannot find Pico-Relay | BLE libraries are missing or Bluetooth is not active | Check the library files and rerun the advertising test |
| Relay turns the wrong way | The module logic is different from expected | Test with the relay click test and adjust only if your module behaves differently |





