Luka Code

Kosakisa na ACS712 mpo na kolakisa courant na LCD1602 to LCD2004 na I2C

Kosakisa na ACS712 mpo na kolakisa courant na LCD1602 to LCD2004 na I2C

Na boyekoli oyo, tokoyekola ndenge ya kosalela sensor ya courant ya Allegro ACS712 mpo na komeka courant ya AC mpe DC mpe kolakisa ba lectures na LCD1602 to LCD2004 na kosalela I2C. Projet oyo ezali na tina mingi mpo na kosala suivi ya courant na ba applications ndenge na ndenge, mpe kopesa eloko ya komona oyo ezali kolakisa ba données ya courant na tango ya sika. Na suka, okozala na installation oyo ezali kosala malamu mpo na kolakisa ba lectures ya courant na LCD.

LCD1602-I2C display module with 4 wires

Mpo na koyeba malamu makambo ya wiring mpe code, sɔ́ngɔ́ na video na ba timestamps oyo ekomami (na video na 00:00).

Hardware Explication

Élément principal ya projet oyo ezali sensor ya courant ACS712, oyo ekoki komeka ba niveaux ya courant kino na 30A. Esalaka na kosalela effet Hall mpo na kobongola courant oyo elekaka na kati na yango na sortie ya tension oyo ezali na proportion. Sortie ya tension oyo ekoki kotángama na Arduino mpo na kokanisa niveau ya courant. Sensor ezali na ba pins misato mpo na connexion: VCC mpo na puissance, GND mpo na terre, mpe OUT mpo na signal ya tension.

LCD1602 to LCD2004 display ekoki kosangana na I2C, oyo epesaka possibilité ya kosala wiring mpe contrôle na ba pins mibale ya données (SDA mpe SCL) na ngonga ya puissance mpe terre. Oyo esalaka ete ezala pete mpo na kolakisa ba lectures ya courant na kobosana te ba connexions ebele.

Détails ya Datasheet

FabricantAllegro Microsystems
Numéro ya pièceACS712ELCTR-30A-T
Tension ya logique/IO4.5–5.5 V
Tension ya alimentation5 V
Courant ya sortie (na canal)30 A
Guidance ya fréquence PWMN/A
Seuils ya logique ya entrée0.5 V (sortie quiescente)
Chute ya tension / RDS(on) / saturation1.2 mΩ
Limites thermiques150 °C max
PackageTO-220

  • Kokamba ete chaleur ekende malamu mpo na ba courants oyo eleki 20A.
  • Kosalela gauge ya fil oyo ebongi (12 AWG mpo na 30A) mpo na kokima échauffement.
  • Kosangisa VCC na 5V mpe GND na terre mpo na fonctionnement malamu.
  • Kokamba ete pin OUT esangisami na pin ya entrée analogique na Arduino (ex., A0).
  • Koyeba ba différences ya sensibilité mpo na ba modèles ndenge na ndenge ya ACS712.
  • Kosalela ba condensateurs mpo na découplage ndenge ekomami na datasheet.

Instructions ya Wiring

Arduino wiring for Allegro ACS712 current sensor with LCD

Mpo na kosala wiring ya sensor ya courant ACS712 na Arduino mpe LCD, banda na kosangisa pin VCC ya ACS712 na pin 5V na Arduino. Sima, sangisa pin GND ya ACS712 na pin ya terre na Arduino. Pin OUT ya ACS712 esengeli kosangisama na pin analogique A0 na Arduino, epai signal ya tension ekotángama.

Mpo na LCD1602 to LCD2004, sangisa pin VCC na pin 5V mpe pin GND na terre. Pin SDA ya LCD esengeli kosangisama na pin SDA na Arduino (mbala mingi A4 na UNO), mpe pin SCL esengeli kosangisama na pin SCL na Arduino (mbala mingi A5 na UNO). Kamba ete ba connexions nyonso ezali ya kokanga malamu mpo na fonctionnement malamu.

Ba Exemples ya Code & Explication

Na code, tozali kopesa définition ya pin ya entrée analogique mpo na kotánga sortie ya sensor na #define VIN A0. Oyo epesaka biso possibilité ya kozwa référence na pin epai sensor esangisami na boumeli ya programme.

#define VIN A0 // définir pin A0 ya Arduino lokola entrée ya tension (V in)
const float VCC   = 5.0; // tension ya alimentation ezali kati na 4.5 na 5.5V. Mbala mingi 5V.

Na sima, tozali kosala configuration ya sensibilité kolanda modèle ya ACS712 oyo tozali kosalela. Ba valeurs ya sensibilité ebombami na tableau, mpo na kozwa yango pete kolanda choix ya modèle.

const int model = 2; // kokota numéro ya modèle (0, 1, to 2 mpo na 5A, 20A, to 30A)
float sensitivity[] = {0.185, 0.100, 0.066}; // ba valeurs ya sensibilité mpo na modèle na modèle

Na fonction setup(), tozali ko-initialiser moniteur série mpe display LCD. Oyo epesaka biso possibilité ya komona ba lectures ya courant na LCD mpe na moniteur série mpo na débogage.

