The article describes an electronic device such as a relay, explains how it works, and also discusses connecting a module with a two-channel DC switching relay to an Arduino using the example of controlling LEDs.
Necessary
- - Module with relay;
- - Arduino;
- - 4 LEDs of different colors;
- - 4 resistors with a resistance of 220 Ohm;
- - a computer with the Arduino IDE development environment;
- - connecting wires.
Instructions
Step 1
In the most general case, 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. According to the classification, the relays are closing and opening, switching, single-channel, multichannel, DC or AC relays, and many others.
Step 2
We will use a module with two identical relays, type SRD-05VDC-SL-C. This type of relay has three contacts for connecting the load: two extreme fixed ones, and the middle one is switching. It is the middle contact that is a kind of "key" that commutes the circuits in one way or another.
Step 3
This module can be powered from the Arduino board with a voltage of 5 V, and each channel is controlled independently.
By applying voltage to the control contacts, we force the relay to switch. To demonstrate and better understand this, let's put together a circuit as shown in the figure.
Step 4
Let's write such a sketch. We will alternately light up a pair of LEDs of the same color, and every second switch to a pair of a different color.
Step 5
Now let's load the sketch into Arduino memory. This is how it all looks.