Search Code

Allegro ACS758 Current Sensor pẹlu LCD ati Idaabobo Overcurrent fun Arduino

Allegro ACS758 Current Sensor pẹlu LCD ati Idaabobo Overcurrent fun Arduino

Nínú ẹ̀kọ́ yìí, a óò kọ́ bí a ṣe lè lo Allegro ACS758 current sensor pẹ̀lú LCD láti fi hàn àwọn ìwọ̀n current àti láti ṣe ìdáàbòbò àṣejù current. Ètò yìí jẹ́ kí a lè ṣe àkíyèsí current àti láti ge asopọ̀ load láìsí ìrànwọ́ ènìyàn bí ó bá kọjá ìwọ̀n tí a ti yàn tẹ́lẹ̀. Iṣẹ́ yìí darapọ̀ mọ́ àwọn ẹ̀yà hardware àti software láti dá ètò ìṣàkóso current tí ó ṣiṣẹ́.

Nípa títẹ̀lé ìtọ́sọ́nà yìí, ìwọ yóò lè so àwọn ẹ̀yà pọ̀ dáradára àti lóye ìlànà programming tí ó wà lẹ́yìn kóòdù náà. Fún àlàyé tí ó ṣe pàtàkì nípa ojú, rí i pé o wo fídíò tí ó somọ́ (nínú fídíò ní 00:00).

Àlàyé Hardware

Àwọn ẹ̀yà pàtàkì nínú iṣẹ́ yìí ní ACS758 current sensor, LCD1602 display pẹ̀lú I2C interface, àti Arduino board. ACS758 sensor ń wọn current tí ó ń kọjá nínú rẹ̀ àti pé ó ń jáde voltage tí ó bá current mu. LCD1602 ń fi àwọn ìwọ̀n current àti àwọn ifiranṣẹ́ ipò hàn, nígbà tí Arduino ń ṣe àkóónú data náà àti ń ṣàkóso relay fún ìdáàbòbò àṣejù current.

ACS758 sensor ń ṣiṣẹ́ lórí ìlànà tí a pè ní Hall effect sensing, èyí tí ó jẹ́ kí ó lè wọn current láìsí ìfarakanra electrical tààrà. Voltage tí ó jáde ń yí padà nípa iye current tí ó ń kọjá, tí ó ń pèsè ọ̀nà àìléwu àti tí ó gbéṣẹ́ láti ṣe àkíyèsí àwọn ẹrù electrical.

Àwọn Àlàyé Datasheet

Olùṣe Allegro MicroSystems
Nọ́mbà ẹ̀yà ACS758
Logic/IO voltage 3.3V / 5V
Supply voltage 5V
Output current (fún ikanni kọ̀ọ̀kan) 200A tí ó pọ̀jù
Peak current (fún ikanni kọ̀ọ̀kan) 200A
PWM frequency ìtọ́sọ́nà N/A
Input logic thresholds 0.5 x VCC (bidirectional)
Voltage drop / RDS(on) / saturation N/A
Thermal limits 150°C
Package PCB mount
Àwọn àkíyèsí / àwọn oríṣi Ọ̀pọ̀lọpọ̀ model wà fún àwọn ìwọ̀n current oríṣiríṣi

 

  • Rí i pé o ṣe heat sinking tí ó tọ́ bí o bá ń ṣiṣẹ́ nítòsí àwọn ìwọ̀n tí ó pọ̀jù.
  • Lo àwọn decoupling capacitors láti mú voltage power supply dúró.
  • Rí i pé relay tí o ń lò lè gba ìwọ̀n load tí ó pọ̀jù.
  • Ṣọ́ra pẹ̀lú wiring láti yẹra fún short circuits.
  • Àwọn ìṣòro tí ó wọ́pọ̀ ní floating inputs; rí i pé gbogbo àwọn asopọ̀ mú ṣinṣin.
  • Ṣe àkíyèsí fún ìgbóná sensor nígbà tí o bá ń lò ó fún ìgbà pípẹ́.

Àwọn ẹ̀yà tí a nílò

  • ACS758 current sensor
  • 12V  100A relay
  • LCD1602 pẹ̀lú I2C (4 wires)
  • 2N2222 tàbí 2N3904 Transistor
  • 1k ohm 1/4W tàbí resistor agbára èyíkéyìí
  • Power Supply fún relay
  • Power supply fún load rẹ
  • Breadboard
  • Jumper wires

