Chuyển tới nội dung
Home » Arduino Uno R3 Relay Control | Arduino 4 Relays Shield Basics

Arduino Uno R3 Relay Control | Arduino 4 Relays Shield Basics

How to control 2 relay module using Arduino UNO R3 // How to interface 2 relay module to Arduino UNO

Learn to turn high power devices on and off

Written By: Marcus Schappi

Difficulty

Easy

Steps

10

A relay is a device that is activated by a current in one circuit to open or close another circuit.

In this guide, we will learn to use a relay to turn an LED on and off. In this guide, a Little Bird Uno R3 board, the 5V 1-Channel relay board module is used. Please see parts list for a complete list of components required.

After learning to use the 5V 1-Channel relay component, you can use it to turn off lamps, fans, and other appliances up to 250 VAC.

Insert the LED into the bread board so that the Cathode (shorter pin) is on the left hand side.

Insert a 220 Ohm Relay so that one pin is in line with the LED’s Anode (longer leg)

The 220 Ohm Relay has the bands: Red, Red, Black, Black, Brown.

Connect the Cathode to a Ground pin on the Arduino.

The Cathode is the negative (shorter) leg of the LED.

Connect the 3.3V Arduino Pin to the Relay.

The 3.3V jumper should go to the NC side of the screw socket.

Connect COM on the relay to the other side of the resistor.

int relay = 13; // Plug the relay into Digital Pin 13 void setup() { pinMode(relay, OUTPUT); } void loop() { digitalWrite(relay, HIGH); // Turn the relay on delay(1000); // Wait 1 second digitalWrite(relay, LOW); // Turn the relay Off delay(1000); // Wait 1 second }

Grab the code and upload it to your board.

You should start to hear the click, click of the relay switching on and off. There is also a red light on the module to tell you when it switches.

The Relay can be use to control up to 250VAC but we DO NOT recommend you play with this sort of voltage / current unless you are an electrician!

Module relay 4 kênh shield v1.0 mở rộng cho Arduino UNO

ỨNG DỤNG:

  • Mạch Arduino shield 4 relays tương thích với board Arduino UNO R3, Arduino Mega2560, lenardo …
  • Mạch Arduino shield 4 relays được sử dụng trong các ứng dụng cần đóng cắt tải AC hoặc DC, mạch có thế kế đơn giản với relay, có oppto cách ly và diode chống nhiễu xung ngược từ relay.

THÔNG SỐ KỸ THUẬT:

  • Điện áp sử dụng: 5VDC từ chân 5V của Arduino.
  • Điện áp kích: TTL 5VDC / 3.3VDC
  • Số Relay: 4 relay 125VAC-3A / 24VDC-3A (có thể đóng ngắt tải 220VAC công suất thấp như bóng đèn, quạt,…).
  • Tích hợp transistor cách ly và diod chống nhiễu xung ngược từ relay (flyback diode).
  • Chân kích Relay (kích mức HIGH):

+ Relay 1: D6
+ Relay 2: D5
+ Relay 3: D4
+ Relay 4: D3

  • Kích thước: 70 x 54 x 26mm.

TÀI LIỆU:

  • Các bạn có thể tải sơ đồ nguyên lý của kit arduino shield 4 relay tại đây : schematic LINK https://lamchucongnghe.com/wp-content/uploads/2018/10/Relay-shield-v0.9b-schematic.pdf

Arduino 4 Relays Shield Basics

Learn the basics of how relays work, and how to control the four relays onboard the Arduino 4 Relays Shield

Introduction: Relay With Arduino Uno R3

As we may know, relay is a device which is used to provide connection between two or more points or devices in response to the input signal applied. In other words, relays provide isolation between the controller and the device as devices may work on AC as well as on DC. However, they receive signals from a microcontroller which works on DC hence requiring a relay to bridge the gap. Relay is extremely useful when you need to control a large amount of current or voltage with small electrical signal.

How to control 2 relay module using Arduino UNO R3 // How to interface 2 relay module to Arduino UNO
How to control 2 relay module using Arduino UNO R3 // How to interface 2 relay module to Arduino UNO

The Arduino 4 Relay Shield

