Skip to content

Project 1.5.4: IR Remote Relay Controller

Beginner Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython

Pico 2 W Diagram

Pico 2 W Pinout


Overview

Build a relay control project that responds to an infrared remote control.

This project demonstrates wireless relay control using an IR receiver and a remote.

The final result should toggle the relay when the chosen remote button is pressed.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
IR receiver module
IR receiver module
1-channel relay module
1-channel relay module
Breadboard
Breadboard
Jumper wires
Jumper wires
IR remote control
IR remote control

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
IR receiver VCC 3.3V Physical pin 36 Check module pin order
IR receiver GND GND Physical pin 38
IR receiver OUT GPIO 1 GPIO 1 / physical pin 2 Signal pin
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

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2 W

Place the Raspberry Pi Pico 2 W 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 IR Receiver and Relay Module

Place the IR receiver module on the breadboard with the receiver window facing outward.

Place the 1-channel relay module on the breadboard or beside it where the pins are easy to reach.

Identify IR receiver VCC, GND, and OUT.

Identify relay VCC, GND, IN, COM, NO, and NC before wiring any load-side connections.

Check the printed pin labels because IR receiver modules often use different pin orders.

Step 2


Step 3: Connect the IR Receiver

Connect IR receiver VCC to 3.3V.

Connect IR receiver GND to GND.

Connect IR receiver OUT to GPIO 1.

Step 3


Step 4: Connect Relay Power

Connect relay VCC to 5V / VSYS.

Connect relay GND to GND.

Step 4


Step 5: Connect the Relay IN Pin

Connect relay IN to GPIO 0.

This pin switches the relay when the remote command is received.

Step 5


Wiring Check

Before running the code, confirm:

  • Pico 2 W is placed correctly across the breadboard center gap.
  • IR receiver VCC connects to 3.3V.
  • IR receiver GND connects to GND.
  • IR receiver OUT connects to GPIO 1.
  • Relay VCC connects to 5V / VSYS.
  • Relay GND connects to GND.
  • Relay IN connects to GPIO 0.
  • No loose jumper wires.

!!! note "Beginner Note"

Point the remote control at the IR receiver during testing. Bright light or poor aim can make IR signals harder to receive.

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 the relay before using the remote control 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.

IR Code Reader Test

Find the button code from your own remote.

from machine import Pin
from ir_rx.nec import NEC_8
import time

def callback(data, addr, ctrl):
    if data >= 0:
        print('Code:', hex(data), 'Address:', hex(addr))

ir = NEC_8(Pin(1, Pin.IN), callback)
print('Press remote buttons now')

while True:
    time.sleep(0.2)

Expected test result: The Shell should print a code when you press a remote button.


Full Project Code

After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below into a new file, or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.

from machine import Pin
from ir_rx.nec import NEC_8
import time

relay = Pin(0, Pin.OUT)
relay.value(1)

TOGGLE_CODE = 0x45

def callback(data, addr, ctrl):
    if data < 0:
        return

    print('Received:', hex(data))

    if data == TOGGLE_CODE:
        relay.value(0 if relay.value() else 1)
        print('Relay ON' if relay.value() == 0 else 'Relay OFF')

ir = NEC_8(Pin(1, Pin.IN), callback)
print('IR relay control ready')
print('Replace TOGGLE_CODE with your own remote code if needed')

while True:
    time.sleep(0.2)

How the Code Works

Code Section What It Does Why It Matters
IR library import Loads the NEC IR receiver support The project needs a decoder for remote signals
TOGGLE_CODE Stores the selected remote button code Students can replace this with their own remote code
callback() Runs when an IR command is received This is where the relay is toggled
Relay toggle Changes between ON and OFF states Lets one remote button control the relay

Expected Result

Pressing the chosen remote button should toggle the relay on and off. The Shell should print the received code and the relay state.


Troubleshooting

Problem Possible Cause Solution
No remote codes appear Wrong IR receiver wiring or missing library files Check the module pin order and the ir_rx folder
Codes appear but relay does not toggle TOGGLE_CODE does not match your remote button Read your remote codes and update TOGGLE_CODE
Relay toggles the wrong way Active-low relay logic Use the printed relay state and adjust only if needed