Basic Questions with ACS712 Current Sensor

Hi all,

I'm working on measuring the current draw from my battery to my inverter. The idea is to connect a hall effect sensor chip (ACS712 from Allegro) in series on the positive wire from the battery to the inverter. I got my current sensor a few days ago, but I'm having some issues getting started with it.

The main problem is that when I have nothing connected to the input pins, the sensor is still reading 4.9V on the A1 pin (or 3.3 if I have the chip powered from the 3.3V pin). Basically, it's outputting the board power supply, not anything having to do with the current. I'm using an Arduino Yun.

I'm hoping that this is a common problem when using these 5 pin current sensors and that there is a simple solution. If anyone has any thoughts, I'd love to hear them.

Are you working with the naked chip, or with someone's breakout board?

If the chip is wired correctly, with a common ground to the Arduino, it is certainly not working correctly. In that case, perhaps the chip was damaged by ESD when being connected to your circuit.

I'm working with the naked chip. Because I don't have female-to-male pin connectors yet, I've just got the 3 pins plugged into a breadboard. I wouldn't think that would impact the issues I'm having though because those breadboard rows aren't connected.

Sorry, what is ESD? I do have it connected to the Arduino ground and 5V (see schematic attached). My first thought was that the output pin had somehow been connected to the VCC pin inadvertently, but I didn't want to assume that was the problem.

Top theories right now:

  1. Output is connected to VCC pin
  2. Plugging the sensor into the breadboard directly is screwing something up.
  3. The sensor is going to measure the current coming from the Arduino because there is no power source connected
  4. The 30A rating is too high for the applications that I'm looking for (i.e. it's expecting such high currents that it would normally disregard the 5V noise it's currently reading.

Would love to get everyone's thoughts on which is most likely.

Current Sensing.png

I don't understand your schematic. The naked ACS712 is an 8-pin chip and needs to have a couple of capacitors connected to it. Here is the datasheet: http://www.allegromicro.com/~/media/Files/Datasheets/ACS712-Datasheet.ashx

Why not post a picture of your setup?

ESD is "electrostatic discharge" and can take place if naked chips (and sometimes, mounted chips) are mishandled. High voltages from static electricity destroys the chip. You should ground yourself to nearby equipment using a wrist ground strap when working with naked chips. It would be best to use a breakout board like that produced by SparkFun or Pololu.

Finally, connecting a battery across the current terminals is a sure way to damage either the chip or the battery. There is no control over the current except for the internal resistances.

I've attached a picture of the chip (or maybe it is a breakout board) that I'm using. I was following a youtube video about the ACS712 and it used this same component. When I looked at the ACS712 datasheet, you are right, it's got more pins than the component that I've got. I'm thinking that maybe I need to get a different piece, like the one you referenced on Sparkfun.

This is especially true since I may have damaged this one already. Are there other components that are perhaps a simpler way to measure current? I'm not looking for amazing accuracy in this measurement.

Also, it sounds like you would recommend using a resistor in series with the positive line before connecting to the sensor (and then another resistor afterwards). Is that how you'd prevent the current from being uncontrolled?

ACS712.jpg

The Arduino can supply only a few milliamperes of current, either from a digital output pin (should always be limited by your circuit to be less than 20 mA) or from the regulated voltage output terminal (typically this should be limited by your circuit to be less than 100 mA). The ACS712 is not suitable for measurements of currents in that range. If you don't have a good multimeter, that should be your very next purchase.

Do read up on Ohm's law. The current in a circuit is limited by the total resistance of the circuit, so you will see a lot of discussion about "current limiting resistors". Very handy knowledge!

The way you have the breakout board wired should be OK. I suggest you check your connections carefully. In particular, make sure there is a connection between Arduino ground and the ground pin of the breakout board. Also, make sure the breakout board is not sitting on anything conductive.

I may be misinterpreting, but I'm not using the Arduino to supply current to the sensor for monitoring. I chose a 1.5V battery because I figured that even with the relatively low voltage, the low resistance would mean that I would have enough current to measure, but certainly not enough to fy anything. I was responding to the suggestion about not connecting the battery to the sensor directly. I wasn't sure why I wouldn't be able to send that current through the sensor if it's rated up to 30A.

