All tutorials

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

  1. 01Add a relay module on pin 7.
  2. 02Declare the pin as OUTPUT.
  3. 03Switch every 3 s and print the state on the serial port.
  4. 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.

Next tutorials