Tìm kiếm mã

Cảm biến dòng điện Allegro ACS758 với LCD và bảo vệ quá dòng cho Arduino

Cảm biến dòng điện Allegro ACS758 với LCD và bảo vệ quá dòng cho Arduino

Trong hướng dẫn này, chúng ta sẽ học cách sử dụng cảm biến dòng điện Allegro ACS758 với màn hình LCD để hiển thị chỉ số dòng điện và triển khai bảo vệ quá dòng. Thiết lập này cho phép chúng ta theo dõi dòng điện và tự động ngắt tải nếu nó vượt quá giới hạn định trước. Dự án kết hợp cả phần cứng và phần mềm để tạo ra một hệ thống giám sát dòng điện hoạt động.

Bằng cách làm theo hướng dẫn này, bạn sẽ có thể đấu dây các thành phần một cách chính xác và hiểu logic lập trình đằng sau mã. Để có giải thích trực quan hơn, hãy xem video liên quan (trong video tại 00:00).

Giải thích phần cứng

Các thành phần chính trong dự án này bao gồm cảm biến dòng điện Allegro ACS758, màn hình LCD1602 có giao diện I2C và bo mạch Arduino. Cảm biến ACS758 đo dòng điện chạy qua nó và xuất ra điện áp tỷ lệ với dòng điện. LCD1602 hiển thị chỉ số dòng điện và thông báo trạng thái, trong khi Arduino xử lý dữ liệu và điều khiển rơ-le để bảo vệ quá dòng.

Cảm biến ACS758 hoạt động dựa trên nguyên lý cảm biến hiệu ứng Hall, cho phép nó đo dòng điện mà không cần tiếp xúc điện trực tiếp. Điện áp đầu ra thay đổi dựa trên lượng dòng điện đi qua, cung cấp một cách an toàn và hiệu quả để giám sát tải điện.

Chi tiết từ bảng dữ liệu

Nhà sản xuất Allegro MicroSystems
Số bộ phận ACS758
Điện áp logic/IO 3.3V / 5V
Điện áp cung cấp 5V
Dòng điện đầu ra (mỗi kênh) 200A tối đa
Dòng điện đỉnh (mỗi kênh) 200A
Hướng dẫn tần số PWM Không áp dụng
Ngưỡng logic đầu vào 0.5 x VCC (hai chiều)
Sụt áp / RDS(on) / bão hòa Không áp dụng
Giới hạn nhiệt 150°C
Kiểu đóng gói Gắn trên PCB
Ghi chú / biến thể Có nhiều mẫu cho các dải dòng điện khác nhau

 

  • Đảm bảo tản nhiệt thích hợp nếu hoạt động gần mức tối đa.
  • Sử dụng tụ điện tách rời để ổn định điện áp nguồn.
  • Xác minh rằng rơ-le được sử dụng có thể chịu được dòng tải tối đa.
  • Thận trọng khi đấu dây để tránh đoản mạch.
  • Các lỗi thường gặp bao gồm đầu vào nổi; đảm bảo tất cả các kết nối đều chắc chắn.
  • Theo dõi hiện tượng quá nhiệt của cảm biến khi sử dụng kéo dài.

Linh kiện cần thiết

  • Cảm biến dòng điện ACS758
  • Rơ-le 12V 100A
  • LCD1602 có I2C (4 dây)
  • Transistor 2N2222 hoặc 2N3904
  • Điện trở 1k ohm 1/4W hoặc bất kỳ điện trở công suất nào
  • Nguồn điện cho rơ-le
  • Nguồn điện cho tải của bạn
  • Breadboard
  • Dây jumper

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

Arduino wiring for ACS758 current sensor with LCD and protection relay
Arduino wiring for ACS758 current sensor with LCD and protection relay

Để đấu dây cảm biến dòng điện Allegro ACS758 và màn hình LCD1602, hãy bắt đầu bằng cách kết nối cảm biến ACS758. Kết nối chân VCC của cảm biến với chân 5V trên Arduino. Chân GND nên được kết nối với chân nối đất trên Arduino. Chân S (tín hiệu) của cảm biến nên được kết nối với chân đầu vào analog A0 trên Arduino.

Tiếp theo, đối với LCD1602, kết nối chân VCC với chân 5V trên Arduino và chân GND với nối đất. Chân SDA của LCD nên kết nối với chân A4 (SDA) trên Arduino, trong khi chân SCL nên kết nối với chân A5 (SCL) trên Arduino. Cuối cùng, kết nối một mô-đun rơ-le với chân kỹ thuật số 2 để điều khiển tải dựa trên chỉ số dòng điện.

Ví dụ mã & hướng dẫn chi tiết

Trong mã Arduino, chúng ta bắt đầu bằng cách định nghĩa các định danh chính như VIN, đại diện cho chân đầu vào analog được kết nối với cảm biến ACS758. relayPin được đặt để điều khiển rơ-le, trong khi maxCurrent định nghĩa ngưỡng cho bảo vệ quá dòng.