Inside the shield, the low power circuit is already made. The only thing we need to connect is a power supply (max 48V), and a high power component (max 48V). These are connected to the high power pins. In the image below, you can get a better understanding on the layout of the shield:

Circuit

Let’s begin by mounting our Arduino 4 Relay Shield on top of an Arduino UNO.

Programming the Board

We will now get to the programming part of this tutorial.

First, let’s take a look at how we will activate our relays. We are actually not using a library, as the operation is very basic.

  • – assigns


    int relay_1 = 4;

    to pin 4. It is important that we assign it to pin 1, as the relay is internally wired to this pin.


    relay_1

  • – assigns


    int relay_2 = 7;

    to pin 7. Same here, the relay is wired to pin 2, so we can’t use a pin of our choosing.


    relay_2

  • – assigns


    int relay_3 = 8;

    to pin 8. Same here, the relay is wired to pin 2, so we can’t use a pin of our choosing.


    relay_3

  • – assigns


    int relay_4 = 12;

    to pin 12. Same here, the relay is wired to pin 2, so we can’t use a pin of our choosing.


    relay_4

  • – configures relay 1 to be an


    pinMode(relay_X, OUTPUT)


    OUTPUT

  • – write either a high or low state to relay 1.


    digitalWrite(relay_X, state)

The sketch can be found in the snippet below. Upload the sketch to the board.