Àwọn Ìtọ́sọ́nà Wiring

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

Láti so Allegro ACS758 current sensor àti LCD1602 display pọ̀, bẹ̀rẹ̀ nípa sísopọ̀ ACS758 sensor. So VCC pin sensor náà pọ̀ mọ́ 5V pin lórí Arduino. GND pin yẹ kí ó sopọ̀ mọ́ ground pin lórí Arduino. S (signal) pin sensor náà yẹ kí ó sopọ̀ mọ́ analog input pin A0 lórí Arduino.

Lẹ́yìn náà, fún LCD1602, so VCC pin pọ̀ mọ́ 5V pin lórí Arduino àti GND pin mọ́ ground. SDA pin LCD yẹ kí ó sopọ̀ mọ́ A4 pin (SDA) lórí Arduino, nígbà tí SCL pin yẹ kí ó sopọ̀ mọ́ A5 pin (SCL) lórí Arduino. Níkẹyìn, so relay module pọ̀ mọ́ digital pin 2 fún ṣíṣàkóso load dá lórí àwọn ìwọ̀n current.

Àwọn Àpẹẹrẹ Kóòdù & Ìtúwò

Nínú kóòdù Arduino, a bẹ̀rẹ̀ nípa ṣíṣàlàyé àwọn idámọ̀ pàtàkì bíi VIN, èyí tí ó dúró fún analog input pin tí ó sopọ̀ mọ́ ACS758 sensor. relayPin ni a ṣètò fún ìṣàkóso relay, nígbà tí maxCurrent ń ṣàlàyé ìwọ̀n àṣejù fún ìdáàbòbò.

#define VIN A0 // ṣàlàyé Arduino pin A0 gẹ́gẹ́ bí voltage input (V in)
const int relayPin = 2; // ṣètò digital pin fún relay
const float maxCurrent = 15.00; // ṣètò current tí ó pọ̀jù

Iṣẹ́ setup() ń bẹ̀rẹ̀ LCD àti ṣètò relay pin gẹ́gẹ́ bí output. Ó tún ń tẹ̀ ifiranṣẹ́ káàbọ̀ sí LCD, tí ó ń sọ fún olùṣàmúlò nípa current sensor tí a ń lò.

void setup() {
    pinMode(relayPin, OUTPUT); // ṣètò relayPin gẹ́gẹ́ bí output
    Serial.begin(9600); // bẹ̀rẹ̀ serial monitor
    lcd.begin(); // bẹ̀rẹ̀ LCD
    lcd.backlight(); // Tan iná backlight
    lcd.print("Robojax");
}

Nínú iṣẹ́ loop(), a ń ka voltage láti sensor nígbà gbogbo àti ṣe ìṣirò current. Bí current bá kọjá ìwọ̀n tí ó pọ̀jù, relay yóò wọ́n láti ge asopọ̀ load. Ìlànà yìí ń rí i pé ètò náà dáàbò bò ara rẹ̀ láti àwọn ipò àṣejù current.

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // Ka voltage láti sensor
  float current = voltage / FACTOR; // Ṣe ìṣirò current
  if (current >= minCurrent) {
    if (current <= maxCurrent) {
      digitalWrite(relayPin, LOW); // pa relay náà fún ìgbà díẹ̀ láti gba current
    } else {
      digitalWrite(relayPin, HIGH); // tan relay náà láti ge asopọ̀ current
    }
  }
}

Ìfihàn / Ohun tí o yẹ kí o rí

Nigbati ohun gbogbo ba ti sopọ ati pe koodu naa ti gbe soke, LCD yoo ṣe afihan awọn iwọn lọwọlọwọ. Ti iwọn lọwọlọwọ ba kọja maxCurrent ti a ti ṣalaye, relay yoo ṣiṣẹ, ti yoo ge asopọ ẹrù naa. O le ṣe idanwo eyi nipa mimu iwọn lọwọlọwọ ẹrù pọ si diẹdiẹ ati ki o ṣe akiyesi awọn iyipada lori LCD ati ninu atẹle serial. Rii daju pe o yago fun awọn asopọ polarity ti o yipada, nitori eyi le ba awọn ẹya ara jẹ (ninu fidio ni 10:15).

Aworan

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

Ohun ti o le nilo

Fáìlìs📁

Fọọmu data (pdf)