Search Code

如何使用Allegro ACS758电流传感器配合Arduino测量50A至200A电流

如何使用Allegro ACS758电流传感器配合Arduino测量50A至200A电流


喺高容量應用入面,而家嘅測量可以好有挑戰性,但係 Allegro ACS758 電流傳感器簡化咗呢個任務。呢個傳感器可以處理由 50A 到 200A 嘅電流水平,為各種項目提供可靠嘅解決方案。喺呢個教學入面,我哋會探討點樣將 ACS758 連接到 Arduino,並且準確噉讀取電流值。
呢個項目嘅成果係可以量度流經負載嘅電流,並且將結果顯示喺串行監視器上面。ACS758 使用霍爾效應感測技術,將電流轉換成一個同電流成比例嘅電壓,而 Arduino 可以讀取呢個電壓,令到監測電流水平變得容易。記得睇吓條片攞多啲見解(喺片入面 01:15)。

硬件解釋

呢個項目嘅主要元件係 Allegro ACS758 電流傳感器。呢個傳感器係基於霍爾效應嘅原理運作,令到佢可以量度流經導體嘅電流所產生嘅磁場。佢會產生一個同電流成比例嘅輸出電壓,令到 Arduino 可以讀取同解釋呢啲數值。 ACS758 有幾個唔同嘅型號,而「100B」表示佢可以量度高達 100A。佢具備雙向電流測量功能,無論電流方向係點,都可以準確讀取。呢個傳感器需要 3.3V 或者 5V 嘅電源供應,用嚟供電畀佢內部嘅電路,包括一個處理霍爾效應信號嘅運算放大器。

數據表詳情

製造商Allegro Microsystems
零件編號ACS758LCB-100B
邏輯/IO 電壓3.3 V / 5 V
供應電壓4.5 V - 5.5 V
輸出電流(每通道)100 A
峰值電流(每通道)200 A
PWM 頻率指引唔適用
輸入邏輯閾值兼容 TTL
電壓降 / RDS(on) / 飽和0.1 V @ 100 A
熱限制工作溫度:-40 °C 至 125 °C
封裝5 針封裝
備註 / 型號有唔同電流額定值可供選擇(50A、100A、150A、200A)

  • 確保接線正確,避免因為電阻而產生電壓降。
  • 喺高電流應用入面,使用合適粗幼嘅電線,防止過熱。
  • 將傳感器保持喺指定嘅溫度範圍內,先至可以準確讀數。
  • 根據所用嘅具體型號校準傳感器輸出。
  • 如果有需要,可以考慮使用濾波電容嚟穩定讀數。

接線指示

Arduino-wiring-for-ACS758-Current-sensor
要將 ACS758 電流傳感器接線到 Arduino,首先將傳感器嘅 VCC 針腳連接到 Arduino 嘅 5V 輸出。跟住,將傳感器嘅 GND 針腳連接到 Arduino 嘅接地。傳感器嘅輸出(提供同量度電流成比例嘅電壓)可以連接到 Arduino 上面嘅模擬輸入針腳,通常標示為 A0。 確保你想量度嘅負載同傳感器串聯連接。電流路徑應該流經傳感器,等佢可以準確量度流過嘅電流。傳感器有兩個電流輸入針腳;將你負載嘅正極線連接到其中一個針腳,而另一個針腳就連接到你電源嘅正極端子。電源嘅負極就應該連接到負載嘅負極端子。呢個設置令到傳感器可以量度流向負載嘅電流。

代碼示例同講解

用嚟讀取 ACS758 傳感器數值嘅 Arduino 代碼好直接。下面係進階代碼嘅節錄,用嚟初始化傳感器同讀取電壓:

#define VIN A0 // 將 Arduino 針腳 A0 定義為電壓輸入(V in)
const float VCC = 5.0; // 供應電壓
const float FACTOR = 20.0 / 1000; // ACS758-100B 嘅靈敏度
呢段代碼定義咗模擬輸入針腳,並且設定供應電壓。佢亦都根據所用型號計算靈敏度因數,呢個對於準確讀取電流嚟講好重要。 代碼入面另一個重要部分係 loop 函數,佢會持續讀取傳感器嘅電壓:

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // 從傳感器讀取電壓
  float current = (voltage_raw - (VCC * 0.5)) / FACTOR; // 計算電流
  Serial.print("Current: ");
  Serial.println(current, 2); // 打印電流值
}
喺呢部分,代碼會讀取傳感器嘅電壓,根據靜態輸出電壓調整,然後用定義咗嘅靈敏度因數計算電流。電流值跟住會打印到串行監視器。 如果想完整了解代碼結構同功能,請參考文章下面載入嘅完整代碼。

示範 / 預期效果

一旦所有嘢接線正確,而且代碼已經上載,你應該會喺串行監視器上面見到電流值顯示出嚟。讀數會按照代碼入面嘅設定,每半秒更新一次。如果電流低過代碼入面設定嘅截止限制,你就會見到「No Current」嘅訊息顯示。呢個截止功能有助於過濾噪音同電流讀數嘅細微變化。 要小心反接極性嘅連接,因為咁樣會整壞傳感器。永遠確保傳感器正確噉同負載串聯接線,並且監測輸出嚟確認讀數準確。條片提供咗額外嘅背景同示範(喺片入面 12:30)。

圖片