Also, with regard to your last point about resistors, why would I want to limit the current if that's what I'm trying to measure? I'm sure there's a good reason, I'm just trying to understand why I would need to do that. I'm pretty comfortable with the idea of V=IR ( at least in the context of building a voltage divider circuit, which is the one place I've applied that), but not sure why I would need to limit current in this instance.

Also, dc42, I'll try to make sure that it's not sitting on anything conductive. I've had it sitting on a wooden table, so not sure if I can get much less conductive than that, but at this point, any suggestion is a good one.

Perhaps if you described the actual circuit in which you wish to measure the current, you would get more helpful advice.

You are correct, a small 1.5 V battery can't supply 30 A of current, so you would be pretty safe with the connection shown in your schematic. But there is nothing in that schematic that indicates the battery size, and some batteries, like RC car batteries, can supply far more than 30 A! With the setup you posted, you have no way of knowing the actual current, so you don't know if the current sensor is working correctly, nor do you have any way to check the overall calibration.

You are right. I'll explain the setup below. I was just so bummed to see the 5V or 3.3 V getting measured, that I wanted to see if I was doing something stupid first. But you are right, here is the setup.

I have a 12V 34Ah AGM solar battery and I want to record the power I'm pulling from it continuously (think every 15 seconds all day every day). I have a Cobra 12V/400W inverter connected to the battery that is powering a surge protector with the various electronics that I'm powering. More than likely, I'll be powering a 1A Roku device 24 hours a day and charging tablets, phones, etc during peak sun hours. For solar experts, I 100% understand that this panel produces more energy that the battery can realistically store.

I've already created a voltage sensing circuit with a 100K and 10K ohm resistor that is currently recording my voltages at all times (granted, right now it's voltage across the battery terminals, but eventually, it will be voltage on the wires connecting the inverter to the battery), so that I can measure voltage. This voltage sensor is being read by Arduino pin 0 and is currently working perfect. If I am able to figure out current sensing, I'll do the same thing on the positive wire from the battery to the inverter to continuously measure current. At that point, I'll always have current and voltage, so I can calculate total watt hours used.

Based on my 24 hr rating for the battery, I won't ever really be drawing more than 5A to prevent excessive discharge. That means, that at any given time, my current should be between 0A and 5A and voltage will be constant at 12V. Again, I've got voltage monitoring pretty much figured out. And now I'm starting to play with current sensors to add that side of the equation.

Thanks. Let me know if there is any additional information that I need to provide.

That helps a lot! As dc42 said, you've connected the current sensor module to the Arduino correctly. But you should check the sensor's output with a multimeter to see if the Arduino program is working properly. Also, double check the common ground between the Arduino and the sensor. A faulty ground connection would likely result in the symptoms that you describe (output stuck at Vcc).

To test the current sensor and to check its calibration, you need to have a known current, somewhere within the linear range of the sensor. If you already have the 12 V battery, then connect that to the current sensor in series with a load resistor (dare I say to limit the current?)

You might start with 1 amp of current, thus a 12 ohm resistor. The resistor will dissipate a lot of heat (P = IV or RI^2) or about 12 watts, so you you probably want a 20 watt resistor. The exact current can be calculated from the battery voltage, or measured with a multimeter.

Alternatively you could use a 12 volt DC lamp bulb as a current-limiting resistor and use a multimeter to measure the actual lamp current. A 50 watt bulb would consume around 4 amps of current. If the lamp lights (or the resistor heats up) and the sensor doesn't give a sensible output, then it isn't working.

Some breadboards have a break half way along the Vcc and/or ground strips, and this could mean you don't have a ground connection. If you have a multimeter, measure the resistance between the ground pin of the breakout board and another Arduino ground pin.

Can you post a photo of your wiring?

Hi, I have a 5A version of that board, with no current the output should be about 2.5V when you use a 5V supply.

So measure the voltages at the terminals of the board to check that all terminals are connected.

If you put current thrught the terminals on the board then the output to the arduino will change,up or down from 2.5V, depending on the direction of current flow.

Tom... :slight_smile:

I tried the to light a 60W bulb from the 12V battery, but I don't think it was powerful enough as I didn't see any light. I'm going to try and use the resistor approach to create a known current and see if the sensor can measure that more accurately.

I saw that radio shack has 10ohm 1/4W resistors, but I also saw the recommendation that I look for 20W to deal with heat dissipation. Since it may come down to a choice between going to the store and getting the 1/4 resistor tomorrow or having someone ship me a 20W resistor, is the heat dissipation great enough to warrant waiting for the bigger one. Especially since this is just a test to make sure that the sensor is working. I also have some 10K ohm resistors, but given the effective range of the current sensor, I think that would be too much.

Let me know if you think the 1/4w resistor would be ok for this test purpose.

  • Zack

Sounds like there's been some confusion around the device here.
What you need to do is let us know the exact part number on that 712.
There are two basic varieties, one is a small 8 pin SOC and the other is more like a TO220 type package with 'horns' on it.
From what I gather, you have the 'horny' one.

Now, I understand you are able to get uni-directional or bi-directional sensors.
Bi-directional will have their output at Vcc÷2, while the uni-directional will be close to zero volts while no current is flowing through the main current sensing line.

Which one do you have?

These devices will take way more current than what they are calibrated for, typically five times, so your device being rated for 30Amps should be able to pass 30•5, or 150 Amps.

Do a quick test by simply connecting the device to a power supply of 5 volts, so the Gnd to 0 volts and Vcc to 5 volts and use a multimeter, either analog or digital to measure what is on the output pin.
If you are measuring Vcc, then the device is kaput. If you are measuring Vcc÷2, or say 2.5 volts, then you have a bi-directional device, which would appear to work. If you measure close to zero volts, say a few tens of milli volts, then I would be again hopeful you have a working uni-directional sensor.

Once you have proved that your device either works or doesn't allows you to proceed to testing with real, I mean real current flowing through the main sensing path.

