< img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=5580415518647572&ev=PageView&noscript=1" />

How to Use a Relay Module with Arduino

Using a 4 channel 5V relay module with Arduino
Using a 4 channel 5V relay module with Arduino
Resource: https://youtu.be/B3m34lr4vbo

Using a relay module with Arduino microcontrollers is a simple and easy way to control a variety of devices and components. In this relay module Arduino tutorial, you’ll learn, in a step-by-step process, how to use a relay module with this type of microcontroller. But first, about the module and what it means to use it with an Arduino.

What Is Relay Module Arduino?

A relay module is an electronic device that uses electromagnetism to mechanically operate a switch. It’s basically an electromagnetic switch that can be activated by an electrical current. In other words, it’s a way to control one circuit by using another circuit.

A relay module Arduino circuit involves pairing an Arduino microcontroller with a relay. The microcontroller activates the relay, which in turn can be used to activate or deactivate a device or component.

The Arduino connects to and supplies the relay module input voltage, enabling it to turn a higher voltage load on and off. This makes it useful for controlling devices that require higher voltages, such as lamps and motors.

Using relay module with Arduino
Using relay module with Arduino
Resource: https://youtu.be/BQOji4i4PEc

Using Relay Module with Arduino

Using a relay module with Arduino offers many benefits. First, it allows Arduinos to control devices that require a higher voltage or current than what the microcontroller can provide. Second, it protects the Arduino from damage by the device or component being controlled.

An Arduino also cannot produce enough power to directly control a motor or high-voltage load. By using a relay module, Arduino microcontrollers can operate these devices indirectly.

Additionally, a relay module can be used to control multiple devices or components with just one Arduino board. That allows users to manage an array of devices with ease and from a single location.

4 relay module Arduino connection
4 relay module Arduino connection
Resource: https://youtu.be/VsDzZ3oBZ_s

How to Use a Relay Module with Arduino

Using relay module with Arduino microcontrollers is a straightforward process. It also only requires a few components that are usually readily available. In this section, we’ll go over the steps needed to set up and use a relay module with Arduino microcontrollers.

Before we get started, you’ll need to gather a few supplies. In addition to an Arduino microcontroller, you’ll need a relay module, some jumper wires, and a device or component to control such as light.

  • In our Arduino and relay module project, we will use the one-channel configuration. Note that multiple relay configurations are also possible.
  • Other option includes using a 4-relay module Arduino, 8-relay module Arduino and even up to 16 relays.
Relay module Arduino schematic diagram
Relay module Arduino schematic diagram
Resource: https://forum.arduino.cc

Relay Module Arduino Connection

Caution! If using mains electricity or any other high-voltage source, take appropriate precautions. The high voltage can be dangerous, even fatal.

1. Begin by connecting the ground (GND) pin on the Arduino to the ground pin on the module. Then, connect the power (5V) pin on the Arduino to the VCC pin on the module.

2. Next, connect the signal (S) pin on the Arduino to the IN1 pin on the module. You can use a different input pin on the module if you’d like, but for this example, we’ll be using IN1.

3. Finally, connect the device or component you wish to control using the Arduino with relay module. In our example, we’ll be controlling a light, so we’ll connect one end to the COM terminal and the other to the NO (Normally Open) or NC (Normally closed) terminal.

Use the NO terminal if you want the light to only turn on when the relay is activated. Use the NC terminal if you want the light to turn off when the relay is activated.

Relay Module Arduino Code

Now that your hardware is all set up, it’s time to write the code that will tell the Arduino what to do, or the relay module Arduino code.

The Arduino code for relay module operation contains the basic functions to control a relay. In our case, we’ll want the light to turn on for 2 seconds and turn off for another 2 seconds.

1. First, we need to establish the variables that will be used in our code. In our example, we’ll be using two variables: one for the light and one for the delay.

2. After that, we need to set up our void setup (){} function. This is where we’ll tell the Arduino what pins are being used and what state they should start in.

3. For our example, we’ll be using pin 13 for the light and we’ll set it to be an OUTPUT. Here is a sample code.

int Relay = 3;

void setup()

{

pinMode(13, OUTPUT); //Set Pin13 as output

digitalWrite(13, HIGH); //Set Pin13 High

pinMode(Relay, OUTPUT); //Set Pin3 as output

}

void loop()

{

digitalWrite(Relay, HIGH); //Turn on relay

delay(2000);

digitalWrite(Relay, LOW); //Turn off relay

delay(2000);

}

And that’s it! When you upload this code to your Arduino and power it on, the light should turn on and then turn off every 2 seconds, over and over again.

Arduino Relay Projects

Now that you know how to use a relay module for Arduino, you can begin incorporating them into your own projects. These may include turning on and off lights, motors, fans, or other devices. You can also use the setup to control more than one device at a time; by using multiple relays.

As you can see, using a relay module with Arduino microcontrollers is a relatively simple process and can be used to create all sorts of automated devices.

With a few simple components, you can create all sorts of automated devices and control them remotely. Give it a try and see what you come up with!

Conclusion

Using a relay module with Arduino microcontrollers is a simple and efficient way to control high-voltage devices or components. With just a few connections and some basic code, you can create all sorts of automated systems. When used in combination with other components, the possibilities of Arduino relay module control systems are endless.

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping