3 · Outputs & actuators
Relay and mains load
Intermediate15 min
Goal
Switch a power load safely from a pin.
Why it matters
The relay galvanically isolates the control side from the power side.
Steps
- 01Add a relay module on pin 7.
- 02Declare the pin as OUTPUT.
- 03Switch every 3 s and print the state on the serial port.
- 04Note that a flyback diode protects the driving transistor.
This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.