#define VIN A0 // định nghĩa chân A0 của Arduino là đầu vào điện áp (V in)
const int relayPin = 2; // đặt một chân kỹ thuật số cho rơ-le
const float maxCurrent = 15.00; // đặt dòng điện tối đa

Hàm setup() khởi tạo LCD và thiết lập chân rơ-le làm đầu ra. Nó cũng in một thông báo chào mừng trên LCD, thông báo cho người dùng về cảm biến dòng điện đang được sử dụng.

void setup() {
    pinMode(relayPin, OUTPUT); // đặt relayPin làm đầu ra
    Serial.begin(9600); // khởi tạo màn hình nối tiếp
    lcd.begin(); // khởi tạo LCD
    lcd.backlight(); // bật đèn nền
    lcd.print("Robojax");
}

Trong hàm loop(), chúng ta liên tục đọc điện áp từ cảm biến và tính toán dòng điện. Nếu dòng điện vượt quá giới hạn tối đa, rơ-le được kích hoạt để ngắt tải. Logic này đảm bảo hệ thống tự bảo vệ khỏi các điều kiện quá dòng.

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // đọc điện áp từ cảm biến
  float current = voltage / FACTOR; // tính toán dòng điện
  if (current >= minCurrent) {
    if (current <= maxCurrent) {
      digitalWrite(relayPin, LOW); // tắt rơ-le để cho phép dòng điện
    } else {
      digitalWrite(relayPin, HIGH); // bật rơ-le để ngắt dòng điện
    }
  }
}

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

Khi mọi thứ đã được kết nối và mã được tải lên, màn hình LCD sẽ hiển thị các chỉ số hiện tại. Nếu dòng điện vượt quá maxCurrent đã định nghĩa, rơ-le sẽ kích hoạt, ngắt kết nối tải. Bạn có thể kiểm tra điều này bằng cách tăng dần dòng điện tải và quan sát các thay đổi trên LCD cũng như trong màn hình nối tiếp. Hãy đảm bảo tránh kết nối ngược cực, vì điều này có thể làm hỏng các linh kiện (trong video tại 10:15).

Hình ảnh

LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
ACS758-sensor-0
ACS758-sensor-0
ACS758-sensor-1
ACS758-sensor-1
ACS758-sensor-3
ACS758-sensor-3
ACS758-sensor-4
ACS758-sensor-4
Arduino wiring for ACS758 current sensor with LCD and protection relay
Arduino wiring for ACS758 current sensor with LCD and protection relay
111-Arduino Code for Allegro ACS758 Current Sensor with LCD160
Ngôn ngữ: C++
/*
 * 
 * Arduino Sketch for Allegro ACS758 Current Sensor with LCD1602 & I2C module and current protection
 * This sensor can measure current at a range of up to 200A. It has overcurrent protection with a relay to disconnect the load if 
 * the current reaches beyond the limit.
 * It operates with 3.3V or 5V.
 * This sketch requires you to watch the following 2 videos before using this code:
 * 1- ACS758 Sensor https://www.youtube.com/watch?v=SiHfjzcqnU4
 * 2- LCD1602 with I2C https://www.youtube.com/watch?v=q9YC_GVHy5A
 * 3- Combined 1 and 2 in one video https://www.youtube.com/watch?v=tug9wjCwDQA
 * 4- Allegro ACS with Robojax Library (latest video and code) https://youtu.be/sB6EULTix2k
 * 
 * Written by Ahmad Shamshiri on Tuesday, June 26, 2018 at 17:56 in Ajax, Ontario, Canada
 * for Robojax.com
 * You can watch a detailed video on the ACS758 Current sensor at: https://youtu.be/SiHfjzcqnU4
 * This code has been explained in this video: https://youtu.be/GE4I10IZ1jY
 * This code has been downloaded from Robojax.com
 */
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const int relayPin = 2;// set a digital pin for relay
const float VCC   = 5.0;// supply voltage 5V or 3.3V. If using PCB, set to 5V only.
const int model = 2;   // enter the model (see below)

const float maxCurrent = 15.00;// set maximum Current 
int maxCurrentWait = 6000;// wait time before current is connected

float minCurrent = 1.00;// reading cutt-off current. 1.00 is 1 Amper

/*
          "ACS758LCB-050B",// for model use 0
          "ACS758LCB-050U",// for model use 1
          "ACS758LCB-100B",// for model use 2
          "ACS758LCB-100U",// for model use 3
          "ACS758KCB-150B",// for model use 4
          "ACS758KCB-150U",// for model use 5
          "ACS758ECB-200B",// for model use 6
          "ACS758ECB-200U"// for model use  7   
The sensitivity array holds the sensitivity of the ACS758
current sensors. Do not change.          
*/
float sensitivity[] ={
          40.0,// for ACS758LCB-050B
          60.0,// for ACS758LCB-050U
          20.0,// for ACS758LCB-100B
          40.0,// for ACS758LCB-100U
          13.3,// for ACS758KCB-150B
          16.7,// for ACS758KCB-150U
          10.0,// for ACS758ECB-200B
          20.0,// for ACS758ECB-200U     
         }; 

