Suchcode

Allegro ACS758 Stromsensor mit LCD und Überstromschutz für Arduino

Allegro ACS758 Stromsensor mit LCD und Überstromschutz für Arduino

In diesem Tutorial lernen wir, wie man den Allegro ACS758 Stromsensor zusammen mit einem LCD verwendet, um Strommesswerte anzuzeigen und einen Überstromschutz zu implementieren. Diese Konfiguration ermöglicht es uns, den Strom zu überwachen und die Last automatisch zu trennen, wenn er einen vordefinierten Grenzwert überschreitet. Das Projekt kombiniert sowohl Hardware- als auch Softwarekomponenten, um ein funktionsfähiges Stromüberwachungssystem zu erstellen.

Wenn Sie dieser Anleitung folgen, können Sie die Komponenten korrekt anschließen und die Programmierlogik hinter dem Code verstehen. Für eine anschaulichere Erklärung sollten Sie sich unbedingt das zugehörige Video ansehen (im Video bei 00:00).

Hardware erklärt

Zu den Schlüsselelementen dieses Projekts gehören der Allegro ACS758-Stromsensor, ein LCD1602-Display mit I2C-Schnittstelle und ein Arduino-Board. Der ACS758-Sensor misst den durch ihn fließenden Strom und liefert eine Spannung, die zum Strom proportional ist. Das LCD1602 zeigt die Stromwerte und Statusmeldungen an, während das Arduino die Daten verarbeitet und das Relais zum Überstromschutz steuert.

Der ACS758-Sensor arbeitet nach einem Prinzip namens Hall-Effekt-Sensorik, das es ihm ermöglicht, Strom ohne direkten elektrischen Kontakt zu messen. Die Ausgangsspannung ändert sich je nach der durchfließenden Stromstärke und bietet so eine sichere und effiziente Möglichkeit, elektrische Lasten zu überwachen.

Datenblattdetails

Hersteller Allegro MicroSystems
Teilenummer ACS758
Logik-/IO-Spannung 3.3V / 5V
Versorgungsspannung 5V
Ausgangsstrom (pro Kanal) 200 A max.
Spitzenstrom (pro Kanal) 200A
Hinweise zur PWM-Frequenz Nicht zutreffend
Schwellenwerte der Eingangslogik 0.5 x VCC (bidirektional)
Spannungsabfall / RDS(on)/ Sättigung Nicht zutreffend
Thermische Grenzwerte 150°C
Paket Leiterplattenmontage
Notizen / Varianten Mehrere Modelle für verschiedene Strombereiche verfügbar.

  • Stellen Sie bei Betrieb nahe den maximalen Grenzwerten eine ausreichende Wärmeableitung sicher.
  • Verwenden Sie Entkopplungskondensatoren, um die Versorgungsspannung zu stabilisieren.
  • Stellen Sie sicher, dass das verwendete Relais den maximalen Laststrom aushält.
  • Achten Sie beim Verdrahten darauf, Kurzschlüsse zu vermeiden.
  • Häufige Fallstricke sind offene Eingänge; stellen Sie sicher, dass alle Verbindungen fest sitzen.
  • Überwachen Sie den Sensor bei längerer Nutzung auf Überhitzung.

Benötigte Komponenten

  • ACS758-Stromsensor
  • 12V 100A Relais
  • LCD1602 mit I2C (4 Drähte)
  • 2N2222- oder 2N3904-Transistor
  • 1 kΩ 1/4 W oder ein beliebiger Leistungswiderstand
  • Stromversorgung für Relais
  • Stromversorgung für Ihre Last
  • Steckbrett
  • Jumperkabel

Verdrahtungsanleitung

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

Um den Allegro ACS758-Stromsensor und das LCD1602-Display zu verkabeln, beginnen Sie damit, den ACS758-Sensor anzuschließen. Verbinden Sie denVCCPin des Sensors an den 5V‑Pin am Arduino. DerGNDDer Pin sollte mit einem GND-Pin auf dem Arduino verbunden sein. DerS(Signal-)Pin des Sensors sollte mit dem analogen Eingangspin verbunden werden.A0auf dem Arduino.

Als Nächstes verbinden Sie für das LCD1602 dieVCCPin an den 5V-Pin des Arduino und denGNDam Boden festnageln. DerSDADer Pin des LCD sollte an den ... angeschlossen werdenA4Pin (SDA) am Arduino, während derSCLDer Pin sollte an dasA5Pin (SCL) am Arduino. Schließen Sie schließlich ein Relaismodul an den digitalen Pin an.2zur Steuerung der Last anhand der Strommesswerte.

Code-Beispiele und Schritt-für-Schritt-Anleitung

Im Arduino-Code beginnen wir damit, wichtige Bezeichner wieVIN, der den analogen Eingangspin darstellt, der mit dem ACS758-Sensor verbunden ist. DerrelayPinist für die Relaissteuerung eingestellt, währendmaxCurrentdefiniert die Schwelle für den Überstromschutz.

#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 maxCurrent = 15.00; // set maximum Current

Thesetup()Die Funktion initialisiert das LCD und richtet den Relais-Pin als Ausgang ein. Sie gibt außerdem eine Begrüßungsnachricht auf dem LCD aus, die den Benutzer über den aktuell verwendeten Stromsensor informiert.

void setup() {
    pinMode(relayPin, OUTPUT); // set relayPin as output
    Serial.begin(9600); // initialize serial monitor
    lcd.begin(); // initialize the LCD
    lcd.backlight(); // Turn on the blacklight
    lcd.print("Robojax");
}

In demloop()In dieser Funktion lesen wir kontinuierlich die Spannung vom Sensor und berechnen den Strom. Wenn der Strom den maximalen Grenzwert überschreitet, wird das Relais aktiviert, um die Last zu trennen. Diese Logik sorgt dafür, dass sich das System vor Überstrombedingungen schützt.

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // Read the voltage from sensor
  float current = voltage / FACTOR; // Calculate current
  if (current >= minCurrent) {
    if (current <= maxCurrent) {
      digitalWrite(relayPin, LOW); // turn the relay OFF to allow current
    } else {
      digitalWrite(relayPin, HIGH); // turn the relay ON to disconnect current
    }
  }
}

Demonstration / Was Sie erwartet

Sobald alles verkabelt ist und der Code hochgeladen wurde, zeigt das LCD die aktuellen Messwerte an. Wenn der Strom den definiertenmaxCurrent, wird das Relais anziehen und die Last trennen. Sie können dies testen, indem Sie den Laststrom schrittweise erhöhen und die Änderungen auf dem LCD sowie im seriellen Monitor beobachten. Achten Sie darauf, verpolte Anschlüsse zu vermeiden, da dies die Bauteile beschädigen kann (im Video bei 10:15).

Bilder

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

Dinge, die Sie vielleicht brauchen

Dateien📁

Datenblatt (pdf)