void setup() {
    Serial.begin(9600); // initialiser moniteur série
    lcd.begin(); // initialiser LCD
    lcd.backlight(); // kopelisa backlight
    lcd.print("Robojax ACS712"); // kolakisa texte ya liboso
    delay(2000); // kozela mpo na secondes 2
}

Fonction loop() etángaka tension na sensor, akokanisaka courant kolanda sensibilité, mpe alakisiaka ba résultats ndenge esengeli. Soki courant eleki limite ya coupure oyo ekomami, elakisi valeur; soki te, elakisi ete courant moko te emonanaki.

Démonstration / Nini Okomona

Na ngonga ya kopelisa circuit, LCD esengeli kolakisa "Robojax ACS712" mpe na sima "Current: " elongo na valeur ya courant oyo emekami na ampères. Soki courant ezali na nse ya limite ya coupure, display ekolakisa "No Current." Kozala na bokebi ntango ozali komeka na ba courants ya makasi, mpo sensor ekoki kozala na moto (na video na 12:00).

Mpo na komeka installation, mata courant na kati na ACS712 mokemoke mpe tala ba changements na LCD mpe na moniteur série. Kamba ete courant eleka te ba limites oyo ekomami ya sensor mpo na kokima kobebisa yango.

Images

Allegro ACS712 DC/AC current sensor with LCD1602/LCD2004 I2C and Arduino code
Allegro ACS712 DC/AC Current sensor with LCD1602/LCD2004 I2C with Arduino Code
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
ACS712_in_series_with_load
ACS712_in_series_with_load
allegro_ACS712_module-1
allegro_ACS712_module-1
allegro_ACS712_module-2
allegro_ACS712_module-2
allegro_ACS712_module-4
allegro_ACS712_module-4
allegro_ACS712_module-0
allegro_ACS712_module-0
Arduino wiring for Allegro ACS712 current sensor with LCD
Arduino wiring for Allegro ACS712 current sensor with LCD
131-Allegro ACS712 DC/AC current sensor with LCD1602/LCD2004 I2C and Arduino code
Langue: C++
/*
 * 
 * Arduino Sketch for Allegro ACS712 Current Sensor with LCD1602/LCD2004 with I2C 
 * This sensor can measure current at a range of up to 30A.
 * The current is measured and displayed on LCD1602 or LCD2004.
 * The current is also displayed on the Serial monitor (click Tools->Serial monitor).
 * It operates with 5V.
 * Please watch the video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on July 14, 2018 at 07:02 in Ajax, Ontario, Canada
 * for Robojax.com
 * View the video instruction at https://youtu.be/kzXouSzvcp8
 * This code has been downloaded from Robojax.com
 
  * You must watch the following two videos before you can understand this:
 * 1- Introduction to ACS712 Current Sensor: https://www.youtube.com/watch?v=DVp9k3xu9IQ
 * 2- LCD1602 with I2C display: https://www.youtube.com/watch?v=q9YC_GVHy5A
 */
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC   = 5.0;// supply voltage is from 4.5 to 5.5V. Normally 5V.
const int model = 2;   // enter the model number (see below)

float cutOffLimit = 1.01;// set the current which, below that value, doesn't matter. Or set 0.5

/*
          "ACS712ELCTR-05B-T",// for model use 0
          "ACS712ELCTR-20A-T",// for model use 1
          "ACS712ELCTR-30A-T"// for model use 2  
Sensitivity array is holding the sensitivity of the ACS712
current sensors. Do not change. All values are from page 5 of the data sheet          
*/
float sensitivity[] ={
          0.185,// for ACS712ELCTR-05B-T
          0.100,// for ACS712ELCTR-20A-T
          0.066// for ACS712ELCTR-30A-T
     
         }; 


const float QOV =   0.5 * VCC;// set quiescent Output voltage of 0.5V
float voltage;// internal variable for voltage


// start of settings for LCD1602 with I2C
#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 settings for LCD1602 with I2C

void setup() {
    //Robojax.com ACS712 Current Sensor 
    Serial.begin(9600);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS712 Current Sensor");
  // initialize the LCD
  lcd.begin();  
  lcd.backlight();
  lcd.print("Robojax ACS712");
  lcd.setCursor(0,1);
  lcd.print("Demo"); 
  delay(2000);     
}

void loop() {
  

  //Robojax.com ACS712 Current Sensor with LCD1601
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage_raw - QOV + 0.012 ;// 0.000 is a value to make voltage zero when there is no current
  float current = voltage / sensitivity[model];
 
  if(abs(current) > cutOffLimit ){
    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 ACS712 with LCD1602 and I2C
    lcd.clear();
    lcd.setCursor (0,0); // set to line 1, char 0  
    lcd.print("Robojax ACS712");
    lcd.setCursor (0,1); // set to line 1, char 0  
    lcd.print("Current: ");
    lcd.setCursor (9,1); // go to start of 2nd line
    lcd.print(current);
    lcd.setCursor (14,1); // go to start of 2nd line
    lcd.print("A");
 
  }else{
    Serial.println("No Current");
    lcd.clear();
    lcd.setCursor (0,0); // set to line 1, char 0 
    lcd.print("No Current");     
  }
  delay(500);
}

Nko o na nki.

Mokili na bisika

Fichiers📁

Maktabat ya Arduino (zip)

Fiche technique (pdf)

Fritzing File