Interfacing Allergro's ACS712 current sensor

Go To Last Post
47 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I am trying to interface the ACS712 Hall Effect current sensor from Allegro. It's a nice little chip with some neat features like; output voltage proportional to AC or DC currents, very stable output voltage offset, ratiometric output from supply voltage.

As far as to interface the sensor with DC currents, there nothing much to it, just sample the output subtract the 2.5V offset and multiply the difference with the output gain.

But it's a different ball game when measuring AC(50Hz in my case) currents, the output follows nicely the AC sine current but the 'zero crossing' is at the offset voltage (+2.5V).

Now my question, how can I synchronize the ADC sampling to read peak current, and in mean time to read or count the frequency?

I tested the sensor with the scope and a AC voltage meter, and the sensor is working fine. I get a nice sine wave on the scope when there's AC current flowing and on the voltage meter I can read in AC millivolts the peak current.

So the sensor is working, but I am wondering will I need some additional hardware to read AC current or could I implement it in software to measure the peak AC current and the frequency?

Marc.

Edit, removed some typo's.

Last Edited: Sat. Jun 30, 2007 - 06:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To mesure peak current you need diode and capacitor,
to measure frequency you need resistor devider and AVR internal comparator.
Alexander.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whoa. Just sample with the ADC fast enough (say 10X the sine frequency or higher). You can find peak points pretty easy. Zero crossings are pretty simple also. Just look for one reading on one side of zero and the next on the other side of zero; if you need more accuracy, just interpolate. No need for diodes, R or C.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This job can be done in the analog domain or the digital domain using the algo Jim has suggested. Need some specs tho... what is the max current? how small a difference do you want to see? Example... you hang this gizmo on the incoming ac that can supply 10kw and you want to see when you plug and unplug a 1 watt wall wart in the computer room? Need 1 part in 10 thousand... 14 bit a/d. But you might not need that extreme resolution.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alexander thanks for the answer, if figured something like that but I prefer a software method.

Bob, I am using the +/-5A optimized current sensor (max 10A), maybe in the future I’ll need the +/-20A sensor. The lowest reading (it’s more used as a part fail detector) is 10W and the max will be 1500W with a 220V AC supply.

Thanks Jim, that’s what I think I am gone to use.

So to calculate the period I need to subtract the time(r) values from the successive highest and lowest ADC readings multiplied by two? So I need a ‘time stamp’ from the ADC readings to calculate the period?

Wouldn’t the use of the comparator be simpler in that case?

I just started to read the documentation on the comparator trigger function for TIMER1. I guess I can use this function to trigger the timer and then calculate the period of the frequency. To increase accuracy I would use this trigger to start the ADC readings near the peak values, say 10 readings (or more) at a frequency of 10X the source frequency. Could that work and will I need the resistor divider to make the comparator to function?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fleemy wrote:
So to calculate the period I need to subtract the time(r) values from the successive highest and lowest ADC readings multiplied by two? So I need a ‘time stamp’ from the ADC readings to calculate the period?

While reading my answer I now see it’s easier then I thought.

As the ADC reading interval is fixed, I just need to count the number of readings between the highest and lowest successive reading, multiply that with the ADC interval and then by 2, to have the period of the frequency, right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Right.

You may want to average over several periods because the max and min you find may not be the actual max and min of the signal. That depends on your sample rate.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, thanks Jim.

I'll try some code and put it here(that will be working at night as I need to share my time between work, my 18 month and two week old sons, the wife and then the programming…).

Marc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So its like a 'refridgerator is running' detector.... one approach might be... take a/d readings into a buffer for a half cycle... 8ms.... scan the buffer to see if any sample is farther than N counts away from 0 amps (about 512 on a scale from 0 to 1023). Assuming +-2.5V means +-5A at 220V, that would be 1100W at plus or minus full scale, so 10W would be about 5 counts above or below 512.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Bob,

Well yes it's for detecting a coil (10-12W) failure on a solenoid valve, the lowest consumer, and defrosts resistances witch are the highest consumers.

The sensors outputs a 2.5V offset when there’s no current flowing through it. It output’s 180mV/A (for the +/-5A sensor) above the offset for positive currents, 180mV/A under the offset for negative currents. So when applying AC current to the sensor, the output swings above and under the offset voltage at the AC frequency.

