How To Connect A Relay To Arduino

Table of contents:

How To Connect A Relay To Arduino
How To Connect A Relay To Arduino

Video: How To Connect A Relay To Arduino

Video: How To Connect A Relay To Arduino
Video: How to use 5V Relay with Arduino to turn ON and OFF AC bulb or DC load 2024, November
Anonim

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.

Relay module SRD-05VDC-SL-C
Relay module SRD-05VDC-SL-C

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.

The principle of operation of the electromagnetic relay
The principle of operation of the electromagnetic relay

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.

External view of the module with the SRD-05VDC-SL-C relay
External view of the module with the SRD-05VDC-SL-C relay

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.

Arduino relay connection diagram
Arduino relay connection diagram

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.

Sketch for controlling the relay module
Sketch for controlling the relay module

Step 5

Now let's load the sketch into Arduino memory. This is how it all looks.

Recommended: