Allegro ACS758 Current Sensor with LCD and Overcurrent Protection for Arduino
In this tutorial, we will learn how to use the Allegro ACS758 current sensor with an LCD to display current readings and implement overcurrent protection. This setup allows us to monitor current and disconnect the load automatically if it exceeds a predefined limit. The project combines both hardware and software components to create a functional current monitoring system.

By following this guide, you will be able to wire the components correctly and understand the programming logic behind the code. For a more visual explanation, be sure to check out the associated video (in video at 00:00).
Hardware Explained
The key components in this project include the Allegro ACS758 current sensor, an LCD1602 display with an I2C interface, and an Arduino board. The ACS758 sensor measures current flowing through it and outputs a voltage proportional to the current. The LCD1602 displays the current readings and status messages, while the Arduino processes the data and controls the relay for overcurrent protection.
The ACS758 sensor operates on a principle called Hall effect sensing, which allows it to measure current without direct electrical contact. The output voltage changes based on the amount of current passing through, providing a safe and efficient way to monitor electrical loads.
Datasheet Details
| Manufacturer | Allegro MicroSystems |
|---|---|
| Part number | ACS758 |
| Logic/IO voltage | 3.3V / 5V |
| Supply voltage | 5V |
| Output current (per channel) | 200A max |
| Peak current (per channel) | 200A |
| PWM frequency guidance | N/A |
| Input logic thresholds | 0.5 x VCC (bidirectional) |
| Voltage drop / RDS(on) / saturation | N/A |
| Thermal limits | 150°C |
| Package | PCB mount |
| Notes / variants | Multiple models available for different current ranges |
- Ensure proper heat sinking if operating close to maximum ratings.
- Use decoupling capacitors to stabilize power supply voltage.
- Verify that the relay used can handle the maximum load current.
- Be cautious with wiring to avoid short circuits.
- Common pitfalls include floating inputs; ensure all connections are secure.
- Monitor for overheating of the sensor during prolonged use.
Components needed
- ACS758 current sensor
- 12V 100A relay
- LCD1602 with I2C (4 wires)
- 2N2222 or 2N3904 Transistor
- 1k ohm 1/4W or any power resistor
- Power Supply for realy
- Power supply for your load
- Breadboard
- Jumper wires
Wiring Instructions

To wire the Allegro ACS758 current sensor and LCD1602 display, start by connecting the ACS758 sensor. Connect the VCC pin of the sensor to the 5V pin on the Arduino. The GND pin should be connected to a ground pin on the Arduino. The S (signal) pin of the sensor should be connected to the analog input pin A0 on the Arduino.
Next, for the LCD1602, connect the VCC pin to the 5V pin on the Arduino and the GND pin to the ground. The SDA pin of the LCD should connect to the A4 pin (SDA) on the Arduino, while the SCL pin should connect to the A5 pin (SCL) on the Arduino. Finally, connect a relay module to digital pin 2 for controlling the load based on the current readings.
Code Examples & Walkthrough
In the Arduino code, we start by defining key identifiers like VIN, which represents the analog input pin connected to the ACS758 sensor. The relayPin is set for the relay control, while maxCurrent defines the threshold for overcurrent protection.
#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
The setup() function initializes the LCD and sets up the relay pin as an output. It also prints a welcome message on the LCD, informing the user about the current sensor being used.
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 the loop() function, we continuously read the voltage from the sensor and calculate the current. If the current exceeds the maximum limit, the relay is activated to disconnect the load. This logic ensures that the system protects itself from overcurrent conditions.
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 / What to Expect
Once everything is wired and the code is uploaded, the LCD will display the current readings. If the current exceeds the defined maxCurrent, the relay will activate, disconnecting the load. You can test this by gradually increasing the load current and observing the changes on the LCD and in the serial monitor. Make sure to avoid reversed polarity connections, as this can damage the components (in video at 10:15).
/*
*
* 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);
}
|||您可能需要的东西
-
亚马逊亚马逊加拿大的ACS758电流传感器amzn.to
-
亚马逊从亚马逊购买100A 12V继电器amzn.to
-
亚马逊美国亚马逊上的ACS758电流传感器amzn.to
-
全球速卖通从AliExpress购买一个LCD1602s.click.aliexpress.com
-
全球速卖通在AliExpress上购买10个LCD1602-I2Cs.click.aliexpress.com
-
BanggoodPurchase LCD1602 display from Banggoodbanggood.com
资源与参考
-
外部
-
外部
-
外部
-
外部Purchase LCD1602 display from Banggoodbanggood.com
-
外部从AliExpress购买一个LCD1602s.click.aliexpress.com
文件📁
数据手册 (pdf)
-
ACS758电流传感器数据表
robojax_ACS758_current_sensor_datasheet.pdf1.03 MB