Allegro ACS758 current sensor with Arduino
Allegro ACS758 Current Sensor with Arduino
Arduino-wiring-for-ACS758-Current-sensor
Arduino-wiring-for-ACS758-Current-sensor
ACS758-sensor-0
ACS758-sensor-0
ACS758-sensor-1
ACS758-sensor-1
ACS758-sensor-3
ACS758-sensor-3
ACS758-sensor-4
ACS758-sensor-4
ACS758-sensor-5-schematic
ACS758-sensor-5-schematic
100-Advanced Arduino code for the Allegro ACS758 current sensor
語言: C++
/*
 * 
 * Arduino Sketch for Allegro ACS758 Current Sensor (Advanced)
 * This sensor can measure current at a range of up to 200A.
 * It operates with 3.3V or 5V.
 * Please watch the video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on Saturday, May 27, 2018 at 13:19 in Ajax, Ontario, Canada
 * for Robojax.com
 * View the video instruction at
 * This code has been downloaded from Robojax.com
 */
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
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)

float cutOffLimit = 1.00;// reading cutoff current. 1.00 is 1 Ampere

/*
          "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   
          // sensitivity array is holding 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
float cutOff = FACTOR/cutOffLimit;// convert current cut off to mV

void setup() {
    //Robojax.com ACS758 Current Sensor 
    Serial.begin(9600);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS758 Current Sensor");
}

void loop() {
  //Robojax.com ACS758 Current Sensor 
  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(abs(voltage) > cutOff ){
    Serial.print("V: ");
    Serial.print(voltage,3);// print voltage with 3 decimal places
    Serial.print("V, I: ");
    Serial.print(current,2); // print the current with 2 decimal places
    Serial.println("A");
  }else{
    Serial.println("No Current");
  }
  delay(500);
}
101-Arduino code for Allegro ACS758 current sensor (basic)
語言: C++
/*
 * Arduino Sketch for Allegro ACS758 Current Sensor (Basic Simple)
 * This sensor can measure current at a range of up to 200A.
 * It operates with 3.3V or 5V (the module works with 5V, the sensor can work with 3.3V or 5V).
 * Please watch the video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on Saturday, May 26, 2018 at 7:05 PM in Ajax, Ontario, Canada
 * for Robojax.com
 * View the video instruction at https://youtu.be/SiHfjzcqnU4
 * This code has been downloaded from Robojax.com
 */
#define VIN A0
const float vcc    = 5.00;// supply voltage 5V or 3.3V
const float factor = 0.02;// 20mV/A is the factor

float voltage;

void setup() {
    //Robojax.com ACS758 Current Sensor 
    Serial.begin(9600);
    Serial.println("Robojax Tutorial");
    Serial.println("ACS758 Current Tester");
    Serial.println("Basic Simple Code");
}

void loop() {
  //Robojax.com ACS758 Current Sensor 
  voltage =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage - (vcc * 0.5) + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  float current = voltage / factor;
  Serial.print("V: ");
  Serial.print(voltage,3);
  Serial.print("V, I: ");
  Serial.print(current,2); Serial.println("A");
  delay(500);
}
102-Advanced Arduino code for four Allegro ACS758 current sensors
語言: C++
/*
 * 
 * Arduino Sketch for 4 modules Allegro ACS758 Current Sensor (Advanced)
 * This sensor can measure current at a range of up to 200A.
 * It operates with 3.3V or 5V.
 * Please watch the video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on August 4, 2018 at 13:19 in Ajax, Ontario, Canada
 * for Robojax.com in request from Ross M. from YouTube video https://youtu.be/SiHfjzcqnU4 
 * View the video instruction at
 * This code has been downloaded from Robojax.com
 */
#define VIN1 A0 // define the Arduino pin A0 as voltage input (V in)
#define VIN2 A1 
#define VIN3 A2 
#define VIN4 A3 

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)

float cutOffLimit = 1.00;// reading cutoff 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   
sensitivity array is holding 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 voltage1;// internal variable for voltage1
float voltage2;// internal variable for voltage2
float voltage3;// internal variable for voltage3
float voltage4;// internal variable for voltage4

float cutOff = FACTOR/cutOffLimit;// convert current cut off to mV

void setup() {
    //Robojax.com ACS758 Current Sensor 
    Serial.begin(9600);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("Four ACS758 Current Sensors");
}

void loop() {
  //Robojax.com ACS758 Current Sensor 
  float voltage_raw1 =   (5.0 / 1023.0)* analogRead(VIN1);// Read the voltage from sensor
  float voltage_raw2 =   (5.0 / 1023.0)* analogRead(VIN2);// Read the voltage from sensor
  float voltage_raw3 =   (5.0 / 1023.0)* analogRead(VIN3);// Read the voltage from sensor
  float voltage_raw4 =   (5.0 / 1023.0)* analogRead(VIN4);// Read the voltage from sensor
  
  voltage1 =  voltage_raw1 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  voltage2 =  voltage_raw2 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  voltage3 =  voltage_raw3 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  voltage4 =  voltage_raw4 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  
  float current1 = voltage1 / FACTOR;
  float current2 = voltage2 / FACTOR;
  float current3 = voltage3 / FACTOR;
  float current4 = voltage4 / FACTOR;
  
  if(abs(voltage1) > cutOff ){ //Corrected abs(voltage) to abs(voltage1)

    Serial.print("I1: ");
    Serial.print(current1,2); // print the current with 2 decimal places
    Serial.println("A");
	
    Serial.print("I2: ");
    Serial.print(current2,2); // print the current with 2 decimal places
    Serial.println("A");

    Serial.print("I3: ");
    Serial.print(current3,2); // print the current with 2 decimal places
    Serial.println("A");
	
    Serial.print("I4: ");
    Serial.print(current4,2); // print the current with 2 decimal places
    Serial.println("A");	
	
  }else{
    Serial.println("No Current");
  }
  delay(500);
}

資源與參考資料

暫時冇資源。

文件📁

其他文件