Interfacing ACS712 Current Sensor with Arduino

1,510 views

Introduction

Are you looking to measure current in your electronics project but don’t know where to start? Look no further than the ACS712 current sensor paired with an Arduino! This combination allows for easy and accurate measurement of both AC and DC currents. In this article, we will discuss the basics of the “ACS712 sensor“, how to connect it to an Arduino, and how to use the data it provides in your projects.

What is ACS712 Current Sensor?

The ACS712 is a fully integrated Hall effect-based linear current sensor. It can measure both AC and DC currents accurately and provides an analog output voltage that is proportional to the current flowing through the sensor. The sensor has a low-resistance current conductor that reduces power loss and minimizes heat generation. It also has an onboard amplifier that provides a gain of 185 for low-level current sensing applications. The ACS712 current sensor is widely used in power monitoring applications, motor control, and industrial automation, among others. The sensor comes in different models, each with a specific current rating, ranging from 5A to 30A.

ACS712 Current Sensor
ACS712 Current Sensor

Hardware Components

To interface ACS712 Current Sensor with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
Current SensorACS7121
Jumper Wires1

ACS712 Current Sensor Pinout

ACS712 Current Sensor Pinout1
ACS712 Current Sensor Pinout1
Pin NumbersPin NamePin Description
1 and 2IP+Current Sense Terminals. These two pins are shorted inside the IC
3 and 4IP-Current Sense Terminals. These two pins are shorted inside the IC
5GNDGround terminal
6FILTERYou can connect the external capacitor to this pin. The capacitance value decides the bandwidth
7VIOUTThe output signal (analog value) 
8VCCPower supply pin

ACS712 Current Sensor Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

Arduino Current Sensor
5VVCC
GNDGND
A0OUT

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Arduino Code 5A

Now copy the following code and upload it to Arduino IDE Software.

void setup() {
  Serial.begin(9600); //Start Serial Monitor to display current read value on Serial monitor
}
 
void loop() {
  unsigned int x = 0;
  float AcsValue = 0.0, Samples = 0.0, AvgAcs = 0.0, AcsValueF = 0.0;
 
  for (int x = 0; x < 150; x++) { //Get 150 samples
    AcsValue = analogRead(A0);     //Read current sensor values
    Samples = Samples + AcsValue;  //Add samples together
    delay (3); // let ADC settle before following sample 3ms
  }
  AvgAcs = Samples / 150.0; //Taking Average of Samples
  AcsValueF = (2.5 - (AvgAcs * (5.0 / 1024.0)) ) / 0.185;
 
  Serial.print(AcsValueF);//Print the read current on Serial monitor
  delay(50);
}

Code Explanation

This Arduino code is used to measure the current flowing through a circuit using the ACS712 current sensor. Here is a brief explanation of the code:

The “void setup()” function is used to initialize the serial communication between the Arduino board and the computer. It starts the Serial Monitor at a baud rate of 9600, which will be used to display the current reading on the computer screen.

The “void loop()” function is the main code that runs repeatedly. It starts by initializing some variables, such as “x” for loop iteration, “AcsValue” for storing the analog value read from the ACS712 sensor, “Samples” for summing up the samples, “AvgAcs” for taking the average of the samples, and “AcsValueF” for converting the analog value into the current value.

Next, the “for” loop is used to take 150 samples of the current sensor reading. In each iteration of the loop, the analog value is read from the ACS712 sensor and added to the “Samples” variable.

After taking 150 samples, the average of the samples is calculated by dividing the sum of all samples by the total number of samples (150).

Finally, the analog value is converted into the actual current value using the formula provided in the code. The calculated current value is then displayed on the Serial Monitor using the “Serial.print()” function. The “delay()” function is used to wait for 50 milliseconds before taking another sample.

In summary, this code takes 150 samples of the current sensor reading, calculates the average value, converts it into the actual current value, and displays it on the Serial Monitor. It provides a simple and effective way to measure the current flowing through a circuit using the ACS712 current sensor and an Arduino board.

Applications

  • Power monitoring in industrial, commercial, and residential applications
  • Motor control in robotics, electric vehicles, and automation
  • Battery management in portable devices and electric vehicles
  • Overcurrent protection in electronic circuits and devices
  • Power supply monitoring and control
  • Solar panel power monitoring
  • Current measurement in welding and metal cutting applications
  • Monitoring of high-power electrical equipment, such as transformers, generators, and inverters
  • Electrical energy metering

Conclusion

The ACS712 current sensor is a versatile component that can measure both AC and DC currents. With the help of an Arduino board, it can be easily interfaced with any electronic circuit to measure the current flowing through it accurately. This feature makes it ideal for power monitoring applications, where it is essential to monitor the current consumption of a device.