Learn

Switching a Load with a 5V Single-Channel Relay Module on a Raspberry Pi 4B

Wire a 5V single-channel relay module to a Raspberry Pi 4B, drive its coil from a GPIO pin, and use its dry-contact switched side to control a simulated LED load — two genuinely separate electrical sides on one part, and why the trigger pin is active-LOW, not active-HIGH.

Note: the 5V Single-Channel Relay Module is a VIP-tier component in the simulator — you’ll need a VIP plan to use it there.

Try this directly in the free Raspberry Pi 4B simulator — no hardware or signup required. New to the GPIO header? Start with the interactive pinout guide.

What you’ll need

  • Raspberry Pi 4B
  • 5V Single-Channel Relay Module
  • LED
  • Resistor

Step by step

  1. Drag Raspberry Pi 4B onto the Canvas.
  2. Drag the 5V Single-Channel Relay Module onto the Canvas — it has TWO separate groups of pins on one body, and they never electrically touch each other except through the relay's own coil-driven switch.
  3. Hover its pins to confirm the labels. Bottom edge (the control side, breadboard-pluggable): GND, IN, VCC. Top edge (the switched side, a dry contact — wire it directly, don't try to mount it in a breadboard): NO, COM, NC.
  4. Wire VCC → a Pi 5V pin and GND → a Pi GND pin — this powers the coil, separately from whatever the switched side ends up controlling.
  5. Wire IN → any Pi GPIO pin you'll configure as an output (e.g. physical pin 37).

This relay's real hardware trigger is active-LOW — driving IN LOW energizes the coil, and driving it HIGH (or leaving it unwired) de-energizes it. That's the opposite of a plain LED, and it matches the actual common 5V optocoupler-isolated relay module this component models, not an arbitrary simulator choice.

  1. Now build the load side. Drag an LED and a Resistor onto the Canvas.
  2. Wire the relay's COM pin → a Pi 5V pin (this stands in for the load's own power supply — never real AC/mains; this simulator only ever switches a simulated low-voltage load like this LED, for real safety/legal reasons).
  3. Wire the relay's NO pin → the Resistor → the LED's anode, then the LED's cathode → a Pi GND pin.
  4. Go to the Code tab and write a script that toggles the relay's coil:
import RPi.GPIO as GPIO
import asyncio
 
GPIO.setmode(GPIO.BOARD)
RELAY_IN = 37 # adjust to match your wiring
 
GPIO.setup(RELAY_IN, GPIO.OUT)
 
while True:
GPIO.output(RELAY_IN, GPIO.LOW) # energize — LOW, not HIGH
print("Relay energized — LED should be ON")
await asyncio.sleep(2)
 
GPIO.output(RELAY_IN, GPIO.HIGH) # de-energize
print("Relay de-energized — LED should be OFF")
await asyncio.sleep(2)
  1. Click Start.

What “working correctly” looks like

  • The relay's own small green status LED lights whenever the coil is energized (IN driven LOW), matching a real board's onboard indicator — and its red power LED stays lit the whole time VCC/GND are both correctly wired, regardless of trigger state.
  • The LED you wired through NO lights up in sync with "Relay energized" and goes dark in sync with "Relay de-energized" — the relay's own dry contact is really switching which pin COM connects to, not just reacting to the coil directly.
  • Rewiring the LED's resistor+anode to the relay's NC pin instead of NO flips the behavior exactly: the LED is lit while de-energized and dark while energized — the complementary contact.
  • With IN left unwired entirely, the relay stays permanently de-energized (COM↔NC) — matching real hardware, where a floating trigger pin on this kind of module reads as released, not energized.

If something’s wrong

  • The LED never lights → the most common mistake is driving IN HIGH to energize — this module is active-LOW, so GPIO.output(RELAY_IN, GPIO.LOW) is what energizes the coil, not GPIO.HIGH.
  • The LED stays lit the whole time, never turning off → double-check you wired the load through NO (normally open), not NC (normally closed) — NC is lit while de-energized, the opposite of NO.
  • The relay's own status LED never lights at all → confirm VCC and GND are both wired to real Pi power/ground pins — the coil side needs its own power, completely separate from whatever the switched side is controlling.