|
A relay is basically a switch which is operated by an electromagnet. The electromagnet requires a small voltage to get activated which we will give from the Arduino and once it is activated, it will pull the contact to make the high voltage circuit. The relay module we are going to use is the SRD-05VDC-SL-C(http://www.circuitbasics.com/wp-content/uploads/2015/11/SRD-05VDC-SL-C-Datasheet.pdf). It runs on 5V and we can control it with any micro-controller but we are going to use Arduino and NI-DAQ.
The Arduino relay module has total of six pins: three on one side and three on other side.On the bottom side, there are three pins which are signal, 5V and ground. We will connect these pins with the Arduino. While on the other side, there are NC (Normally close), C (Common) and the NO (normally open) which are the output pins of the 5V relay. There, we will connect the output device.
The Arduino relay module can be used in two states which are
1. Normally open state (NO)
2. Normally closed state (NC)
Normally open (NO)
In the normally open state, the initial output of the relay will be low when it will be powered. In this state, the common and the normally open pins are used.
Normally closed state (NC)
In the normally closed state, the initial output of the relay will be high when it will be powered. In this state, the common and the normally close pins are used.
In the first part, we will control a led using the relay and in the second part we will control a high voltage device using the relay. Controlling a DC device is easy as compared to the AC device. For controlling the DC device, you do not require an external supply until you are controlling a small voltage device like LED which runs on up to 5V.
The connections for connecting the relay module with Arduino are very simple. In this example, we will connect the relay module with Arduino in the normally open state. So, connect the 5V and the ground of the Arduino with the 5V and the ground of the relay module. Then connect the signal pin of the relay module with the pin 12 of the Arduino.
On the other side of the relay module, we will use the common pin and the normally open pin because we are going to connect the relay in the normally open state. So, connect the pin 13 of Arduino to the common of relay module and the normally open (NO) of the relay module to the positive pin of the LED. Connect the other pin of LED to the ground of Arduino.
int relay_pin = 8;
int led_pin = 13;
void setup(){
pinMode(relay_pin,OUTPUT);
pinMode(led_pin,OUTPUT);
digitalWrite(led_pin,HIGH);}
void loop(){
digitalWrite(relay_pin,HIGH);
delay(5000);
digitalWrite(relay_pin,LOW);
delay(5000);}
For the control of AC device, you need to take the necessary precautions because the AC is dangerous and it can cause damage to you. So, to avoid any danger, follow the below tutorial correctly.
For the control of AC device, we will require an external source which will power the AC source. So, connect the VCC, ground and signal to the 5V, ground and pin 8 of Arduino respectively. On the other end, connect one wire of the AC source to the one end of the bulb and the other wire to the common (C) of the relay. Then connect the normally open (NO) to the other end of the bulb.
int relay_pin = 8;
void setup(){
pinMode(relay_pin,OUTPUT);}
void loop(){
digitalWrite(relay_pin,HIGH);
delay(5000);
digitalWrite(relay_pin,LOW);
delay(5000);}
References:
http://www.techydiy.org/how-does-an-electric-relay-work/
http://www.techydiy.org/keyes-sr1y-relay-module/
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-8 14:28
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社