How to wire a relay module to a Raspberry Pi Pico
To wire a relay module to a Raspberry Pi Pico, connect VCC to VBUS (5 V from USB), GND to GND and IN to GP15 (physical pin 20). The coil runs from the 5 V pin while IN comes from a 3.3 V pin; most single-channel modules switch fine from 3.3 V, but some need closer to 5 V. The sketch below uses no library beyond what the board includes. It switches the relay on for a second and off for a second, printing a line each time.
- 3.3 V logic
- Library: none
- 3 wires
Relay module to Raspberry Pi Pico wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| Relay module pin | Raspberry Pi Pico pin | Wire color | Why |
|---|---|---|---|
| VCC | VBUS (5 V from USB) | red | The coil is a 5 V coil; it takes about 70 mA, more than any pin can give. |
| GND | GND | blue | Common ground. |
| IN | GP15 (physical pin 20) | amber | A logic signal only: the module’s transistor switches the coil. |
| COM, NO, NC | The load | n/a | The switched side: COM is the arm, NO is open until the relay pulls in, NC is closed until then. |
Power and logic levels for relay module and Raspberry Pi Pico
Logic level
The Raspberry Pi Pico’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.
Supply
The relay module takes 5 V from VBUS (5 V from USB). That is the Raspberry Pi Pico’s 5 V rail, so the part shares the current the board can supply.
This pair
The coil runs from VBUS (5 V from USB) and IN comes from a 3.3 V pin. Most single-channel modules switch fine from 3.3 V; some optocoupler modules with a high-side jumper need closer to 5 V, and then a small transistor or a 3.3 V relay module solves it. The simulated relay is set to trigger on HIGH.
Pins to leave alone
The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.
The working code for the Raspberry Pi Pico
Library: none, the sketch drives IN with digitalWrite(). This is the sketch the circuit above runs.
const int RELAY_PIN = 15; // IN, GP15 (physical pin 20)
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // released at start
}
void loop() {
digitalWrite(RELAY_PIN, HIGH); // pull in: COM to NO
Serial.println("Relay on");
delay(1000);
digitalWrite(RELAY_PIN, LOW); // release: COM back to NC
Serial.println("Relay off");
delay(1000);
}
What you should see
The relay clicks closed and open. The serial monitor, at 115200 baud, prints Relay on when the coil is energized and Relay off when it is released.
The switched side, COM, NO and NC, is isolated from the board: wire the load there, never to the board’s pins.
The serial monitor prints this, recorded from the circuit above running for two and a half seconds:
Relay on
Relay off
Relay onCommon mistakes wiring a relay module to a Raspberry Pi Pico
Active low modules
Many cheap relay boards switch when IN goes LOW, so the sketch seems inverted and the relay is on at boot. Check the board, and in the editor set the relay’s trigger property to low to match.
Driving a coil straight from a pin
A bare relay coil wants 70 mA or more and kicks back a voltage spike when it releases. On a module the transistor and the flyback diode are already there; a bare relay needs both, and never a direct pin.
Switching mains without care
The contacts are rated for mains, but the board and the screw terminals are not a safe enclosure. Learn on a 12 V lamp or a motor, and leave mains to a properly rated, enclosed module.
Build your own relay module project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.