1int relay_1 = 4;2int relay_2 = 7;3int relay_3 = 8;4int relay_4 = 12;56void setup() {7 // put your setup code here, to run once:8 Serial.begin(9600);910 pinMode(relay_1, OUTPUT);11 pinMode(relay_2, OUTPUT);12 pinMode(relay_3, OUTPUT);13 pinMode(relay_4, OUTPUT);1415}1617void loop() {1819 digitalWrite(relay_1, HIGH);20 digitalWrite(relay_2, HIGH);21 digitalWrite(relay_3, HIGH);22 digitalWrite(relay_4, HIGH);2324 Serial.println(“All relays ON”);2526 delay(1000);2728 digitalWrite(relay_1, LOW);29 digitalWrite(relay_2, LOW);30 digitalWrite(relay_3, LOW);31 digitalWrite(relay_4, LOW);3233 Serial.println(“All relays OFF”);3435 delay(1000);36}

Product Description

Product Description:High quality.Relay Shield (i.e. 5 V Quad Relay Module) is a small current signal control power equipment widely used electronic module, allowing high-power single-chip control devices to be widely used in SCM system to create smart home project; and can be directly in compatible with the use of various types of motherboards, eliminate the patch cable problems see Features

Characteristics:1. Standard for Shield interfaces and shape2. Can leave others in place for expansion boards3. 3 M3 screw position holes for easy installation4. High Drive (5V or 3.3V) normally open contact closure.5. Onboard relay indicator (red).Special note: When using the For UNO board is connected to it, because UNO USB interface is extremely high, should avoid green terminals are scale.

Relay Shield Interface: (the last image shows the last image)Relay: sky- 5V DC relay, model HJR-4102-L-5V, of which Relay1 is the 1st relay, the others and so on.Power Interface: 5V DC power interfaceIndicator: four lights are red when the relay is high, the corresponding indicator will light up.Relay Terminals: Terminal high-power, high current high voltage can be connected to the device. The 1st foot (i.e. NOx) is a normally open pin , the NCx pin is normally closed, COMx is common, i.e., when the relay is not controlled, NOx and COMx open between two pins, NCx and COMx connection; When the relay (x) control signal pin is high drive relays, NOx and COMMA. connection open bed between NCx and Comx.

Delivery Contents:1 x 4 channel 5 V relay shield module2 x HJR 4102 L 5V relay

Arduino IoT Project with Google Assistant & Alexa app using ESP8266 Arduino UNO WiFi control Relay
Arduino IoT Project with Google Assistant & Alexa app using ESP8266 Arduino UNO WiFi control Relay

Conclusion

In this tutorial, we have gone through some basics of how a relay works, including how the internal mechanism works, but also how to create a circuit with high power components, and how to create a program that activates or de-activates them.

Relays are incredible popular electronic components that are practically used everywhere: cars, planes, heating systems, industrial machines and many many more.

Suggested changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.

Step 4: Procedure

Connect a 1K resistor (for current limiting when the transistor is energized) to pin 8 of the SunFounder Uno board, then to an NPN transistor whose collector is connected to the coil of a relay and emitter to GND; connect the normally open contact of the relay to an LED and then GND. Therefore, when a High level signal is given to pin 8, the transistor is energized, thus making the coil of the relay conductive. Then its normally open contact is closed, and the LED will light up. When pin 8 is given a Low level, the LED will stay dim.

Function of the freewheeling diode: When the voltage input changes from High (5V) to Low (0V), the transistor changes from saturation (three working conditions: amplification, saturation, and cut-off) to cut-off, the current in the coil suddenly has no way to flow through. At this moment, without the freewheeling diode, a counter-electromotive force (EMF) will be generated at the ends of the coil, with positive at the bottom and negative at the top, a voltage higher than 100V. This voltage plus that from the power at the transistor are big enough to burn it. Therefore, the freewheeling diode is extremely important in discharging this counter-EMF in the direction of the arrow in the figure above, so the voltage of the transistor to GND is no higher than +5V (+0.7V).

In this experiment, when the relay closes, the LED will light up; when the relay opens, the LED will go out.

Step 1:

Build the circuit.

Step 2:

Download the code from https://github.com/primerobotics/Arduino

Step 3:

Upload the sketch to the Arduino Uno board

Click the Upload icon to upload the code to the control board.

If “Done uploading” appears at the bottom of the window, it means the sketch has been successfully uploaded.

Now, send a High level signal, and the relay will close and the LED will light up; send a low one, and it will open and the LED will go out. In addition, you can hear a tick-tock caused by breaking the normally close contact and closing the normally open one.

Arduino - Driving DC Motor (Water Pump) with Relay
Arduino – Driving DC Motor (Water Pump) with Relay

Kết luận

Tóm lại, việc sử dụng Arduino để điều khiển đèn 220V bằng rơ le là một ứng dụng thực tế và hữu ích trong các hệ thống điện tử. Điều này giúp giảm thiểu việc tiếp xúc trực tiếp với điện áp cao và tăng cường an toàn cho người sử dụng. Bên cạnh đó, việc sử dụng rơ le cũng giúp đảm bảo việc điều khiển đèn 220V được ổn định và chính xác hơn. Tuy nhiên, để thực hiện được ứng dụng này, cần phải có kiến thức và kỹ năng về lập trình và điện tử, cũng như đảm bảo an toàn và tuân thủ các quy định về điện áp.

Step 5: Code

//relay

//Email:[email protected]

//Website:www.primerobotics.in

/******************************************************/

const int relayPin = 8; //the base of the transistor attach to

/******************************************************/

void setup()

pinMode(relayPin, OUTPUT); //initialize the relayPin as an output

/******************************************************/

void loop()

digitalWrite(relayPin, HIGH); //drive relay closure conduction

delay(1000); //wait for a second

digitalWrite(relayPin, LOW); //drive the relay is closed off

delay(1000); //wait for a second

/******************************************************/

Điều khiển Đèn 220V bằng Rơ le (Relay) sử dụng Arduino

How to make GSM based Home Appliance Control using Arduino and GSM | GSM based Home Automation
How to make GSM based Home Appliance Control using Arduino and GSM | GSM based Home Automation

Relays

Relays allow low-power microcontrollers to handle circuits that uses much higher power than what the board can handle directly. They are typically used in industrial applications to control high power circuits, but it is also used in cars, homes and other electric applications.

Relays are composed by an electromagnet that moves a tiny metallic plank, which is called COM terminal, between two different positions NC terminal and NO terminal. We can decide in which position the COM terminal is connected to through activating/deactivating the electromagnet, by connecting a low power signal in the electromagnet control terminals.

Writing a program to control the relays is very easy: it works very similar to turning ON or OFF an LED. Take a look at the snippet below to understand how it is used:

1digitalWrite(relay, HIGH);23digitalWrite(relay, LOW);

And that’s basically how we control the relays. Depending on the configuration, the logic will be inverted. For example, if we are using an NC (normally closed) configuration, we need to write a LOW signal to activate the relay. If we are using an NO (normally open) configuration, we need to write a HIGH signal to activate the relay.

Testing It Out

After we have uploaded the code, the program will start running immediately. If everything is working correctly, we will hear a “tick-tack” noise every second. This is the sound of the relays that are mechanically switching on and off. If we take a look at the shield, we will see four LEDs blinking every second. These signify the state of the relays. We can also view the states in the Serial Monitor.

Now in this example, we have simply activated the relays, but we still haven’t connected anything to them. While we are not going to go in-depth on how to connect high power components, we can take a look at how a circuit looks like for turning ON or OFF a 24V lamp.

Let’s begin with the high power pins on the Arduino 4 Relays Shield. There are twelve in total for all four relays, where there are three different type of connections: COM, NC and NO. Below is how the high power pins for Relay 4 looks like.

In this scenario, we are going to use the NC configuration, which means that writing a LOW signal to the relay will connect the NC pin to COM, which provides power to the component connected. The circuit for this could look like this:

In this circuit, we are using a 24V power supply and a 24V light bulb. Now, if we were to write a program for this, we would activate through using:

1digitalWrite(relay_4, LOW)

and to de-activate it:

1digitalWrite(relay_4, HIGH)

Note: Use extreme caution when creating higher power circuits. Make sure that both the power supply and the component does not exceed 48V. For example, connecting it straight to a wall socket without a power converter would supply 220-240V, which is 5 times as high.

Troubleshoot

If the code is not working, there are some common issues we can troubleshoot:

  • We have not connect the LEDs properly (this is an optional requirement).
  • If the code fails to compile, make sure there’s no missing curly brackets {} or semicolons ; anywhere in the code.
  • We have connected the shield correctly on top of the board (the pins should match each other).
HOW TO USE RELAY MODULE WITH ARDUINO | 4 RELAY MODULE ARDUINO | RELAY MODULE | 5V RELAY MODULE
HOW TO USE RELAY MODULE WITH ARDUINO | 4 RELAY MODULE ARDUINO | RELAY MODULE | 5V RELAY MODULE

Code

Đoạn code khá đơn giản ở đây mình sử dụng chân D8 để làm chân điều khiển. Khi bắt đầu chương trình đèn sẽ sáng trong 3 giây, sau 3 giây bóng đèn sẽ tắt .

int Relay = 8; void setup() { pinMode(Relay, OUTPUT); digitalWrite(Relay, HIGH); } void loop() { digitalWrite(Relay, LOW); delay(3000); digitalWrite(Relay, HIGH); delay(3000); }

Giải thích Code

Đoạn code trên dùng để điều khiển một module relay (rơle) kết nối với chân số 8 của board Arduino. Khi chương trình được chạy, ở hàm

setup()

, chân số 8 được cấu hình là đầu ra với lệnh

pinMode(Relay, OUTPUT);

, và sau đó được kích hoạt bằng lệnh

digitalWrite(Relay, HIGH);

, giúp đảm bảo rơle khởi động ở trạng thái ban đầu.

Ở hàm

loop()

, rơle được điều khiển để chuyển đổi trạng thái bằng cách đặt đầu ra của chân số 8 ở mức thấp với lệnh

digitalWrite(Relay, LOW);

, sau đó đợi trong 3 giây bằng lệnh

delay(3000);

. Sau khi chờ 3 giây, chân số 8 được đặt ở mức cao bằng lệnh

digitalWrite(Relay, HIGH);

, rơle sẽ được kích hoạt và giữ ở trạng thái này trong 3 giây nữa. Điều này tạo ra một chu trình chuyển đổi trạng thái của rơle sau mỗi 6 giây.

Bài viết liên quan

  • Mới học Arduino nên chọn board nào?
  • GÓC DIY | Chế tạo Robot tránh vật cản – Hướng dẫn chi tiết
  • Điều khiển Đèn 220V bằng Realy sử dụng Arduino
  • Đo nhiệt độ bằng Cảm biến LM35 sử dụng Arduino
  • Báo động chống trộm bằng cảm biến PIR (HC-SR501)

Chúc các bạn thành công!

Trân trọng.

Số lượng mua (Cái)

Đơn giá (VND)

1+ 59.000
10+ 58.000
20+ 57.000

Giao hàng toàn quốc

Thanh toán khi nhận hàng

Cam kết đổi/trả hàng

Thuộc tính Giá trị Tìm kiếm

Điện áp kích

5 VDC

Mức kích

Kích mức cao

Loại relay

Thường

Số kênh

124 Sản phẩm tương tự
Relay 4-Kênh Relay
Giao tiếp Chuẩn Arduino Shield
Mức kích Kích mức cao
Led báo Led báo màu đỏ
Điện áp hoạt động 5V
Dòng điện 130mA
Điện áp tải Max 250VAC/30VDC
Dòng Max 3A

Lưu ý: Sản phẩm không được bảo hành. Quý khách vui lòng tham khảo Quy định bảo hành và Quy định đổi trả hàng

int RL1 = 4; int RL2 = 5; int RL3 = 6; int RL4 = 7; void setup() { pinMode(RL1, OUTPUT); pinMode(RL2, OUTPUT); pinMode(RL3, OUTPUT); pinMode(RL4, OUTPUT); for (int i = 4; i < 8; i++) { digitalWrite(i, LOW); } } void loop() { for (int i = 4; i < 8; i++) { digitalWrite(i, !digitalRead(i)); delay(500); } }

Chat

Use an Arduino to Control a Relay

What is Relay? | How to control Relay using Arduino
What is Relay? | How to control Relay using Arduino

Step 2: Principle

There are 5 parts in every relay:

1. Electromagnet – It consists of an iron core wounded by coil of wires. When electricity is passed through, it becomes magnetic. Therefore, it is called electromagnet.

2. Armature – The movable magnetic strip is known as armature. When current flows through them, the coil is it energized thus producing a magnetic field which is used to make or break the normally open (N/O) or normally close (N/C) points. And the armature can be moved with direct current (DC) as well as alternating current (AC).

3. Spring – When no currents flow through the coil on the electromagnet, the spring pulls the armature away so the circuit cannot be completed.

4. Set of electrical contacts – There are two contact points:

. Normally open – connected when the relay is activated, and disconnected when it is inactive.

. Normally close – not connected when the relay is activated, and connected when it is inactive.

5. Molded frame – Relays are covered with plastic for protection.

Working of Relay

The working principle of relay is simple. When power is supplied to the relay, currents start flowing through the control coil; as a result, the electromagnet starts energizing. Then the armature is attracted to the coil, pulling down the moving contact together thus connecting with the normally open contacts. So the circuit with the load is energized. Then breaking the circuit would a similar case, as the moving contact will be pulled up to the normally closed contacts under the force of the spring. In this way, the switching on and off of the relay can control the state of a load circuit.

Transistor

Transistor is a semiconductor device that controls current by current. It functions by amplifying weak signal to larger amplitude signal and is also used for non-contact switch. A transistor is a three-layer structure composed of P-type and N-type semiconductors. They form the three regions internally. The thinner in the middle is the base region; the other two are both N-type or P-type ones – the smaller region with intense majority carriers is the emitter region, when the other one is the collector region. This composition enables the transistor to be an amplifier.

From these three regions, three poles are generated respectively, which are base (b), emitter (e), and collector (c). They form two P-N junctions, namely, the emitter junction and collection junction. The direction of the arrow in the transistor circuit symbol indicates that of the emitter junction. Based on the semiconductor type, transistors can be divided into two groups, the NPN and PNP ones. From the abbreviation, we can tell that the former is made of two N-type semiconductors and one P-type and that the latter is the opposite. See the figure below.

When a High level signal goes through an NPN transistor, it is energized. But a PNP one needs a Low level signal to manage it. Both types of transistor are frequently used for contactless switches, just like in this experiment.

Các linh kiện cần thiết cho dự án

Tên linh kiện Số lượng Shopee
Arduino Uno R3 Mua ngay
Cáp nạp Mua ngay
Relay 5V/1 Kênh Mua ngay
Dây cắm (Đực – Cái) Mua ngay

Bạn sẽ học được gì

  • Có kiến thức cơ bản về Robotics
  • Chế tạo Robot dò đường thông minh
  • Đánh thức nhà khoa học bên trong bạn
  • Tìm hiểu thêm về Robotics, các thuật toán Robot tự động
  • Kiến thức nền tảng để chế tạo các máy móc tự động phục vụ đời sống sinh hoạt, lao động sản xuất
  • Kiến thức để chế tạo sản phẩm, tham gia các cuộc thi khoa học công nghệ trong nước và quốc tế
How to use 5V Relay to Turn ON and OFF AC Light bulb - Arduino Tutorial
How to use 5V Relay to Turn ON and OFF AC Light bulb – Arduino Tutorial

Introduction

In this tutorial, we will test out the four relays on board the Arduino 4 Relays Shield. This shield is a great addon for the Arduino UNO board, as it has four relays capable of handling loads up to 48V. To control the relays, we need to use the following pins:

  • Relay 1 – pin 4.
  • Relay 2 – pin 7.
  • Relay 3 – pin 8.
  • Relay 4 – pin 12.

The sketch we will use is going to be very simple. It will activate all four relays for one second, then de-activating them for one second. The status of the relays can be seen onboard the shield, as it has a status LED for each relay.

Note: Please use extreme caution when using relays and higher power loads. Powering the relays directly from a wall socket can be extremely dangerous, and exceeds the maximum voltage the relays can handle by far.

Keywords searched by users: arduino uno r3 relay control

Mạch 4 Relay Arduino Shield 5V Kích Mức Cao Nguồn: 5Vdc, Dùng Cho Arduino,  Tải: 250Vac/30Vdc 3A
Mạch 4 Relay Arduino Shield 5V Kích Mức Cao Nguồn: 5Vdc, Dùng Cho Arduino, Tải: 250Vac/30Vdc 3A
Arduino - Uno R3 - Relay Module Control - Demo - Plc 4 Relays Out - Youtube
Arduino – Uno R3 – Relay Module Control – Demo – Plc 4 Relays Out – Youtube
Module Relay 4 Kênh Shield V1.0 Mở Rộng Cho Arduino Uno Mte
Module Relay 4 Kênh Shield V1.0 Mở Rộng Cho Arduino Uno Mte
How To Use 5V Relay Module | Arduino Uno With 5V Relay Module [Code And  Circuit Diagram] - Youtube
How To Use 5V Relay Module | Arduino Uno With 5V Relay Module [Code And Circuit Diagram] – Youtube
Cách Điều Khiển Modul Relay Với Arduino
Cách Điều Khiển Modul Relay Với Arduino
Amazon.Com: Elegoo 4 Channel Dc 5V Relay Module With Optocoupler Compatible  With Arduino Uno R3 Mega 2560 Dsp Arm Pic Avr Stm32 : Electronics
Amazon.Com: Elegoo 4 Channel Dc 5V Relay Module With Optocoupler Compatible With Arduino Uno R3 Mega 2560 Dsp Arm Pic Avr Stm32 : Electronics
Arduino 4 Relay Shield
Arduino 4 Relay Shield
How Many Relays Can I Connect To One Arduino? - Youtube
How Many Relays Can I Connect To One Arduino? – Youtube
Diy: Relay Switch Motor Controller - Arduino : 4 Steps (With Pictures) -  Instructables
Diy: Relay Switch Motor Controller – Arduino : 4 Steps (With Pictures) – Instructables
Mạch 4 Relay Arduino Shield 5V Kích Mức Cao Nguồn: 5Vdc, Dùng Cho Arduino,  Tải: 250Vac/30Vdc 3A
Mạch 4 Relay Arduino Shield 5V Kích Mức Cao Nguồn: 5Vdc, Dùng Cho Arduino, Tải: 250Vac/30Vdc 3A
Lesson 67: Controlling 8 Channel Relay With A 4X3 Keypad To Control 4 Ac Or  Dc Loads - Youtube
Lesson 67: Controlling 8 Channel Relay With A 4X3 Keypad To Control 4 Ac Or Dc Loads – Youtube
4 Channel Dc 5V Relay Module With Optocoupler For Arduino Uno R3 Mega 2560  1280 | Ebay
4 Channel Dc 5V Relay Module With Optocoupler For Arduino Uno R3 Mega 2560 1280 | Ebay
Điều Khiển Đèn 220V Bằng Rơ Le (Relay) Sử Dụng Arduino | Arduino Kit
Điều Khiển Đèn 220V Bằng Rơ Le (Relay) Sử Dụng Arduino | Arduino Kit

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *