Interfacing ACS712 Current Module with Arduino

Table of Contents

ACS712 Current Module Features

ACS712 chip is used to measuer DC/AC current based on the Hall effect. This chip is produced in 3 models with different maximum currents. Different models and output sensitivity of each model are shown in the table below:

Sensor sensitivity means that, for example, if you use 5 amp model, as input current increase 1 amp, the output voltage of the sensor increases about 185 mV.

Note

When input is not connected to something and there is no load on output, the sensor has an initial voltage (Offset) of Vcc/2. That is, if nothing is connected to the input and the supply voltage of the module is 5 volts, the output of the module will be 2.5 volts.
As a result, the relationship between the output voltage of the sensor with 5 amp and the supply voltage of 5 volts is as follows:

 

You can download the ACS712 chip datasheet here.

ACS712 Current Module Pinout

ACS712 module has 3 pins as below:

  • VCC: Power supply – 5 Volt
  • GND: Ground
  • OUT: Module output which is in the form of analog voltage.

You can see the pinout of this module in following image:

Required Materials

Hardware Components

Arduino UNO R3 × 1
ACS712 Current sensor module 5A × 1
ACS712 Current sensor module 20A × 1
ACS712 Current sensor module 30A × 1
jumper wire × 1

Software Apps

Arduino IDE

Interfacing ACS712 Current Module with Arduino

Step 1: Circuit

Connect the module to the Arduino according to the following diagram. You can connect the sensor output to any of the Arduino ADC pins.

Step 2: Code

Upload the following code to your Arduino board.

This code reads the output value of the sensor 500 times and averages it. It then displays the result in 3 different ways in the serial monitor.

/*
  ACS712 Current Sensor
  modified on 06 Sep 2020
  by Mohammad Reza Akbari @ Electropeak
  
Home
*/ int analogPin = A0; // Current sensor output const int averageValue = 500; long int sensorValue = 0; // variable to store the sensor value read float voltage = 0; float current = 0; void setup() { Serial.begin(9600); // setup serial } void loop() { for (int i = 0; i < averageValue; i++) { sensorValue += analogRead(analogPin); // wait 2 milliseconds before the next loop delay(2); } sensorValue = sensorValue / averageValue; voltage = sensorValue * 5.0 / 1024.0; current = (voltage - 2.5) / 0.185; Serial.print("ADC Value: "); Serial.print(sensorValue); Serial.print(" ADC Voltage: "); Serial.print(voltage); Serial.print("V"); Serial.print(" Current: "); Serial.print(current); Serial.println("A"); }

When there is no load on the sensor’s input, you will have the same result as the following image.

When there is 1 amp bar on module, you should see something like this:

Liked What you see?

Get updates and learn from the best

More To Explore

Comments (4)

  • Rabea Reply

    Can you explain these to me:
    sensorValue = sensorValue / averageValue;
    voltage = sensorValue * 5.0 / 1024.0;
    current = (voltage – 2.5) / 0.185;

    November 14, 2021 at 5:11 pm
    • Mehran Maleki Reply

      Hi,
      As you can see in line 23 of the code, a “for loop” has been used to get the output of the sensor. The output of the sensor has been obtained for “averageValue = 500” times, so it needs to be divided to “averageValue”. Actually, instead of getting a single sample of the output, we have gotten 500 samples of it and calculated their average to get rid of the noise that the output of the sensor might have. And about “voltage = sensorValue * 5.0 / 1024.0;”, sensorValue is actually the value we have read from the analog pin A0. That value is between 0 (equivalent to 0 Volts) and 1024 (equivalent to 5 Volts). So, that equation is used to get the output voltage of the sensor. And about “current = (voltage – 2.5) / 0.185;”, that is the formula between the current and the voltage of the sensor. It has already been mentioned in the article, in the “Note” in “ACS712 Current Module Features” section.

      November 15, 2021 at 6:02 am
  • syad Reply

    Hi can i ask you how to use acs712 sensor current with esp32 can u give the codeing

    November 28, 2021 at 5:52 am
    • Mehran Maleki Reply

      Hi.
      The ACS712 current module has a single analog output. So, you can use as many of them as you want with an ESP32 board, as long as you have GPIO pins left. And for the coding, it’s not much different from the code written in this article. You just need to define all variables of the original code twice. For example, you can define sensorValue1, sensorValue2, voltage1, voltage2, current1, current2 and so on.

      November 28, 2021 at 8:12 am

Leave a Reply

Your email address will not be published. Required fields are marked *