The sensor is ‘calibrated’ for +/- 5amps, but the range is 10A.
0.180 x 10 + 2.5 = 4.3V and -0.180 x 10 + 2.5V = 0.7V, so there’s even some room left between the 0-5V rail.

So that leave’s me 9 bit’s of accuracy, if I use the input directly from the sensor. But that will be enough, as I will have approx 6W of resolution for the 10A range.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been looking at these. The datasheet seems to indicate these devices have noise in them. You can reduce this noise with a capacity but this also reduces the response of the devices. When I looked at them it seemed to suggest the best accuracy was 100mA? Has anyone else found this or did I read them wrong?

I ask this because you might well not end up with 9bits of accuracy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The sensitivity is, depending on the selected sensor, 66 mV, 100 mV and 180 mV for the 30A, 20A and 5A sensors respectively.

The accuracy is 1.5% full range. As it is an analog component the limit in accuracy is the ADC.

The noise is quite significant (5A sensor); 20 mV for 2 kHz bandwidth and 75mV for the max 50 kHz bandwidth. But you could oversample the signal to cancel noise and increase the resolution in mean time.

But it’s true, I have less than 9 bits of accuracy if I read the raw signal on the ADC.

0A = 2.5V, 10A = 2.5V + 0.180 x 10 = 4.3V.

512 (9 bit counts) x (4.3 – 2.5) / (5.0 – 2.5) = ~369 counts for the full range.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I’ve done some testing, and as Trevor said there’s a lot of noise on the signal. Will do some new testing with different capacitor values you can connect to reduce the noise, but that also reduces the bandwidth. In my case it’s not really relevant as I only need 50Hz of bandwidth.

Here’s the test configuration:
I'am using a simple halogen lamp as current source.

The prototype board:

With the smd ACS712 sensor on the bottom side:

The pictures are not the best quality, as I took them with the cell phone camera.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have room to add rectifier :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Be really interested to see your results. I have just received samples of the devices myself so some info on the actual noise figures you are getting will be very interesting/useful. Are you able to show some scope traces of the noise?

Trev

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These is scope trace on my acs704-15.
Alexander.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've used these devices recently - you need to watch out for stray magnetic fields! don't put a relay or high current carrying tracks nearby!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

True, when I put a screwdriver (a little magnetized) near the sensor, the output reacts on it. In a real world application I would shield the sensor on both sides.

Kartman, did you use the bidirectional or the unidirectional sensor? The reason I ask is how did you interfaced the sensor with the µcontroller?

Some people advised me to take multiple readings and then get the highest and lowest values to calculate the peak to peak current; witch was what I thought also the way to go. The problem is that this method does not really give a stable output. The reason I think is that for AC measurements you need to stay synchronized with the signal, otherwise the readings are, what I would call ‘phase shifted’ now end then, witch makes the readings unstable.

I am changing the hardware a little to use the comparator input, feeding the negative comparator input with a fixed 2.5V voltage input from a resistor divider, and using the sensor output for the positive input.

The comparator interrupt (on toggle) triggers a timer, to calculate the period of the signal, but also to trigger the ADC at a fixed delay to read the signal as close as possible to both the peak values.

Could that be done and would it work? What are the other options?

As for the results so far, with some averaging (32), I’ve got it stable to 1 count until the reading goes out of sync.

Zauberer, I’ll try with the rectifier and see how it goes.

Thanks for the responses so far, I appreciate.

As I never went to school for all of this, don’t mind to tell me when I say something stupid.

This experiment is helping me a lot to understand how the µcontroller reacts to changes in code, and the limitations of the resources. Coming from programming in VB on a PC (just for fun) it’s a whole different world.

Marc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sensing current on a full wave rectified AC signal - I sample 10 times and take the highest reading. I don't need accurate current readings.

As for interfacing the sensor - the sensor output is biased to half VCC - I subtract this value in my code. Basically, I have the RC filter described in the datasheet then to the ADC input on the AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, so I only need the RC filter to rectify the signal for a smother output, just as zauberer mentioned. So I take the highest value from 10 samples, subtract 511d from it, then multiply that with 5/1023 and divide that with the square root of two, to have roughly the RMS value of the AC current.

