ACS712 Low Current Sensor Hookup Guide

This Tutorial is Retired!

Note: This tutorial is for the ACS712 Current Sensor Breakout Boards. If you are using either of the newer ACS723 Breakout Boards, please refer to the new Current Sensor Breakout (ACS723) Hookup Guide.

View the updated tutorial: Current Sensor Breakout (ACS723) Hookup Guide

Pages
Contributors: AGlass0fMilk
Favorited Favorite 1

Introduction

The ACS712 is a handy little current sensor from Allegro MicroSystems for low to moderate current sensing applications. SparkFun offers two flavors of breakout board, one with just the sensor and another with an on-board amplifier to increase the sensitivity.

SparkFun Hall-Effect Current Sensor Breakout - ACS712

BOB-08882
3 Retired

SparkFun Low Current Sensor Breakout - ACS712

SEN-08883
9 Retired

The ACS712 sensor uses a Hall effect sensor to output a voltage relative to the current flowing through the IP+ and IP- pins. The advantage of using a Hall effect sensor is that the circuit being sensed and the circuit reading the sensor are electrically isolated. This means that, although your Arduino is running on 5V, the sensed circuit can be operating at higher DC or AC voltages!

The amplified breakout board is capable of sensing very small currents down to around 10mA and large currents up to 5A! However, since the output is analog, your usable readings will be limited by noise and the resolution of the ADC reading the output. This sensor is not recommended for current sensing lower than 10's of milliamps.

Required Materials

Depending on the equipment available to you, you will need some of the following items to follow along with this hookup guide:

Suggested Reading

Here are some topics related to this hookup guide you may want to review:

The Hall Effect and Current Sensors

This section provides a quick recap of electromagnetic concepts that make this current sensor possible. How does this little chip take current from one circuit and produce a proportional output voltage without physically connecting the two circuits?

Faraday's Law of Induction

In the ACS712, sensing current starts with a phenomena known as Faraday's Law (of Induction). This phenomena, first discovered by Michael Faraday in 1831, is a foundation of modern radio and electromagnetics. This law describes how an electrical current flowing in a conductor creates a surrounding magnetic field, and how a changing magnetic field can create, or induce, a current in a conductor. This is how antennas pick up radio waves!

Faraday's Law