You can use a small 12 volt lamp from a vehicle, say an indicator lamp, something around 5 to 10 Watts. Test it first across the battery to make sure you see light. This proves your battery has charge and that the light works. Next connect the 712 sensor in line in accordance to the correct wiring and again measure the output pit with a multimeter.

Don't use 1/4 watt resistors for this test, full stop.

Once you prove you have a working system for measuring current, then you can bring in the Arduino.

I would suggest you get online and read the data sheets that are available from the Algero website.

Anyhow, if you want, you can see one working from my project, which measures the current from my solar array to my battery system. I have made the Arduino do many things including pushing this data up to my online host, where you can view it in real time. Oppps,I forgot, at present it's raining and near the end of the day, so no solar input until the sun shines again, but you can see it by looking at the trend page and scrolling back in time via some buttons I have on the trend page. http://paulalting.com/hydrosolar/hydrosolar.php

These devices are really quite good as they isolate the sensing side from the measuring side, allowing you to measure current paths not connected to your Arduino supply, which I think is a good thing for many people.


Paul

A 10 Ohm 1/4 watt resistor for your test load will produce a little output for a mS or so while it's going up in smoke...
P = I * V 1 A X 12V = 12 watts != 1/4W... 10 120 ohm 1W resistors would be ok for short periods of time if you monitor the temperature... A "Digital: Wattmeter" or your index finger as it's commonly known as. When the resistors get hot they will also change value...

Doc

Ok, wanted to re-open this thread because I've got some new insights and components. I went ahead and got the ACS712 breakout board from Sparkfun. There were quite a few examples and projects with this board, so I figured that more documentation would mean an easier time for me. And that was mostly right.

The primary issue I have now is that when no load is attached the current is measured at -.61A. The sensor puts out 2.37V, which is 487 on the 0-1023 scale, and equates to -.61A. The formula I'm using is amps = ((ACS_voltage_units*.0049 - 2.5)/.185). Looking at the ratings on the stuff I'm powering, it's unclear why this is happening. My wiring diagram follows the attached picture. So I have three questions:

  1. Is there a callibration step that I'm missing with my ACS712? Is there something I can do in hardware to offset the variation?
  2. Is it more likely that it's a -.61 offset or that it's an offset plus rate thing. I.e. true amps = x + .61 or true amps = x*1.1 + .61?
  3. Since it's a hall effect sensor, is there any risk of interference from other wires around it? (note: this seems unlikely since the sensor is at least 5 inches from any other wire.
  4. Since I'm measuring current before the interver, there is probably some additional current baked into the measurements that is going to the inverter. Is there a good way to estimate how much that is adding?

Additional Info:
To refresh, I'm measuring current from a battery to an inverter as part of a solar electric project. That current is being measured by my ACS712 and fed into an Arduino for storage in my database. I did a bunch of different tests yesterday and the good news is that I'm able to get consistent readings that vary depending on the load that's connected to the inverter. For example, my router is measuring .57A where my small CFL lamp is measuring 1.7.

  1. Does the reading change if you turn the sensor upside down? It might be responding to stray magnetic fields. The contribution from the earth's magnetic field should be no greater than 0.054A.

  2. What is powering the Arduino? USB power tends to be very noisy, and is unlikely to give you good results.

  3. Do you have anything else connected to the +5V and ground pins you are using to connect the ACS712?

  4. Which variant of the ACS712 are you using: the X05B, X20A, or X30A?

Unfortunately, the datasheet doesn't appear to specify the maximum zero offset error. It does specify upper and lower limits on the sensitivity.

  1. Yes, if I turn the board so that the sensor is facing down, the offset gets even higher. So instead of -.61, it reads -.64 to -.66.

  2. The Arduino is being powered by micro-usb. I've got a voltage regulator on the way, so that this will be powered directly from the battery.

  3. Nothing is connected to the 5V pin, but there are two voltage divider circuits connected to the GND pins. However, disconnecting these other circuits has no impact on the current measurement.

  4. It's the 5A X05B model.

zcapozzi:

  1. Yes, if I turn the board so that the sensor is facing down, the offset gets even higher. So instead of -.61, it reads -.64 to -.66.

  2. The Arduino is being powered by micro-usb. I've got a voltage regulator on the way, so that this will be powered directly from the battery.

  3. Nothing is connected to the 5V pin, but there are two voltage divider circuits connected to the GND pins. However, disconnecting these other circuits has no impact on the current measurement.

  4. It's the 5A X05B model.

OK, it sounds like the -0.61 is an offset you will have to allow for. If it stays the same when you are powering the Arduino from a good regulated 5V, then I suggest you subtract 487 from the raw reading (rather than 512) and convert the resulting difference to amps.

Connecting the voltage divider circuits to the same ground pin is fine, assuming they are low-current voltage dividers used to scale down an input voltage into something that the analog inputs can handle. OTOH power, output devices and digital sensors should be connected to a different ground pin or pins.

EDIT: note that the zero offset is temperature-sensitive, see the datasheet for details.

EDIT: the formula I think you should use is:

amps = (R - Z) * C

where C = 5.0/(1024.0 * 0.185)

where R is the analog reading and Z is the reading at zero current.