Also as a side note; if I want to divide with floating numbers, is it better if I use (float)int * 1/constant float, or should I just use (float)int /constant float?

Marc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello dear,

Hope you will be doing fine, I am using ACS712 Hall Effect IC to build a power meter. I have developed the board by exactly following your circuit diagram and the ACS712 datasheet. Power meter is both for AC measurment. The signal I am getting on the output is bit noisy as when seen on Ociloscope, I have also checked the out put voltage on Multimeter, when i set the meter knob at DC voltage measurment it gives me some what constant values when i vary the load from 100 to 250Watts by connecting bulbs in series. the output reading it gives is 2.503 but it remains almost same for load from 100 to 250 watts.

But when i put Multimeter knob at AC voltage settings then i see 0.023V as no load value and 0.068V at 100 watts, 0.102 for 150W and 0.139 for 200W. now i want to interface this thing to MSC1200 MCU. Could you plz guid me in this regard? The AC signal is riding on a fix DC offset and i am not getting any idea how to interface it with ADC. kindly please guide me.

Please email me at asifhussain_au@yahoo.com, thanks for taking your time to read my email, i hope you will guide me and give me some help in this regard.

Looking forward to your reply.

Kind regards

Asif Hussain

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

multiplying is always faster than dividing using either floats or longs, and multiplying longs is always faster than multiplying floats. Evaluate that 1/constant with a calculator and multiply it by 65536 or some trick like that.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Examine app note AVR465 on the Atmel web site. This is an example of how to use the adc to perform true rms voltage and current measurements. Simple digital filtering is employed to remove dc offsets from the input signals allowing one to enjoy the full precision of the adc, and accurate results, while keeping the circuitry very minimal.

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for bringing up this old thread, but I just bought the ACS712 breakout, and I'm quite disappointed, as it looks like I have to use it as a SHUNT, i.e. to CUT the circuit where I want to measure current! Is that correct? I bought an hall sensor just to AVOID cutting the circuit, else I would just use a resistor shunt!

I want to measure a DC. How can I do this without modifying the circuit where current flows?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ACS712 measures the voltage dropped across its internal series resistance ... therefore you must insert the sensor in the current path. Such is life sometimes ...

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ACS712 is a hall effect device. The shunt is integrated into the package for convenience. Running your current carrying wire down the length of the package should measure the current in that wire. Not sure of the sensitivity when doing this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So... :?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So..... I answered your question. Which part wasn't clear?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Woops ... yes the ACS712 uses a Hall effect sensor ... have been looking at high side current monitors (max471, ina139, zxct1008) that do not use hall sensors and got confused. Sorry.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Deleted post. My thoughts were for AC meter.

It all starts with a mental vision.

Last Edited: Tue. Jan 10, 2012 - 02:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
So..... I answered your question. Which part wasn't clear?

You and Valusoft gave two exactly opposite answers to my question! :D

But now that valusoft fixed his one it's more clear. :wink:

I'll perform some tests.

The breakout I have mounts a "05B" chip, which means "max 5A"; actually I have to detect up to 30 A; I wonder how far from the wire I have to place the sensor...
But above all, I wonder how to produce 30A just for testing... :shock:
I'm going to measure the current coming out from a 67V/25Ah battery to power a 1500W electric motor: it's an electric motorcycle, but I can't put it in my room for testing.. :lol:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use 12 V battery and a number of car headlamp bulbs. Note that they will get hot. For 30 A you'll need 360W worth. Probably three or so bulbs required so wire both the normal and high beams and that should give around 100W a piece. Put your sunglasses on!

One thing that I found when I was playing with these devices is that if you overload them, they seem to stick at full scale. Maybe someone can confirm this? I'm thinking they get magnetised.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wonder which cables I would need to carry 30 A when connecting the three lamps without putting fire to my house...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why wonder when you have Google? Since we don't know where in the world you are, I don't know if you want the cable size in AWG,SWG or sqmm. Anyway, Google 'ampacity table', which I just did:

http://www.allaboutcircuits.com/...

Also, don't forget about a fuse - a lead-acid battery will give hundreds, if not, thousands of amps into a short circuit very easily.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

 

