A relay is used to switch high voltage applications using a lower voltage. This is often used in houses as well since it’s a safe option to switch on and off high voltages.
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.
Controlling a relay module with the Arduino is as simple as controlling any other output as we’ll see later on.
The following figure shows the relay module pinout.
The six pins on the left side of the relay module connect high voltage, and the pins on the right side connect the component that requires low voltage—the Arduino pins.
Code:- You apply a small voltage (5V) to one side of the relay and it will switch the other side on or off.
// 5V relay module
int relay = 10; // relay turns trigger signal – active high;
void setup ()
pinMode (relay, OUTPUT); // Define port attribute is output;
void loop ()
digitalWrite (relay, HIGH); // relay conduction;
digitalWrite (relay, LOW); // relay switch is turned off;