⚡️ How to connect the relay to Arduino

The article describes such an electronic device as a relay, briefly explains the principles of its operation, and also discusses the connection of a module with a DC relay to an Arduino using the example of LED control.

The article describes such an electronic device as a relay, briefly explains the principles of its operation, and also discusses the connection of a module with a DC relay to an Arduino using the example of LED control.

We will need:

  • Arduino UNO (or compatible fee);
  • a module with a relay (for example, such);
  • 4 220 Ohm resistors (I recommend to purchase a set of resistors with nominal values from 10 Ohm to 1 MΩ);
  • 4 LEDs (for example, from this set);
  • breadboard;
  • connecting wires (such).

The principle of operation and types of relays

A relay is an electromechanical device for closing and opening an electrical circuit. In the classic version, the relay contains an electromagnet that controls the opening or closing of contacts. If, in the normal position, the relay contacts are open, and when the control voltage is applied, they close, this relay is called closing. If in the normal state, the relay contacts are closed, and when the control voltage is applied, they open, this type of relay is called open.

In addition, there are many other types of relays: switching, single-channel, multichannel, DC or AC relays, and others.

Schema of connection of the module of the relay SRD-05VDC-SL-C

We will use a module with two identical relays of type SRD-05VDC-SL-C or similar.

The module has 4 connectors: power connectors K1 and K2, a control connector and a connector for external power supply (with a jumper).

Relay type SRD-05VDC-SL-C has three contacts for connecting the load: two extreme stationary, and the middle – switching. It is the middle contact that is a kind of “key” that commutes the chains in one way or another. There is a hint on the module which relay contact is normally closed: the marking “K1” and “K2” connects the middle contact with the leftmost contact (in the photo). Applying a control voltage to the input IN1 or IN2 (low-current control connector) will cause the relay to switch the middle contact of the contact group K1 or K2 to the right (power connector). The current sufficient to switch the relay is about 20 mA, Arduino digital outputs can output up to 40 mA.

Connector for external power supply is used to provide galvanic isolation of the Arduino board and the relay module. By default, there is a jumper on the connector between the JD-VCC and VCC pins. When installed, the module uses the voltage supplied to the VCC pin of the control connector, and the Arduino board is not electrically isolated from the module. If you need to provide galvanic isolation of the module and the Arduino, you must apply power to the module through the external power connector. To do this, remove the jumper, and additional power is supplied to the contacts JD-VCC and GND. In this case, the power to the VCC output of the control connector is also supplied (from +5 V to the Arduino).

By the way, the relay can switch not only a low-current load, as in our example. With the help of the relay, you can close and open large enough loads. What exactly – you need to look in the technical description for a particular relay. For example, this SRD-05VDC-SL-C relay can switch networks with currents up to 10 A and voltages up to 250 V AC or 30 V DC. That is, it can be used, for example, to control the lighting of an apartment.

In this example, we do not need the isolation of the Arduino and the relay module, so we will power the module directly from the Arduino board, and leave the jumper in its place. We assemble the scheme, as shown in the figure. The resistors used are 220 Ohms, any LEDs.

Relay Control Sketch using Arduino

Let us alternately light up a pair of LEDs of the same color, and every second switch to a pair of a different color. Let’s write this sketch.

const int relay1 = 2; 
const int relay2 = 3; 

const int led1 = 4;  
const int led2 = 5;

void setup() {
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(led1, HIGH);  
  digitalWrite(led2, HIGH);

void loop() {
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);

Now load the sketch into the Arduino memory. This is what it looks like with me. The relays click loudly once a second, and the LEDs blink merrily.

By the way, there are other types of switching devices, for example, optocouplers. These devices do not have mechanical parts, which significantly increases their durability and response speed. In addition, they have a smaller size and lower power consumption.

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest