Using an ACS712 to Display Current on an LCD1602 or LCD2004 with I2C

Using an ACS712 to Display Current on an LCD1602 or LCD2004 with I2C

In this tutorial, we will learn how to use the Allegro ACS712 current sensor to measure both AC and DC current and display the readings on an LCD1602 or LCD2004 using I2C. This project is particularly useful for monitoring current in various applications, providing a visual display of real-time current data. By the end, you will have a working setup that can accurately show current readings on an LCD.

LCD1602-I2C display module with 4 wires

For clarification on the wiring and code, be sure to check the video at the specified timestamps (in video at 00:00).

Hardware Explained

The main component of this project is the ACS712 current sensor, which can measure current levels up to 30A. It operates by utilizing the Hall effect to convert the current flowing through it into a proportional voltage output. This voltage output can be read by the Arduino to calculate the current level. The sensor has three pins for connection: VCC for power, GND for ground, and OUT for the voltage signal.

The LCD1602 or LCD2004 display connects via I2C, which allows for easier wiring and control using only two data pins (SDA and SCL) in addition to power and ground. This makes it simple to show current readings without cluttering the wiring with multiple connections.

Datasheet Details

ManufacturerAllegro Microsystems
Part numberACS712ELCTR-30A-T
Logic/IO voltage4.5–5.5 V
Supply voltage5 V
Output current (per channel)30 A
PWM frequency guidanceN/A
Input logic thresholds0.5 V (quiescent output)
Voltage drop / RDS(on) / saturation1.2 mΩ
Thermal limits150 °C max
PackageTO-220

  • Ensure proper heat dissipation for currents above 20A.
  • Use appropriate wire gauge (12 AWG for 30A) to avoid overheating.
  • Connect VCC to 5V and GND to ground for proper operation.
  • Ensure the OUT pin is connected to an analog input pin on the Arduino (e.g., A0).
  • Be aware of the sensitivity differences for various ACS712 models.
  • Use capacitors for decoupling as specified in the datasheet.

Wiring Instructions

Arduino wiring for Allegro ACS712 current sensor with LCD

To wire the ACS712 current sensor with the Arduino and LCD, start by connecting the VCC pin of the ACS712 to the 5V pin on the Arduino. Next, connect the GND pin of the ACS712 to a ground pin on the Arduino. The OUT pin of the ACS712 should be connected to the analog pin A0 on the Arduino, where the voltage signal will be read.

For the LCD1602 or LCD2004, connect the VCC pin to the 5V pin and the GND pin to ground. The SDA pin of the LCD should be connected to the SDA pin on the Arduino (usually A4 on an UNO), and the SCL pin should be connected to the SCL pin on the Arduino (usually A5 on an UNO). Make sure all connections are secure to ensure proper functionality.

Code Examples & Walkthrough

In the code, we define the analog input pin for reading the sensor output with #define VIN A0. This allows us to easily reference the pin where the sensor is connected throughout the program.

#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.

Next, we set up the sensitivity based on the model of the ACS712 we are using. The sensitivity values are stored in an array, allowing for easy access based on the model selection.

const int model = 2; // enter the model number (0, 1, or 2 for 5A, 20A, or 30A)
float sensitivity[] = {0.185, 0.100, 0.066}; // sensitivity values for each model

In the setup() function, we initialize the serial monitor and the LCD display. This allows us to view the current readings both on the LCD and through the serial monitor for debugging.

void setup() {
    Serial.begin(9600); // initialize serial monitor
    lcd.begin(); // initialize the LCD
    lcd.backlight(); // turn on the backlight
    lcd.print("Robojax ACS712"); // display initial text
    delay(2000); // wait for 2 seconds
}

The loop() function reads the voltage from the sensor, calculates the current based on the sensitivity, and displays the results accordingly. If the current exceeds a specified cutoff limit, it displays the value; otherwise, it indicates that there is no current detected.

Demonstration / What to Expect

Upon powering the circuit, the LCD should display "Robojax ACS712" followed by "Current: " along with the measured current value in amperes. If the current is below the cutoff limit, the display will show "No Current." Be cautious when testing with high currents, as the sensor may get hot (in video at 12:00).

To test the setup, gradually increase the current through the ACS712 and observe the changes on the LCD and the serial monitor. Ensure that the current does not exceed the rated limits of the sensor to avoid damage.

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
Language: C++
Copied!

Things you might need

Resources & references

Files📁

Arduino Libraries (zip)

Datasheet (pdf)

Fritzing File