A microcontroller like an Arduino or ESP32 outputs a signal at 3.3V or 5V, nowhere near enough voltage or current to directly drive most motors, household lamps, or anything running on mains AC power. A relay module is the standard bridge: a small electromagnetic switch that lets your low-voltage logic turn a completely separate, much higher-power circuit on and off, without the two circuits ever touching electrically.
How a relay actually works
Inside the module, a small electromagnet (the relay’s coil) is energized by the microcontroller’s output signal. When energized, the electromagnet physically pulls a switch contact closed, completing the separate high-power circuit. Cut the signal, and a spring pulls the contact back open. That physical separation between the control side and the switched side is the whole point: your Arduino’s fragile low-voltage pins never carry the current actually driving the load.
NO, NC, and COM
Every relay module terminal block exposes three screw terminals for the switched side: COM (common), NO (normally open), and NC (normally closed). Wire your load between COM and NO if you want it off by default and on when the relay energizes, the far more common setup for a lamp, motor, or any kinetic sculpture element you want inactive until triggered. Wire between COM and NC if you want the opposite, a circuit that’s on by default and switches off when triggered.
Active-high or active-low
Before wiring anything, check whether your specific module is active-high (a HIGH signal on the IN pin energizes the relay) or active-low (a LOW signal energizes it). Many common breakout boards are active-low because of how their onboard optocoupler and transistor driver stage are wired, which catches beginners expecting digitalWrite(relayPin, HIGH) to turn the load on. Check your specific module’s datasheet or test it with a simple blink sketch before wiring up a real load.
A minimal Arduino sketch
const int relayPin = 7;
void setup() {
pinMode(relayPin, OUTPUT);
}
void loop() {
digitalWrite(relayPin, HIGH); // energize (check active-high vs active-low on your module)
delay(1000);
digitalWrite(relayPin, LOW);
delay(1000);
}
On an ESP32, the same logic works with any available GPIO, and the module’s onboard optocoupler isolates the ESP32’s 3.3V logic from the relay coil, guarding against voltage spikes feeding back into the microcontroller.
Safety, especially around mains power
If you’re switching anything connected to household AC, the stakes change completely. Always disconnect power before changing any wiring on the high-voltage side, never touch exposed AC terminals while energized, and test your relay’s logic-side wiring with a low-voltage load (an LED, a small DC motor) before ever connecting anything to mains power. Check the relay’s actual voltage and current rating with real margin, a relay rated right at your load’s voltage is a relay rated too close for comfort, and add a flyback diode across any driven coil if you’re switching the relay directly from a transistor rather than using a pre-built module with its own protection circuitry already on board.