Tìm kiếm mã

Mã Arduino và Video cho Rơ-le 5V Hai Kênh

Mã Arduino và Video cho Rơ-le 5V Hai Kênh

Trong hướng dẫn này, chúng ta sẽ học cách điều khiển tải AC và DC bằng rơ-le 5V hai kênh với Arduino. Rơ-le cho phép bạn chuyển đổi giữa hai tải khác nhau, chẳng hạn như bóng đèn AC và động cơ DC, mang lại sự linh hoạt cho nhiều ứng dụng khác nhau. Đến cuối hướng dẫn này, bạn sẽ có thể tự thiết lập hệ thống rơ-le của mình và điều khiển nó thông qua mã Arduino đơn giản.

2 chanel relay module

Trong suốt quá trình, chúng ta sẽ đề cập đến các linh kiện cần thiết, hướng dẫn đấu dây và hướng dẫn chi tiết về mã Arduino dùng để điều khiển rơ-le. Dự án này rất phù hợp cho người mới bắt đầu muốn khám phá thế giới điện tử và tự động hóa. Để có hướng dẫn trực quan, hãy xem video liên quan (trong video tại 00:00).

Giải thích về Phần cứng

Linh kiện chính trong dự án này là rơ-le 5V hai kênh. Rơ-le này bao gồm hai công tắc độc lập có thể điều khiển các tải riêng biệt. Mỗi rơ-le có ba tiếp điểm: Thường Đóng (NC), Thường Mở (NO) và Chung (COM). Khi rơ-le được kích hoạt, tiếp điểm NO kết nối, cho phép dòng điện chạy qua tải.

Các linh kiện thiết yếu khác bao gồm bo mạch Arduino, bo mạch này sẽ điều khiển rơ-le thông qua các chân kỹ thuật số của nó. Mô-đun rơ-le cũng có đèn LED chỉ báo sáng lên khi rơ-le được kích hoạt. Ngoài ra, rơ-le được cách ly quang học, mang lại sự an toàn bằng cách tách mạch điều khiển khỏi mạch tải.

Chi tiết Bảng dữ liệu

Nhà sản xuấtSongle
Số bộ phậnSRD-05VDC-SL-C
Điện áp Logic/IO5 V
Điện áp cấp nguồn5 V
Dòng điện đầu ra (mỗi kênh)10 A
Dòng điện đỉnh (mỗi kênh)10 A
Hướng dẫn tần số PWMKhông áp dụng
Ngưỡng logic đầu vàoTối thiểu 2,5 V
Sụt áp / RDS(on) / bão hòa80 mΩ
Giới hạn nhiệt70 °C
Kiểu đóng góiMô-đun
Ghi chú / biến thểCách ly quang học

  • Đảm bảo cách ly thích hợp khi kết nối tải AC.
  • Sử dụng cầu chì phù hợp để an toàn với tải cao.
  • Giữ mô-đun rơ-le tránh xa độ ẩm.
  • Cân nhắc tản nhiệt cho các ứng dụng công suất cao.
  • Kiểm tra hệ thống dây điện trước khi cấp nguồn để tránh hư hỏng.
  • Sử dụng nguồn điện riêng cho các thiết bị dòng điện cao nếu cần thiết.

Hướng dẫn Đấu dây

Arduino wiring for 2 channel relay module AC load
Arduino wiring for 2 channel relay module AC load

Để đấu dây rơ-le hai kênh với Arduino, hãy bắt đầu bằng cách kết nối chân VCC của mô-đun rơ-le với chân 5V trên Arduino. Kết nối chân GND của rơ-le với chân GND trên Arduino. Điều này cung cấp nguồn điện cho mô-đun rơ-le.

Tiếp theo, kết nối các chân điều khiển: nối chân IN1 của rơ-le với chân kỹ thuật số 7 trên Arduino và chân IN2 với chân kỹ thuật số 8. Thiết lập này sẽ cho phép bạn điều khiển cả hai rơ-le một cách độc lập. Cuối cùng, kết nối tải AC hoặc DC của bạn với các tiếp điểm rơ-le theo nhu cầu, đảm bảo tuân thủ các biện pháp an toàn thích hợp khi xử lý điện áp AC.

Ví dụ Mã & Hướng dẫn Chi tiết

Trong mã Arduino, chúng ta bắt đầu bằng cách khởi tạo giao tiếp nối tiếp và đặt chế độ chân cho các chân điều khiển rơ-le. Các biến relay1Pinrelay2Pin được định nghĩa để đại diện cho các chân kết nối với mỗi rơ-le. Trạng thái đầu ra của các chân này sau đó được chuyển đổi trong vòng lặp.

const int relay1Pin = 7; // định nghĩa chân cho rơ-le 1
const int relay2Pin = 8; // định nghĩa chân cho rơ-le 2

void setup() {
  Serial.begin(9600); // thiết lập Serial Monitor để hiển thị thông tin
  pinMode(relay1Pin, OUTPUT); // kết nối với Rơ-le 1
  pinMode(relay2Pin, OUTPUT); // kết nối với Rơ-le 2
}

Đoạn trích này khởi tạo màn hình nối tiếp để xuất thông tin gỡ lỗi và đặt các chân điều khiển rơ-le làm đầu ra. Điều này rất quan trọng để đảm bảo các rơ-le có thể được bật và tắt khi cần thiết.

