Luka Code

Kopelola Current na esaleli ya Allegro ACS758 Current Sensor na LCD1602 (I2C) mpo na Arduino

Kopelola Current na esaleli ya Allegro ACS758 Current Sensor na LCD1602 (I2C) mpo na Arduino


Na boyekoli oyo, tokoyekola ndenge ya komeka courant na sensor ya courant ACS758 ya Allegro mpe kotalisa ba lectures na LCD1602 na kozanga I2C. Setup oyo ezali utile mpo na ba applications ndenge na ndenge, lokola kotalela consommation ya puissance na ba circuits to koyangela usage ya batterie na ba appareils. Na suka ya projet oyo, okozala na système oyo ezali kopesa ba lectures ya courant na temps réel.

LCD1602-I2C display module with 4 wires

Sensor ya courant ACS758 ekoki komeka ba courants kino 200A, yango wana ezali idéal mpo na ba applications ya puissance ya likolo. Display LCD1602 ekolakisa courant na ampères elongo na voltage oyo sensor ya courant ezali kosala. Mpo na koyeba ba étapes nyonso, tala vidéo (na vidéo na 00:00) mpo na démonstration visuelle.

Matériel Explicado

Ba composants principaux ya projet oyo ezali sensor ya courant ACS758 ya Allegro mpe display LCD1602 na I2C. ACS758 ezali kosala na komeka champ magnétique oyo ezali kobima na courant oyo ezali koleka na conducteur. Ezali kopesa voltage ya sortie oyo ezali proportionnel na courant oyo ezali koleka, oyo ekoki kotángama na Arduino.

LCD1602 ezali display ya ba caractères 16x2 oyo ezali kosalela communication I2C, oyo ezali kopesa connexion mpe contrôle facile na ba pins ya données mibale kaka. Oyo ezali kokitisa motango ya ba fils oyo ezali nécessaires, mpe kosala processus ya câblage plus simple. Interface I2C ezali kopesa possibilité na ba appareils ebele ya kosolola na bus moko, mpe yango wana ezali choix versatile mpo na ba projets.

Détails ya Datasheet

FabricantAllegro Microsystems
Numéro ya partieACS758
Voltage ya logique/IO3.3V / 5V
Voltage ya alimentation5V
Courant ya sortie (na canal)200 A max
Courant ya pic (na canal)200 A
Guidance ya fréquence PWMN/A
Seuils ya logique ya entrée0.3V (bas), 2.7V (haut)
Chute ya voltage / RDS(on) / saturation0.5V max
Limites thermiqueskino 150°C
PackageTO-220
Notes / variantesOptions bidirectionnel mpe unidirectionnel

  • Kokamba que le heat sinking ezali malamu mpo na ba applications ya courant ya likolo.
  • Kokabola alimentation mpo na kokitisa bruit oyo ekoki kosala ete ba lectures ezala mabe.
  • Kosalela ba fils ya paire torsadée mpo na chemin ya courant mpo na kokitisa interférence.
  • Kokamba que voltage ya sortie oyo ekokani na courant zéro mpo na calibration.
  • Kotala polarité ntango okosalela ba sensors unidirectionnels.

Instructions ya Câblage

Arduino wiring for ACS758 with LCD

Mpo na câbler sensor ya courant ACS758 ya Allegro mpe display LCD1602, banda na connexion ya puissance mpe terre. Connecter pin VCC ya ACS758 na pin 5V na Arduino, mpe connecter pin GND na terre ya Arduino. Pin ya sortie ya signal (Vout) ya ACS758 esengeli kokangama na pin ya entrée analogique A0 na Arduino.

Na sima, mpo na display LCD1602, connecter pin VCC na pin 5V na Arduino mpe pin GND na terre. SDA (ligne ya données) ya LCD esengeli kokangama na pin A4 ya Arduino, mpe SCL (ligne ya horloge) esengeli kokangama na pin A5. Setup oyo ezali kopesa communication I2C kati na Arduino mpe LCD1602.

Ba Exemples ya Code & Explication

