Project Overview
Pico W + 2-Channel Relay Module: In this project, you will wire a 2-channel relay module to a Raspberry Pi Pico W and control two separate devices (Relay 1 and Relay 2) using MicroPython. This is a clean foundation for switching lights, pumps, fans, solenoids, or any simple on/off load while keeping your Pico W logic safe.
- Time: 10 to 20 minutes
- Skill level: Beginner
- What you will build: A Pico W controller that toggles Relay 1 and Relay 2 reliably, plus helper functions you can reuse for WiFi control later
Parts List
From ShillehTek
- ShillehTek 2-Channel 5V Relay Module - dual relay board for Arduino and Raspberry Pi
External
- Raspberry Pi Pico W
- Jumper wires
- USB cable for Pico W
- Recommended: separate 5V power supply for the relay module (best reliability)
Note: Pico W GPIO is 3.3V logic, while many 2-channel relay boards are powered from 5V. Power the relay board from 5V and always share ground between the Pico W and relay module.
Step-by-Step Guide
Step 1 - Identify your relay pins and operating behavior
Goal: Confirm the control pins and avoid common first-power issues.
What to do: Find the control header labels on your 2-channel relay module. Most boards use the following:
- VCC: relay board power (often 5V)
- GND: ground
- IN1: control pin for Relay 1
- IN2: control pin for Relay 2
Many relay modules are active LOW, meaning the relay turns ON when IN is pulled LOW. If your relay behavior seems backwards later, that is normal for active LOW boards.
If your board also has JD-VCC, it is the opto-isolated style. This guide covers the common VCC/GND/IN1/IN2 style.
Expected result: You know which pins are VCC, GND, IN1, and IN2, and you understand that active LOW behavior is common.
Step 2 - Wire the Pico W to the relay module (control side)
Goal: Make the exact connections needed for reliable relay triggering.
What to do: Wire the control header using these connections:
- Relay VCC to 5V (best: external 5V supply, or Pico VBUS if the Pico is powered by USB)
- Relay GND to Pico GND (shared ground)
- Relay IN1 to Pico GP15
- Relay IN2 to Pico GP14
Tip: If your relay clicks once at boot or acts weird, that can be a boot-state effect. The code in the next step sets both relays OFF at startup.
Expected result: The relay module has 5V power, the Pico W and relay share ground, and IN1/IN2 are connected to GP15/GP14.
Step 3 - Upload the MicroPython test code (2 relays)
Goal: Run a simple loop that cycles Relay 1 and Relay 2 so you can verify wiring fast.
What to do: In Thonny, upload the following as main.py on your Pico W.
Code:
from machine import Pin
import time
# Pico W pins:
# GP15 -> IN1
# GP14 -> IN2
RELAY1_GPIO = 15
RELAY2_GPIO = 14
relay1 = Pin(RELAY1_GPIO, Pin.OUT)
relay2 = Pin(RELAY2_GPIO, Pin.OUT)
# Many relay modules are ACTIVE LOW:
# 0 = ON, 1 = OFF
ACTIVE_LOW = True
def relay_on(relay: Pin):
relay.value(0 if ACTIVE_LOW else 1)
def relay_off(relay: Pin):
relay.value(1 if ACTIVE_LOW else 0)
# Safe startup: both OFF
relay_off(relay1)
relay_off(relay2)
while True:
# Relay 1 ON, Relay 2 OFF
relay_on(relay1)
relay_off(relay2)
time.sleep(1)
# Relay 1 OFF, Relay 2 ON
relay_off(relay1)
relay_on(relay2)
time.sleep(1)
# Both ON
relay_on(relay1)
relay_on(relay2)
time.sleep(1)
# Both OFF
relay_off(relay1)
relay_off(relay2)
time.sleep(1)
If your relay turns ON when you expect OFF, change ACTIVE_LOW = True to ACTIVE_LOW = False.
Expected result: Relay 1 and Relay 2 alternate on a 1-second pattern (you should hear clicks and/or see CH1/CH2 LEDs change).
Step 4 - Verify operation with a quick checklist
Goal: Confirm both channels work and your power setup is stable.
What to do: Use this checklist while the code runs:
- You should hear a click or see LED changes on CH1 and CH2.
- If nothing clicks: confirm relay VCC is 5V and GND is shared.
- If only one channel works: swap IN1 and IN2 wires to see if the problem follows the wire or stays on the same relay channel.
- If the Pico randomly resets: you likely need a better 5V supply for the relay board and cleaner wiring (shared ground still required).
Expected result: Both relays switch reliably without Pico W resets.
Step 5 - Connect your load using COM, NO, and NC (safety first)
Goal: Wire your device to the relay terminals correctly and safely.
What to do: Each relay channel has three screw terminals:
- COM (common)
- NO (normally open): OFF by default, closes when the relay turns ON
- NC (normally closed): ON by default, opens when the relay turns ON
Most projects use NO so the device is OFF unless your code turns it on.
Relays can switch higher voltage loads (including AC mains), but mains wiring can be dangerous. If you are not experienced, stick to low-voltage DC loads for testing. For any AC project, use a proper enclosure, strain relief, correct wire gauge, and a fuse where appropriate.
Expected result: Your load is connected to COM/NO (or COM/NC if needed) and switches when the relay toggles.
Conclusion
You now have a Raspberry Pi Pico W controlling a 2-channel relay module with MicroPython, including a simple test loop and an active LOW option for common relay boards. With the same wiring and helper functions, you can later swap the loop for WiFi control, a button input, or timer logic.
Want the exact parts used in this build? Get the ShillehTek 2-Channel 5V Relay Module and more at ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.