void loop() {
  digitalWrite(relay2Pin, LOW); // tắt rơ-le 2 
  Serial.print("Pin 8 LOW");
  digitalWrite(relay1Pin, HIGH); // bật rơ-le 1
  Serial.println(" Pin 7 HIGH");
  delay(3000); // giữ rơ-le 2 TẮT và rơ-le 1 BẬT trong 3 giây
  digitalWrite(relay1Pin, LOW); // tắt rơ-le 1
  digitalWrite(relay2Pin, HIGH); // bật rơ-le 2
  Serial.print("Pin 7 LOW");
  Serial.println(" Pin 8 HIGH");
  delay(3000); // giữ rơ-le 1 TẮT và rơ-le 2 BẬT trong 3 giây
}

Mã này chuyển đổi các rơ-le mỗi ba giây, bật một rơ-le trong khi tắt rơ-le kia. Màn hình nối tiếp xuất ra trạng thái của các chân, giúp gỡ lỗi và hiểu các hoạt động của rơ-le.

Trình diễn / Điều gì sẽ xảy ra

Khi thiết lập hoàn tất, bạn sẽ thấy rơ-le chuyển đổi giữa các tải được kết nối mỗi ba giây. Rơ-le sẽ kích hoạt bóng đèn AC hoặc động cơ DC được kết nối một cách luân phiên. Hãy thận trọng khi làm việc với tải AC, vì xử lý không đúng cách có thể dẫn đến các tình huống nguy hiểm (trong video tại 12:34).

Mốc thời gian Video

  • 00:00 - Giới thiệu về rơ-le hai kênh
  • 04:15 - Hướng dẫn đấu dây
  • 08:30 - Giải thích mã
  • 10:45 - Trình diễn rơ-le

Hình ảnh

Arduino wiring for 2 channel relay module AC load
Arduino wiring for 2 channel relay module AC load
2 chanel relay module
2 chanel relay module
2 chanel relay module
2 chanel relay module
2 chanel relay module
2 chanel relay module
2 chanel relay module
2 chanel relay module
46-This is the Arduino code for a dual-channel 5V relay.
Ngôn ngữ: C++
/*
 * This is the Arduino code for Dual Channel 5V Relay
 * to control turning ON or OFF AC or DC loads. You can control 2 different loads such as bulbs, or a heater, or other machines.
  Watch the video instruction for this code: https://youtu.be/EclIomn_3dI
 
 *  * 
 * Written by Ahmad Shamshiri for Robojax Video
 * Date: December 26, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purposes only.
 


Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all materials, wiring diagrams and libraries
all in one place. Purchase my course on Udemy.com: http://robojax.com/L/?id=62

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon: http://robojax.com/L/?id=63

or make a donation using PayPal: http://robojax.com/L/?id=64


 * 
  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

 


void setup() {
  
  Serial.begin(9600);// setup Serial Monitor to display information
  pinMode(7, OUTPUT);// connected to Relay 1
  pinMode(8, OUTPUT);// connected to Relay 2

}

void loop() {
  digitalWrite(8, LOW); // turn relay 2 OFF 
      Serial.print("Pin 8 LOW");
  digitalWrite(7,HIGH);// turn relay 1 ON
      Serial.println(" Pin 7 HIGH");
  delay(3000);// keep in relay 2 OFF and relay 1 On for 3 seconds
  digitalWrite(7, LOW);// turn relay 1 OFF
  digitalWrite(8,HIGH);// turn relay 2 ON
      Serial.print("Pin 7 LOW");
      Serial.println(" Pin 8 HIGH");
  delay(3000);// keep in relay 1 OFF and relay 2 On for 3 seconds


}
47-Control AC loads using a 2-channel relay and an Arduino
Ngôn ngữ: C++
/*
 * This is the Arduino code for a dual-channel 5V relay
 * to control turning ON or OFF AC or DC loads. You can control 2 different loads such as bulbs, a heater, or other machines.
 Watch the video instruction for this code: https://youtu.be/EclIomn_3dI
 
 *  * 
 * Written by Ahmad Shamshiri for Robojax Video
 * Date: December 26, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code, given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 


Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all materials, wiring diagrams, and libraries
all in one place. Purchase my course on Udemy.com: http://robojax.com/L/?id=62

If you find this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon: http://robojax.com/L/?id=63

or make a donation using PayPal: http://robojax.com/L/?id=64


 * 
  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

const int relay1Pin =7;// define pin for relay 1
const int relay2Pin =8; // define pin for relay 2


void setup() {
  
  Serial.begin(9600);// setup Serial Monitor to display information
  pinMode(relay1Pin, OUTPUT);// connected to Relay 1
  pinMode(relay2Pin, OUTPUT);// connected to Relay 2

}

void loop() {
  digitalWrite(relay2Pin, LOW); // turn relay 2 OFF 
      Serial.print("Pin 8 LOW");
  digitalWrite(relay1Pin,HIGH);// turn relay 1 ON
      Serial.println(" Pin 7 HIGH");
  delay(3000);// keep in relay 2 OFF and relay 1 On for 3 seconds
  digitalWrite(relay1Pin, LOW);// turn relay 1 OFF
  digitalWrite(relay2Pin,HIGH);// turn relay 2 ON
      Serial.print("Pin 7 LOW");
      Serial.println(" Pin 8 HIGH");
  delay(3000);// keep in relay 1 OFF and relay 2 On for 3 seconds


}

Nghĩ bạn có thể cần

Tài nguyên & tài liệu tham khảo

Chưa có tài nguyên nào.

Tập tin📁

Không có tệp nào khả dụng.