Arduino Relay Control
INTRODUCTION
Arduino cannot directly On/Off a high voltage supply, so we use Relay for that. Relay is basically an electrical switch operated by an electromagnet. The electromagnet is activated with a low voltage (i.e. logically LOW voltage), for example 5 volt from a micro-controller and it pulls a contact to make or break a high voltage circuit.
Controlling a relay with the Arduino is as simple as controlling an output such as an LED.
Ralay module comes with different channels, which means the no. devices that module can control. Here, we will be configuring a 4-Channel relay but the process remains the same for 1-Channel,2-Channel or N- Channels relay. One, this you should take care that these modules comes with Rating, which means how much maximum voltage (both AC/ DC)the relay can handle with corresponding Amps rating. So, one should use the relays only under the rated ratings not beyond that as, it might damage the module and also is dangerous due to involvement of HIGH VOLTAGE.
Here the rating of the relay used is :
Thus, relay module allows you to combine the processing power of the Arduino to devices that use higher current and voltage
The knowledge gained in this project will help you in projects of HOME AUTOMATION, Switching Devices running on AC/DC, Controlling polarities of motors and many more.
Relay Module Input
At the Input Side of the relay we have :
VCC pin: Power is supplied to the module via this pin ( Note : Usually power is given to the module from Arduino on board 5V supply but it results in power shortage at the relay sometimes due to high current required for the Coils of the relay to switch simultaneously, so it is advised to use external power supply(discussed later), in case of 1/ 2 Channel Relay you can power from Arduino directly).
Gnd: Gnd from Arduino is supplied to this pin.
Input Pins IN1, IN2, IN3 and IN4: Connected to an Arduino digital pins
Each channel is energized with low input. So, while writing the code we initialise these Input Pins HIGH in void Setup and when we need to turn relays ON i.e. switch , we make the pins LOW accordingly.
Relay Module Output:
At the output side each relay channel has three connecting terminals namely :
Normally Closed (NC) terminal: there is contact between the COM pin and the NC pin. There is always connection between the COM and NC pins, even when the relay is turned off. When you trigger the relay, the circuit is opened and there is no supply provided to a load.
Common (COM): Common
Normally Open (NO): there is no contact between the COM pin and the NO pin. So, when you trigger the relay, it connects to the COM pin and supply is provided to a load.
Note :For controlling any device like Lamp, TV or Fan for example, it is better to use a normally-open circuit, because we just want to turn on this devices occasionally.
Module Schematic:
Fundamentally this is four separate circuits on one board. Other than sharing VCC and ground, the channels are isolated from one another. See the schematic below:
Typical Connection to an Arduino:
The diagram below shows the typical connections of 4-channel relay with Arduino (Here we are using only one channel for demonstration). In the example shown, a low output on digital pin 3 will cause the light bulb to turn on.
Here, DC supply of 24V is controlled you can do the same with an AC supply too.
Power the Relay by External Power Supply :
Step1: Remove the Jumper at Jdvcc-Vcc and connect Jd-Vcc pin with the positive supply of external source. Keep the Vcc pin at the Input side vacant.
Step2: Common the Gnd pin of Input side and negative terminal of external supply. And, connect it to the Arduino’s Gnd pin.
Step3: Connect the Input pins IN1,IN2,IN3 and IN4 with digital pins of Arduino, as discussed before. Code will be same for both the connections.
Code Section:
for this particular connection we are using only 1 channel of the relay module i.e. IN1 with digital pin 7. You can modify it as per your need.
void setup() { pinMode(7, OUTPUT); // initialize digital pin 7 as an output. digitalWrite(7, HIGH); // initialize digital pin 7 as HIGH. } // the loop function runs over and over again forever void loop() { digitalWrite(7, LOW); // turn the Relay ON (LOW is the voltage level) delay(3000); // wait for 3 second digitalWrite(7, HIGH); // turn the LED off by making the voltage HIGH again delay(3000); // wait for 3 second }
Buy From Us and Get More Exciting Offers
www.tomsonelectronics.com