4 Leds Example

4 Leds Example

This example shows you how to pilot the switch on of 4 Leds by 4 Relays Shield. 
In this example are used 4 Leds to demonstrate the operation of the 4 Relays Shield but you can connect to relays other types of loads and create your personalized sketch.


  • Arduino board
  • Arduino 4 Relays Shield
  • 4 Leds
  • 4 Resistor 220Ω
  • Wires


Mount your 4 Relays Shield on an Arduino board, connect the "Common" contacts (C) of the Relays to power pin "5V" of the Shield. 
Connect all anodes of the Leds (usually the longer pin) in series to a resistor of 220Ω and connect them to "Normally Open" contact (NO) of the Relays. 
Also connect the cathodes of the Leds to Ground (GND) of the Shield. 
Finally connect the board to PC with a USB cable and upload the sketch. 
Now you can pilot each single Led by the relay that it has been connected.


This sketch pilots 4 Leds. 
First it switches on the led1 connected to relay1, after one second it turn on the led2 connected to relay2, exceeded another second it turns on the led3 connected to relay3 and finally, passed one second, it switches on the led4 that it is connected to relay4. 
When all Leds have been turned on it waits one second and it turns off a led each second, starting from led4 untill to led1. 
The relay1 is piloted from pin 4, the relay2 from pin7, the relay3 from 8 and the relay4 from pin 12. 
The commutation is commanded by "digitalWrite()" function. 
When the relays are set as LOW, the "Common" (C) contact is connected to "Normally Closed" (NC) contact. 
Instead when the relays are set as HIGH, the "Common" (C) contact switches and connects to "Normally Open" (NO) contact.

Here you can download the Schematic of 4-Relays Shield.

The complete code and its detailed description are shown down.

/*4-Relays Shield Example*/
//define variable
int RELAY1 = 4;                      
int RELAY2 = 7;
int RELAY3 = 8;
int RELAY4 = 12;
void setup()
//set Relays as Output
pinMode(RELAY1, OUTPUT);  
pinMode(RELAY2, OUTPUT);  
pinMode(RELAY3, OUTPUT);  
pinMode(RELAY4, OUTPUT);  
void loop()
  digitalWrite(RELAY1,HIGH); // Turns ON Led1
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY2,HIGH); // Turns ON Led2
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY3,HIGH); // Turns ON Led3
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY4,HIGH); // Turns ON Led4
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY4,LOW); // Turns OFF Led4
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY3,LOW); // Turns OFF Led3
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY2,LOW); // Turns OFF Led2
  delay(1000);               // Wait 1 seconds
  digitalWrite(RELAY1,LOW); // Turns OFF Led1
  delay(1000);               // Wait 1 seconds