Arduino ACS712 AC/DC Current Sensor + Measurement Examples

In this tutorial, you’ll learn how to interface an Arduino With ACS712 AC/DC Current Sensor, install the Arduino ACS712 library, and test some code examples to Measure DC Current with Arduino + ACS712, and also Measure AC current with Arduino + ACS712 sensor. Without further ado, let’s get right into it!

Table of Contents

  1. Arduino ACS712 AC/DC Current Sensor
  2. Arduino ACS712 Interfacing
  3. Arduino ACS712 Library Installation
  4. Arduino ACS712 DC Current Measurement Example
  5. Arduino ACS712 AC Current Measurement Example
  6. Wrap Up

Arduino ACS712 AC/DC Current Sensor

The ACS712 current sensor is a common choice for Arduino projects needing AC/DC current measurement capability. The ACS712 current sensor provides a linear voltage output that makes it so easy to measure the amplitude of the AC/DC current with minimal calculations.

The internal hall sensor inside the ACS712 can also determine the polarity of the current (positive or negative) while measuring DC currents. It can also measure AC currents from 5A up to 30A, which is more than enough to make it extremely useful for home automation and power monitoring applications.

ACS712 Pinout Diagram

Below is the pinout diagram of the ACS712 AC/DC current sensor.

ACS712 Pinout Diagram

Key Specifications of the ACS712 AC/DC Current Sensor:

  • 5v single supply operation
  • ±5A/±20A/±30A AC/DC current sensing variants
  • 66 to 185 mV/A output sensitivity (linear input-to-output relationship)
  • Very low (1.2 mΩ) internal conductor resistance
  • Total output error 1.5% at TA= 25°C

ACS712 AC/DC Current Sensor Variants

ACS712 AC-DC Current Sensor Variants (5A-20A-30A)

ACS712 AC/DC Current Sensor Working Principles

The ACS712 AC/DC current sensor uses an internal hall effect sensor that measures the (EM field strength & direction) induced by the “to be measured” current flowing inside the sensor’s internal conductor.

The current-carrying conductor and the hall effect sensor are completely isolated, so there is no risk of high-voltage striking your microcontroller unless you’ve got more than 2.4k volts or something that can ARC over the IC package. Below is a “simplified” diagram that shows the internal structure of the ACS712 to illustrate how it works.

The actual internal structure of the ACS712 is a bit more complex than what I’ve shown above. It just has some signal conditioning, filters, and some other supporting analog circuits. But the general concept is exactly the same.

❕ Note

The ACS712 current sensor is internally isolated, so you don’t need to worry about the high-voltage side damaging your microcontroller.

Buy an ACS712 Current Sensor: you can find it here on ( Amazon, AliExpress, eBay )


Arduino ACS712 Interfacing

Interfacing the ACS712 current sensor with Arduino is very easy as it only requires one analog input pin to read the sensor’s output voltage.

The sensor’s output voltage represents the measured AC/DC current according to the following formula:

VOUT = ILoad x Sensitivity

Let’s assume we’ve got a 30A sensor variant that has a sensitivity of 66mv/A, and the sensor’s VOUT voltage measured by the Arduino was 0.165v. Therefore, the current measurement will be: ILoad = VOUT / Sensitivity => ILoad = 0.165/0.66 = 2.5A

❕ Note

Note that the Arduino’s internal ADC is 10 bits, which has a voltage reading resolution of only 5mv. Therefore, it’s much easier for the Arduino to read the output voltage of a 5A ACS712 sensor since it has a sensitivity of 185mv/A compared to the 30A ACS712 sensor variant which has a 66mv/A sensitivity.

The lower the sensor’s sensitivity, the higher the error in the measurement due to Arduino’s limited ADC resolution that can read the incoming analog input voltage in 5mv increments.

Arduino ACS712 Wiring (Connection)

This is a summary of the connections needed between your Arduino board and the ACS712 current sensor.

ACS712Arduino UNODescription
VCC5VPower supply
GNDGNDGround
OutA0Sensor’s Analog Output

Arduino ACS712 Library Installation

The library we’ll use in this tutorial is called ACS712, and this is how to install it on your system.

Step #1

Open your Arduino IDE > Tools > Manage Libraries > Search For “ACS712“.

Step #2

Install the ACS712 library as shown below.

And that’s all about it. Now we can use the library as we’ll do in the next two example projects.

❕ Note

