top of page

Interfacing 2 Channel Relay Module with Arduino and control High Voltage AC (current).


What is a Relay Module?


A Relay is a device that helps microcontrollers (or microcontroller-based boards) like Arduino to switch on or off different household appliances like motors, lights, water heaters, television, fans, etc.


The relay module for Arduino is one of the most powerful applications for Arduino as it can be used to control both A.C and D.C devices by simply controlling the relay by giving 5V. A relay is a switch that is operated electrically by an electromagnet. A relay can be used to control high voltage electronic devices such as motors as well as low voltage electronic devices such as a light bulb or a fan.


Relays work on the principle of electromagnetism. When the electricity is provided to the relay coil then it acts like a magnet and changes the state of the switch. The part which powers the relay module is completely isolated from the part which turns ON or OFF. This is why we can control a 220V appliance by simply controlling it using the 5V Arduino. you should also read getting started projects of Arduino.




Material Required:


Material Quantity


Arduino Uno 1

Relay module (2 Channel) 1

Jumper cables 6

Switching Source 1

Cable, Plug, Socket 1



Pinout Diagram:



HL-52S Relay Module


As an example, for this Arduino Relay Tutorial, we will use the HL-52S 2 channel relay module, which has 2 relays with a rating of 10A @ 250 and 125 V AC and 10A @ 30 and 28 V DC. The high voltage output connector has 3 pins, the middle one is the common pin, and as we can see from the markings one of the two other pins is for a normally open connection and the other one for a normally closed connection.




On the other side of the module, we have these 2 sets of pins. The first one has 4 pins, a Ground and a VCC pin for powering the module, and 2 input pins In1 and In2. The second set of pins has 3 pins with a jumper between the JDVcc and the Vcc pin. With a configuration like this, the electromagnet of the relay is directly powered by the Arduino Board and if something goes wrong with the relay the microcontroller could get damaged.


Circuit Diagram:


For better understanding let’s see the circuit schematics of the relay module in this configuration. So we can see that the 5 volts from our microcontroller connected to the Vcc pin for activating the relay through the Optocoupler IC are also connected to the JDVcc pin which powers the electromagnet of the relay. So in this case we got no isolation between the relay and the microcontroller.





To isolate the microcontroller from the relay, we need to remove the jumper and connect a separate power supply for the electromagnet to the JDVcc and the Ground pin. Now with this configuration, the microcontroller doesn’t have any physical connection with the relay, it just uses the LED light of the Optocoupler IC to activate the relay.



There is one more thing to be noticed from this circuit schematics. The input pins of the module work inversely. As we can see the relay will be activated when the input pin will be LOW because in that way the current will be able to flow from the VCC to the input pin which is low or ground, and the LED will light up and activate the relay. When the input pin will be HIGH there will be no current flow, so the LED will not light up and the relay will not be activated.




High Voltage Warning


Before we continue with this tutorial, I will warn you here that we will use High Voltage which if incorrectly or improperly used could result in serious injuries or death. So be very cautious of what you are doing because I take no responsibility for any of your actions.





How to use the relay module with the High Voltage devices


First, let’s take a look at the circuit diagram. As previously described we will use a 5V Adapter as a separate power supply for the electromagnet connected to the JDVcc and the Ground pin. The Arduino’s 5V pin will be connected to the Vcc pin of the module and PIN 7 to the In1 input pin for controlling the relay. Now for the HIGH Voltage part, we need a power plug, a socket, and a cable with two wires. One of the two wires will be cut and connected to the common and the normally open pin of the module output connector. So with this configuration when we will activate the relay we will get the high voltage circuit closed and working.





Here’s how made the cable. So I bought a plug, a socket, and a cable. Then I carefully cut the cable and cut one of the wires as shown in the picture below and connect them to the normally open connection pins of the relay module. Also connected the ends of the cable to the plug and the socket.





Tested Programming Code:


Now what’s left for this tutorial is to make a simple code and test the relay module and how it will work. Here’s the simple code, we will just use the PIN 7 for controlling the relay, so we will define it as output and make a program that will just activate and deactivate the relay every 3 seconds. I will mention once again here that the input of the module works inversely so a logic low at the input will activate the relay and vice versa.

int in1 = 7;

void setup() {

pinMode(in1, OUTPUT);

digitalWrite(in1, HIGH);


}

void loop() {

digitalWrite(in1, LOW);delay(3000);

digitalWrite(in1, HIGH);

delay(3000);

}


There is a demonstration of this example at the end of the video of this tutorial. I tested 3 devices on it. First a 100W light bulb, then a desk lamp, and a fan heater. All of these devices work on 220V.


Precautions:


1. Double-check the connections before powering on the circuit.

2. Don’t use loose jumper cables.

3. Check whether the proper board is selected from Arduino IDE.

4. Ensure proper placement of Relay Module for correct working.

5. Use proper measures before using AC electricity.


Conclusion:


So that’s how we can control any High Voltage Device using Arduino or any other microcontroller. And of course, the possibilities are now endless, for example, we can control the devices using a TV Remote, Bluetooth, SMS, Internet, and so on.




GET IN TOUCH

We'd love to hear from you

bottom of page