This image illustrates the magnetic field created around a conductor with a current flowing through it (Photo courtesy of http://www.tesla-institute.com)

The current pins of the ACS712 are internally connected to a big trace of copper, allowing a lot of electricity to flow through this part of the chip. When current flows through the copper strip, a magnetic field is created around the trace with a strength proportional to the current.

The Hall Effect

The next step in sensing current is based on the Hall effect - a very useful phenomena discovered by Edwin Hall in 1879. In basic terms, the Hall effect produces a voltage difference across a conductor in the presence of a magnetic field. This provides a neat way of sensing nearby magnetic fields and has many applications. Hall effect sensors are used in some car engines to detect where in a rotation cycle the camshaft or crankshaft are, for example.

Hall Effect Animation

This animation shows how a magnetic field creates a voltage difference. The blue circles are electrons flowing (Photo courtesy of http://www.explainthatstuff.com/hall-effect-sensors.html

The ACS712 has an internal Hall effect sensor placed next to the aforementioned copper strip. When current flows through this copper strip, a magnetic field is created. This magnetic field is then sensed by the Hall effect sensor and produces a voltage output that is proportional to the input current!

Hall Effect current sensor

This shows how the current sensor looks internally (Photo courtesy of Allegro Micro)

This method of sensing allows the sensing circuit to be electrically isolated from the sensed circuit. Practically, this means that since the circuits aren't physically connected, you can use a low-power Arduino to measure the current going through a high power device, even one that uses AC power!

Hardware Overview

This section will explore the various segments of the breakout.

ACS712 Board Picture

ACS712 Breakout Details:

  • Analog output with bandwidth adjustable to 80kHz.
  • The bandwidth on the ACS712 Low Current Sensor Breakout with filter has been set to 34kHz to reduce noise when using at high gains. The full 80KHz bandwidth that the sensor is capable of can be recovered by removing C1. See schematic for more details.
  • Measures DC and AC currents from around 10mA up to 5A
  • Adjustable sensitivity with on-board amplifier, gain from 4.27 to 47 V/V
  • The version without the op-amp has a base sensitivity of 185mV/A
  • Full electrical isolation of measured and sensed circuits
Please Note: Although the chip itself is rated for up to 2.1kV (RMS) of isolation, the board has not been designed for such high voltage applications.

Below is a list of all the pins broken out on the ACS712 and their function.

SymbolDescription
IP+High side of current sensor
IP-Low side of current sensor
GNDMust be connected to ground
VoVoltage output proportional to current flowing through IP+ and IP-
5V5V power supply

To measure a current using this device, the current must flow through the IP+ terminal and out the IP- terminal (it will work in the other direction, but the measurement will be negative). IE: These terminals must be in series with the circuit the measured current is flowing through. Note that both IP+ and both IP- terminals are connected to each other, you can use either (or both) of them.

This amplified version of the breakout board has two potentiometers on it: Vref and Gain

The Vref potentiometer sets the baseline voltage output. In other words, it adjusts the voltage seen at Vo when there is no current flowing through the sensor (0 mA). This allows the sensor to output negative current readings as well as positive.

ACS712 Vref Potentiometer

Vref potentiometer, highlighted

The gain potentiometer sets the sensitivity of the device. For example, if the gain is set high, then a smaller current will cause the voltage output to increase more, giving you higher sensitivity and allowing you to sense smaller currents.

ACS712 Gain Potentiometer

Gain potentiometer, highlighted

However there are a couple caveats:

  1. With higher gain you will see more noise (spikes) on the output, so smaller currents will be harder to measure accurately.
  2. If you are trying to measure larger currents with a high gain setting, your output will saturate or clip and reach the maximum 5V or 0V.

With that in mind, to get meaningful data from the current sensor, you must configure the Vref and gain potentiometers properly.

Calibration and Example Code

An example sketch for Arduino is included below to help you get started with the ACS712. It will help you set the potentiometers and perform calculations to convert raw ADC readings into the actual current in mA.

To properly calibrate the ACS712 breakout board, you should first consider what type and range of currents you will want to measure.

Choosing the Range

If you are going to be dealing mainly with DC, positive currents, you can adjust Vref to the lower end of its range. If you are trying to measure AC currents, you will want to keep Vref about in the middle at 2.5V. This lets your output swing equally in the positive and negative directions.

The gain setting will depend on the range of currents you want to measure. If you want to measure a current between 100mA and 500mA, you will want to set the gain so the sensitivity is something like 250mV/100mA (you will learn how to do this in the following steps).

Setting Vref

To get started, copy and upload the sketch below to your Arduino. You can also find the latest files in the GitHub repository.

language:c
/*  SparkFun ACS712 Demo
    Created by George Beckstein for SparkFun
    4/30/2017

    Uses an Arduino to set up the ACS712 Current Sensor
    See the product page at: https://www.sparkfun.com/products/8883

    Parts you may need:
    - 100 Ohm, 1/2W or greater resistor OR two 220 Ohm 1/4 resistors in parallel
    - ACS712 Breakout with on-board amplifier

    Optional equipment:
    - Oscilloscope
    - Multimeter (or two)
    - A power supply with current limiting/constant current would be handy to calibrate the device without using resistors
*/

const int analogInPin = A0;

// Number of samples to average the reading over
// Change this to make the reading smoother... but beware of buffer overflows!
const int avgSamples = 10;

int sensorValue = 0;

float sensitivity = 100.0 / 500.0; //100mA per 500mV = 0.2
float Vref = 2500; // Output voltage with no current: ~ 2500mV or 2.5V

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  for (int i = 0; i < avgSamples; i++)
  {
    sensorValue += analogRead(analogInPin);

    // wait 2 milliseconds before the next loop
    // for the analog-to-digital converter to settle
    // after the last reading:
    delay(2);

  }

  sensorValue = sensorValue / avgSamples;

  // The on-board ADC is 10-bits -> 2^10 = 1024 -> 5V / 1024 ~= 4.88mV
  // The voltage is in millivolts
  float voltage = 4.88 * sensorValue;

  // This will calculate the actual current (in mA)
  // Using the Vref and sensitivity settings you configure
  float current = (voltage - Vref) * sensitivity;

  // This is the raw sensor value, not very useful without some calculations
  //Serial.print(sensorValue);

  /*************************************************************************************
   * Step 1.)
   * Uncomment and run the following code to set up the baseline voltage 
   * (the voltage with 0 current flowing through the device).
   * Make sure no current is flowing through the IP+ and IP- terminals during this part!
   * 
   * The output units are in millivolts. Use the Arduino IDE's Tools->Serial Plotter
   * To see a plot of the output. Adjust the Vref potentiometer to set the reference
   * voltage. This allows the sensor to output positive and negative currents!
   *************************************************************************************/

  Serial.print(voltage);
  //Serial.print("mV");

  /*************************************************************************************
   * Step 2.)
   * Keep running the same code as above to set up the sensitivity
   * (how many millivolts are output per Amp of current.
   * 
   * This time, use a known load current (measure this with a multimeter)
   * to give a constant output voltage. Adjust the sensitivity by turning the
   * gain potentiometer.
   * 
   * The sensitivity will be (Vreading - Vref)/(known current).
   *************************************************************************************/

    /*************************************************************************************
   * Step 3.)
   * Comment out the code used for the last two parts and uncomment the following code.
   * When you have performed the calibration steps above, make sure to change the 
   * global variables "sensitivity" and "Vref" to what you have set up.
   * 
   * This next line of code will print out the calculated current from these parameters.
   * The output is in mA
   *************************************************************************************/

  //Serial.print(current);
  //Serial.print("mA");


  // -- DO NOT UNCOMMENT BELOW THIS LINE --
  Serial.print("\n");

  // Reset the sensor value for the next reading
  sensorValue = 0;
}

This sketch reads the voltage on pin A0 and prints it to the serial terminal. In later steps you will learn how to get actual current readings with this sketch.

To set up Vref, the sensor should have no current flowing through it! For this part, you only need to connect the ACS712's GND pin to Ground, Vo pin to pin A0 on the SparkFun RedBoard (or equivalent), and 5V to the 5V pin on the RedBoard. If you have one available, it may be useful to also read the output voltage using a multimeter. See the Fritzing diagram below for more information:

Adjusting Vref Circuit

Having a hard time seeing the circuit? Click on the wiring diagram for a closer look.

If you aren't using a multimeter to set Vref, open up the Arduino IDE's serial plotter by clicking Tools->Serial Plotter. This will show the voltage reading from the Arduino in real time. The units are in millivolts.

Turn the Vref potentiometer clockwise to increase Vref and counter-clockwise to decrease. Make small adjustments, as the adjustment is very sensitive!

Note: Using metal/magnetized screwdrivers may cause the sensor to give false readings. This is because the Hall effect sensor inside is picking up the magnetic fields from the screwdriver. You may want to use a plastic screwdriver to eliminate this effect. I made one out of an old guitar pick with some scissors!

In the Serial Plotter, you should see something like this:

Vref Animation

Using the RedBoard and Arduino, you can plot the output voltage as you adjust Vref

Tune Vref to about where you want it, for example 2500mV.

Setting Gain and Sensitivity

To set the gain, you need to pass a known current through the sensor and tune the gain pot to achieve the sensitivity your application needs.

For example, if you want to measure between 100mA and 500mA, you should shoot for a sensitivity of around 250mV/100mA. To do this, you can pass 100mA through the sensor, and adjust the gain pot until the output voltage is 250mV above your set Vref.

For those of you who have a benchtop power supply with a current limiter/constant current (CC) mode, getting this 100mA current is easy. In this case, you can simply connect the positive terminal of the power supply to the IP+ pin and the negative terminal of the power supply to the IP- pin. Make sure your current limit is set to something reasonable (NOT above 5A), and turn the power on. Adjust the output to a constant 100mA current for use in adjusting the gain. Make sure your benchtop power supply won't be damaged by shorting the outputs, read your supply's user manual for more information

If you don't have a power supply, all you need are some resistors (like in this nifty resistor kit, or these power resistors for more power dissipation). To make a fixed, known current, just use Ohm's Law!

If you want a 100mA current from a 5V source you need (5/0.1) = 50Ω

You should keep in mind how much power your resistors can handle though! If not, they'll end up a bit toasty... With 5V and 100mA, the power would be 500mW or 1/2W. The small resistors in the kit above can only handle 250mW or 1/4W at most. But, wait! A resourceful engineer knows you can still use the 1/4W resistors, you just need to split the power dissipation. By placing equal resistors in parallel, you can increase the maximum allowable power dissipation; each resistor just adds their power rating. IE: 1/4W resistor + 1/4W resistor = 1/2W capacity! Keep in mind that the equivalent resistance will be lower though.

500mW is still a lot of power for these 1/4W resistors, so I recommend using only 50mA to tune the gain, unless you have the power resistors linked to above.

To get 50mA from 5V, you need 100Ω. Using parallel resistances, you need double that, or around 220Ω. You may want to use your multimeter to make sure the current flowing through the circuit is indeed 50mA. The tolerances of resistors can alter this current. To measure current with your multimeter, make sure to connect it in series! To see a diagram of how to build the circuit for setting the gain, see the Fritzing diagram below:

Adjusting Gain Circuit

Having a hard time seeing the circuit? Click on the wiring diagram for a closer look.

With a known, constant current flowing through the sensor, the gain can be adjusted. The same sketch can be used as last time. Open up the Serial Plotter again. To set the gain, disconnect one of the wires to break the current sensing circuit, when you reconnect it, see how much the output voltage increases. Subtract this from your Vref, to keep the voltage change (also known as delta). So, if you have 50mA flowing in the circuit, you want this change to be about 125mV for the 250mV/100mA sensitivity example. An example is shown below:

Gain Adjust Delta Plot

Adjust the change (Vdelta) to what you need it to be by tuning the gain potentiometer. As mentioned above, this affects the noise (spikiness) you see in the output:

Gain Adjust Noise

As the gain increases, the spiky noise gets bigger (and the Vref changes slightly)

Note: Adjusting the gain pot also changes the Vref setting slightly, you need to take this into account when you do your calculations. You should measure your final Vref and sensitivity with a multimeter after calibration.

Once you have Vref and the sensitivity settings selected, you can modify the code in the example sketch to print out your current readings in milliamps! Follow step 3 in the code comments to learn how to do this. Make sure to change the sensitivity and Vref variables to what you have set so the code can calculate the current properly.

Resources and Going Further

The ACS712 sensor is ideal if you need to measure a small to moderate amount of current, especially if it's AC current! For more information about the ACS712, check out the links below:

If you don't need electrical isolation and want to measure smaller currents, check out the INA169 Breakout Board. And for even higher power applications, check out the Non-Invasive Current Sensor - 30A.

Non-Invasive Current Sensor - 30A

Non-Invasive Current Sensor - 30A

SEN-11005
$10.95
18
SparkFun Current Sensor Breakout - INA169

SparkFun Current Sensor Breakout - INA169

SEN-12040
$11.50
2

For more power related learning, check out the tutorials below:

Wake-on-Shake Hookup Guide

A basic hookup guide for getting started with the SparkFun Wake-on-Shake. The board gives you the ability to put your project into hibernation until bumped or shaken awake using the ADXL362 accelerometer. This means you can design projects meant to stay inert for long periods of time, possibly even several years, depending on the battery type used to power the project.

Photon Battery Shield Hookup Guide

The Photon Battery Shield has everything your Photon needs to run off, charge, and monitor a LiPo battery. Read through this hookup guide to get started using it.

Beginner Parts Kit Identification Guide

The essential parts for beginning (or even experienced) hobbyists that gives you all of the basic through-hole components you will need to get started playing with embedded projects. We'll identify a few parts in the kit and provide a few basic circuits to get started!

Single Cell LiPo Battery Care

This tutorial will go over how to safely charge, connect, disconnect, reinforcing the cables, and handle single cell LiPo batteries.