Sketch ya Arduino ebandi na koyangela pin ya entrée mpo na sensor ya courant. Variable VIN ezwami lokola A0, oyo ezali esika oyo sortie ya sensor ekotángama. Voltage ya alimentation mpe modèle ya ACS758 mpe ezwami. Sensibilité mpo na modèle oyo eponami ekompótama na kosalela tableau sensitivity.

#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC = 5.0; // supply voltage 5V or 3.3V
const int model = 2; // enter the model (see below)

Na fonction setup(), LCD ebandisami mpe message ya bienvenue elakisi. Backlight ezipamisami mpo na kotala malamu. Oyo ezali esika okoki kosala personnalisation ya message ya liboso ya display mpo na projet na yo.

void setup() {
    Serial.begin(9600); // initialize serial monitor
    lcd.begin(); // initialize the LCD
    lcd.backlight(); 
    lcd.print("Robojax");
    lcd.setCursor (0,1); // go to start of 2nd line 
    lcd.print("ACS758 Current Sensor"); 
    delay(2000); // delay for 2 seconds
    lcd.clear();  
}

Na fonction loop(), voltage oyo euti na sensor etángami mpe ekompótami mpo na kozwa courant. Soki voltage eleki limite ya coupure oyo ezwami, courant elakisi na moniteur ya série mpe na LCD. Soki courant moko te emonani, message elakisi oyo elobi "No Current". Oyo ezali kopesa possibilité ya surveillance ya courant na temps réel.

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // Read voltage from sensor
  float current = voltage / FACTOR;
  if (abs(voltage) > cutOff) {
    Serial.print("V: "); Serial.print(voltage, 3); // print voltage
    lcd.print(current); // display current on LCD
  } else {
    Serial.println("No Current"); // output when no current is detected
  }
  delay(500); // wait before next reading
}

Kokamba que otala explication ya code mobimba na vidéo (na vidéo na 01:30) mpo na détail ya chaque segment.

Démonstration / Nini Okoki Kozela

Tango ezipelwami, sisitemu ekosengela likambo ya courant oyo ezali koleka na sensor na LCD na ntango ya solo. Okoki komeka setup na yo na kosalela courant oyo eyebani mpe kotala ba lectures. Soki sensor emoni courant, ba valeurs ya voltage mpe courant ekobongisama na display. Soki courant ezali te, message "No Current" ekobima. Kozala na bokebi na ba connexions ya polarité oyo ebaluki, oyo ekoki komema na ba lectures ya mabe to kobebisa ba composants.

Images

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 with LCD
Arduino wiring for ACS758 with LCD
108-Allegro ACS758 current sensor with LCD1602 (I2C) for Arduino
Langue: C++
/*
 * 
 * Arduino Sketch for Allegro ACS758 Current Sensor with LCD1602 & I2C module
 * This sensor can measure current at a range of up to 200A.
 * It operates with 3.3V or 5V.
 * This sketch requires you to watch the following two 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
 * 
 * 
 * Written by Ahmad Shamshiri on Tuesday, June 19, 2018, at 20:40 in Ajax, Ontario, Canada
 * for Robojax.com
 * View the video instruction for this code at https://youtu.be/tug9wjCwDQA
 * 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 cut-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 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

// ======== 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 
    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 backlight 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(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");
  //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("Sense V: ");
  lcd.setCursor (9,1); // go to start of 2nd line
  lcd.print(voltage);
  lcd.setCursor (15,1); // go to start of 2nd line
  lcd.print("V");   
  lcd.backlight();
 //end of loopcode Robojax code ACS758 with LCD1602 and I2C


    
  }else{
    Serial.println("No Current");
  lcd.clear();    
  lcd.setCursor (0,0);    
  lcd.print("No Current");    
  }
  delay(500);
}

Mokili na bisika

Pas encore de ressources.

Fichiers📁

Fritzing File

Mabala a mangwe

  • Alegro ACS Current Library
    Arduino library for Allegro ACS current sensor modules. Provides functions to read current measurements from ACS712 and similar sensors.
    robojax_Alegro_ACS_Current_library.zip 0.02 MB