/*         
 *   Quiescent output voltage is a factor of VCC that appears at the output       
 *   when the current is zero. 
 *   For bidirectional sensors it is 0.5 x VCC
 *   For unidirectional sensors it is 0.12 x VCC
 *   For model ACS758LCB-050B, the B at the end represents Bidirectional (polarity doesn't matter)
 *   For model ACS758LCB-100U, the U at the end represents Unidirectional (polarity must match)
 *    Do not change.
 */
float quiescent_Output_voltage [] ={
          0.5,// for ACS758LCB-050B
          0.12,// for ACS758LCB-050U
          0.5,// for ACS758LCB-100B
          0.12,// for ACS758LCB-100U
          0.5,// for ACS758KCB-150B
          0.12,// for ACS758KCB-150U
          0.5,// for ACS758ECB-200B
          0.12,// for ACS758ECB-200U            
          };
const float FACTOR = sensitivity[model]/1000;// set sensitivity for selected model
const float QOV =   quiescent_Output_voltage [model] * VCC;// set quiescent Output voltage for selected model
float voltage;// internal variable for voltage


// ======== start of LCD1602 with i2C settings
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ======= END of  LCD1602 with i2C settings
void setup() {
    //Robojax.com ACS758 Current Sensor 
    pinMode(relayPin,OUTPUT);// set relayPin as output
    Serial.begin(9600);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS758 Current Sensor");
    Serial.println("with LCD1602 & I2C");    
    // initialize the LCD, 
    lcd.begin();   
  // Turn on the blacklight and print a message.
  lcd.backlight(); 
    lcd.clear();
  lcd.print("Robojax");
  lcd.setCursor (0,1); // go to start of 2nd line 
  lcd.print("ACS758 Current Sensor"); 
  delay(2000); 
  lcd.clear();  
}

void loop() {
  //Robojax code ACS758 with LCD1602 and I2C
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage_raw - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  float current = voltage / FACTOR;
  if( current >= minCurrent){
     if(current <= maxCurrent)
     {
              Serial.print("Current Limit: ");
              Serial.print(maxCurrent,3);// print voltage with 3 decimal places
              Serial.print("A, I: ");
              Serial.print(current,2); // print the current with 2 decimal places
              Serial.println("A");
              //start of loop Robojax code ACS758 with LCD1602 and I2C
              lcd.clear();
              lcd.setCursor (0,0); // set to line 1, char 0  
              lcd.print("Current: ");
              lcd.setCursor (9,0); // go to start of 2nd line
              lcd.print(current);
              lcd.setCursor (15,0); // go to start of 2nd line
              lcd.print("A");
            
              lcd.setCursor (0,1);    
              lcd.print("I Limit: ");
              lcd.setCursor (9,1); // go to start of 2nd line
              lcd.print(maxCurrent);
              lcd.setCursor (15,1); // go to start of 2nd line
              lcd.print("A");   
              lcd.backlight();
             //end of loopcode Robojax code ACS758 with LCD1602 and I2C

              digitalWrite(relayPin,LOW);// turn the relay OFF to allow the current.
     }else{
      // the lines bellow will execute if current reaches above the maxCurrent value
              digitalWrite(relayPin,HIGH);// turn the relay ON to disconnect the current.
              
              Serial.print("Max Reached:");
              Serial.print(maxCurrent,3);// print the maxCurrent
              Serial.println("A");              
              Serial.print("Disconnected ");

              //start of loop Robojax code ACS758 with LCD1602 and I2C
              lcd.clear();
              lcd.setCursor (0,0); // set to line 1, char 0  
              lcd.print("I Max: ");
              lcd.setCursor (8,0); // go to start of 2nd line
              lcd.print(maxCurrent);
              lcd.setCursor (15,0); // go to start of 2nd line
              lcd.print("A");
            
              lcd.setCursor (0,1);    
              lcd.print("Disconnected");    
              lcd.backlight();
             //end of loopcode Robojax code ACS758 with LCD1602 and I2C 
             delay(maxCurrentWait );// wait for maxCurrentWait  seconds     
     }
    
  }else{
    Serial.println("No Current");
  lcd.clear();    
  lcd.setCursor (0,0);    
  lcd.print("No Current");
  digitalWrite(relayPin,LOW);// turn the relay OFF to allow the current.
          
  }
  delay(500);
}

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

Tập tin📁

Bảng dữ liệu (pdf)