陆宇振
Relay Module interfacing with Arduino and NI-DAQ
2019-5-2 05:30
阅读:6727

Relay Module

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.

Pin out of 5V relay module

Arduino Relay module

keyes-SR1y-photo-with-labels.jpg

opto-isolated-2-relay-module-connections-crop.jpg

(http://www.techydiy.org/opto-isolated-dual-relay-module-arduino/)

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.

Normally open state (NO) VS Normally closed state (NC)

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.


Case#1) Controlling Relay Module with Arduino

Controlling DC Devices using Arduino Relay Module

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.

Circuit Diagram and Explanation

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.

Control Led using Arduino relay module

Controlling LED using Arduino relay module

Code

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);}


Controlling AC Device using Arduino Relay Module

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.

Circuit Diagram and Explanation

control ac device using arduino relay module

High Voltage Device with Arduino

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.

Code

int relay_pin = 8;

void setup(){

pinMode(relay_pin,OUTPUT);}

void loop(){

digitalWrite(relay_pin,HIGH);

delay(5000);

digitalWrite(relay_pin,LOW);

delay(5000);}

Case#2) Controlling Relay Module with NI-DAQ

relay-niDAQ.jpeg

References:

http://www.techydiy.org/how-does-an-electric-relay-work/

http://www.techydiy.org/keyes-sr1y-relay-module/

https://www.sainsmart.com/products/2-channel-5v-relay-module?variant=45100777236&utm_campaign=gs-2018-08-06&utm_source=google&utm_medium=smart_campaign&gclid=Cj0KCQjwh6XmBRDRARIsAKNInDGYDS0-_N7h5zJ8WlHcgHyVIgWMDvBGFiOZTvXY20U-ipv-EylaMocaAuY6EALw_wcB

转载本文请联系原作者获取授权,同时请注明本文来自陆宇振科学网博客。

链接地址:https://wap.sciencenet.cn/blog-578676-1176621.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?