Other Arduino Codes and Videos by Robojax

Using ACS712 Display current on LCD1602 or LCD2004 with I2C Robojax.com

Allegro ACS712 DC/AC Current sensor with LCD1602/LCD2004 I2C with Arduino Code

This sensor can measure current at range of up to 30A depending on the model. The current is measured and displayed on LCD1602 or LCD2004. The current is also displayed on the Serial monitor (click Tools->Serial monitor) Watch video instruction on how to use ACS712.

Models and Current rating of Allegro ACS712 chip

  1. ACS712ELCTR-05B-T 5A current Sensor
  2. ACS712ELCTR-20B-T 20A current Sensor
  3. ACS712ELCTR-30B-T 30A current Sensor

 

/*
 * 
 * Arduino Sketch for Allegro ACS712 Current Sensor with LCD1602/LCD2004 with I2C 
 * this sensor can measure current at 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 video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on  July 14, 2018 at 07:02 at 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 2IC dislplay : 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 sensitivy of the  ACS712
current sensors. Do not change. All values are from page 5  of 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);
}