Relays

A relay is an electrically operated switch that can be turned on or off, letting the current go through or not, and can be controlled with low voltages, like the 5V provided by the Arduino pins.

The illustration shows how a relay works:

Relay Operation

The relay module shown above has two channels (the blue cubes). Modules with one, four, and eight channels are also available. This module is powered with 5V, which makes it appropriate to use with an Arduino. You can also get relay modules powered with 3.3V, which is ideal for an ESP32.

Each channel has a high voltage side connected to the electrical appliance the relay is controlling and a low voltage side connected to the microcontroller controlling the relay.

The high-voltage side of each channel has three sockets/pins:

  • COM: Common pin to which you connect the neutral wire (in any electrical circuit there are two wires one the carries the electric current known as the live wire and the other is the neutral wire) to the electrical appliance.

  • NC (Normally Closed): the normally closed configuration is used when you want the relay to be closed by default, meaning the current is flowing (and the connected appliance is powered on) until you send a signal from the microcontroller to the relay module to open the circuit and stop the current (and switch off the connected appliance).

  • NO (Normally Open): This configuration works the other way around from NC. The relay is always open, so the circuit is broken (and the connected device is powered off) until you send a signal from the microcontroller to close the circuit (and switch on the connected device).

The low-voltage side of each channel has the VCC and GND pins to power up the module and a third pin which is the input pin to send the control signal for each channel (IN1 and IN2 in this module).

The module has a jumper cap connecting the VCC and JD-VCC pins. The jumper cap allows you to choose whether the circuit is physically connected to the Arduino circuit or not. With the jumper cap on, the VCC and JD-VCC pins are connected. That means the relay electromagnet is directly powered from the Arduino’s power pin, so the relay module and the Arduino circuits are not physically isolated from each other. Without the jumper cap, you need to provide an independent power source to power up the relay’s electromagnet through the JD-VCC pin. This configuration physically isolates the relays from the Arduino with the module’s built-in optocoupler.

Relay Module Pins