Im working on a project where im using ACS712 5A hall effect current sensor to measure the current. i have connected the output of the sensor to the amplifier circuit (taken from the ACS712 breakout board) with op-amp(OPA344) with gain ranging from 4.7-47. i am using MCP3202 12 bit ADC with the data being sent to the raspberry pi. I came across this link :

http://www.academia.edu/4570516/Allegro_ACS712_current_sensor

 

where i got a formula for current but without the gain taken into account. can someone help me formulate the current equation with the gain?

 

Last Edited: Sat. Apr 18, 2015 - 05:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are you putting an opamp on the output of this sensor? To increase sensitivity? If do, look at the noise specs.
As for the formula - the native output is 185mV/A. Since you havent told us what the opamp gain is, how can we help apart from saying you multiply 185mV/A by your gain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

More importantly... why are you asking your questions on this Atmel website? You are using a Raspberry Pi and a Microchip op amp. You are not using any Atmel product.

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes i am giving the output of the sensor to op amp to increase the sensitivity. I did mention the range of the op amp gain. It can be set from 4.7 to 47 using a potentiometer.

And if i take the max gain of 47, how should i proceed with the equation?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You seemed to have missed my comment regarding noise. You'll find out the hard way it seems.

 

Let me see, 185mV/A times 47 = 8.696V/A. The device also sets 0A at 1/2 VCC, thus at 5V, the output is entered on 2.5V. With no external gain the output at 1A is 2.5V + 0.185V, 5A is 2.5V + (0.185 * 5)

 

I just had a look at the data sheet - it says noise is 21mV - that works out to around 0.1A in terms of the reading. Multiply that figure by 47 you get nearly 1V of noise.

 

I'd suggest you stop and reconsider the problem as you'll not get 1mA resolution out of this device. What are you trying to measure?

Last Edited: Sun. Apr 19, 2015 - 06:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im sorry i must have forgot mentioning noise. Im very new to this. I read in one of the blogs that averaging the current output for certain number of samples will eliminate the noise.
Im working on an exeriment to measure the current change through a concrete sample. so i have to measure low current values. Hence im trying to take help.
what should i do to make it work?

Last Edited: Sun. Apr 19, 2015 - 06:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Im working on an exeriment to measure the current change through a concrete sample.

 

 

That tells me very little of what you want to achieve. I had no idea that concrete was a conductor. 

 

I'd suggest you get your ACS712 setup working and then you can tell me if it was successful. You can verify the operation by passing a known current through the sensor and correlate that to the reading you get.

 

If not, then you might want to tell us exactly what you want to measure and give some requirements, otherwise we have no idea. If you want a good answer, then you have to pose a good question.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

 

firstly, the current sensor is connected to the concrete sample which is undergoing chloride penetration. 60v DC is applied across the concrete sample. i have to measure the current flow through the concrete as the penetration of chloride increases.

since the current is very small, i gave the sensor output to an amplifier circuit (taken from the ACS712 breakout board image file attached for the reference). Im not sure if the circuit is correct for the purpose.  i connected the output to the multimeter but i get some random values. can you help me with this first?

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

suvrat13 wrote:

...since the current is very small...

 

How small?

 

I can't help thinking that using a device designed to measure +/-5A to measure very small currents isn't going to end well.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The initial current is 30mA and it increases gradually. considering the noise of 21mV its difficult to read such a low value. hence i thought of using the amplifier circuit.

Last Edited: Sun. Apr 19, 2015 - 07:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

suvrat13 wrote:
The initial current is 30mA and it increases gradually.

and what is the maximum value it can reach?

 

Again, using a sensor designed for 5A to measure currents on the order of 30mA is not at all likely to end well...

 

You wouldn't use a 5m tape to measure 30mm - would you...?!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

suvrat13 wrote:

The initial current is 30mA and it increases gradually. considering the noise of 21mV its difficult to read such a low value. hence i thought of using the amplifier circuit.

 

The trouble is that your amplifier will amplify the noise by the same amount as it amplifies the signal.

 

A few more questions...

 

1) What resolution/precision do you need?

2) What accuracy do you need?

3) What acquisition time do you need?

 

As you are applying a DC excitation you could try following the current detector by a LPF to filter the noise off before further amplification.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about a 3.3ohm resistor so you get 3V3 @ 1A with a 10k in series with the adc input and a 100nF cap to 0V. 250uA resolution. Job done.