It’s relatively easy to read the ACS712 current sensor with your Arduino board without any library. However, it’s better to use the library that we’ve installed as it can help with capturing some initialization parameters to null the reading at startup, wrap the calculations inside some API functions so your code becomes easily readable, and it doesn’t bloat our code anyway, so why not use it?


Arduino ACS712 DC Current Measurement Example

In this example project, we’ll measure DC current with Arduino + ACS712 current sensor. The measured DC current will be sent to a PC over the serial port.

I’ll use a variable DC power supply and an 8Ω load to test the ACS712 current sensor.

Arduino DC Current Measurement (ACS712) Wiring

Here is the wiring diagram for the Arduino DC current measurement setup I’ve used to test the ACS712 sensor.

Arduino ACS712 DC Current Measurement Example

Example Code

Here is the full code listing for this example.

The ACS712 sensor initialization configurations are set in this line of code:

The auto midpoint set function call is done inside the setup() function. And it needs to be called while the sensor is IDLE (no current is flowing through) because this will be the null point for the application afterward.

❕ Note

While resetting your Arduino board, make sure there is no load current going through the ACS712 sensor while the Arduino is booting up because the midpoint setting function could mess up your measurements if it’s called while there is some current flowing through the sensor.

The mA_DC() function is used to read the measured DC current in (mA) unit.

Testing Results

Here are the results of testing this project code example on my Arduino UNO board.

Arduino-ACS712-DC-Current-Measurement-Code-Example

The measurement error percentage is better than expected, TBH.


Arduino ACS712 AC Current Measurement Example

In this example project, we’ll measure AC current with Arduino + ACS712 current sensor. The measured AC current will be sent to a PC over the serial port.

I’ll use a variable AC power supply and a 220V/50Hz AC lamp to test the ACS712 current sensor.

Arduino AC Current Measurement (ACS712) Wiring

Here is the wiring diagram for the Arduino AC current measurement setup I’ve used to test the ACS712 sensor.

Arduino ACS712 AC Current Measurement Example

❕  DANGER

Please, be extremely careful when dealing with AC line input in your home as it can really harm you and cause serious injuries.

Example Code

Here is the full code listing for this example.

The ACS712 sensor initialization configurations are set in this line of code:

The auto midpoint set function call is done inside the setup() function. And it needs to be called while the sensor is IDLE (no current is flowing through) because this will be the null point for the application afterward.

❕ Note

While resetting your Arduino board, make sure there is no load current going through the ACS712 sensor while the Arduino is booting up because the midpoint setting function could mess up your measurements if it’s called while there is some current flowing through the sensor.

The mA_AC() function is used to read the measured RMS AC current in (mA) unit.

Testing Results

Here are the results of testing this project code example on my Arduino UNO board.

Arduino-ACS712-AC-Current-Measurement-Code-Example

The error percentage is acceptable at this very low current range and it gets even better when the current to be measured is much larger (>1A).


Required Parts List

Here is the full components list for all the parts you’d need to perform the practical LABs mentioned in this tutorial and the whole Arduino Programming series of tutorials found here on our website.

* Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.

QTY.Component NameAmazon.comAliExpresseBay
1ACS712 Current SensorAmazonAliExpresseBay
1Arduino UNO KitAmazonAliExpresseBay
1Complete Arduino Sensors/Modules KitAmazonAliExpresseBay
1DC Power SupplyAmazonAliExpresseBay
1BreadBoardAmazonAliExpresseBay
1LEDs KitAmazonAmazonAliExpresseBay
1Resistors KitAmazonAmazonAliExpresseBay
1Capacitors KitAmazonAmazonAliExpress & AliExpresseBay & eBay
1Jumper Wires PackAmazonAmazonAliExpress & AliExpresseBay & eBay
1Push ButtonsAmazonAmazonAliExpresseBay
1PotentiometersAmazonAliExpresseBay

★ Check The Links Below For The Full Course Kit List & LAB Test Equipment Required For Debugging ★

Download Tutorial’s Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting our work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports the whole community.


Wrap Up

To conclude this tutorial, we’ve covered how to interface an ACS712 AC/DC Current Sensor with Arduino, and how to use this sensor to measure DC currents and AC currents with your Arduino board. You can build on top of the provided example projects and use the ACS712 current sensor with your Arduino boards.

If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.

And follow this Arduino Series of Tutorials to learn more about Arduino Programming.

References:

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment