ACS712 Current sensor resolution - Page 1
Forum section: electronics / projects

author: HugoPT
author_rank: Contributor
timestamp: April 04, 2015, 02:13:12 pm
content: Hello folks.I'm trying to develop a home automation project with OpenHAB and I need to measure when the lamps are on or off to inform the HomeAutomation software.I bought some ACS712 current sensor that measures current with a resolution 185mV/A.Today I wired the sensor with a lamp and my amperimeter but the sensor does not "move".My amperimeter measures 68mA, so it's way below the minimum current to make it "move" the output.My interpretation is unless I flow at least one amp thought the sensor it will not "move".Is this interpretation correct?I was reading about this and I found some users telling that I can insert an op-amp on the output but I doubt about this since if I am below the minimun resolution step it will just amplify noise.Is this also correct?Is there any way I can solve this, or should I move to another sensor perhaps ...Thanks for your time

author: amyk
author_rank: Super Contributor
timestamp: April 04, 2015, 02:46:37 pm
content: Hall effect sensors are theoretically completely linear, but in practice there is noise and in your case the datasheet specifies 21mV of noise for 185mV/A sensitivity so you won't be able to distinguish anything below ~114mA with it.

author: max_torque
author_rank: Super Contributor
timestamp: April 04, 2015, 03:14:57 pm
content: It rather depends upon what sort of "Noise" you get on the output. If that noise is "white" and equally distributed around the mean output voltage, with an ADC of sufficient resolution you SHOULD be able to DSP to get a resolution better than the noise specification!I suspect your multimeter in dc current mode will be doing some sort of averaging, so if it can see small changes in current, then the mean output of the AC712 IS changing with those current changes!

author: HugoPT
author_rank: Contributor
timestamp: April 04, 2015, 03:32:32 pm
content: QuoteOk this confirms what I was suspecting.Since my lamps are low current (LED Lamps) the ACS712 will not do the jobQuoteI'm using an Atmega 328 with a ADC of 10 bits.Doing DSP is out of this game.Can you recommend any device that could do this job?Thanks for your answers

author: nctnico
author_rank: Super Contributor
timestamp: April 04, 2015, 03:39:47 pm
content: You can do simple averaging. Technically it is DSP but not every DSP algorithm needs tons of processing power. For example:Code:in=adcvalue=((value * 15 + adc)/16This is easy for a microcontroller to do. The division by 16 is nothing more than a shift operation.Besides that you can increase the filter capacitor on the ACS712 to reduce the bandwidth and noise.

author: HugoPT
author_rank: Contributor
timestamp: April 04, 2015, 04:09:05 pm
content: QuoteYes but the value that I can get from the sensor is below the minimum sensitivity, so I can´t read nothing useful I believe. When I measure the output of it with no current I get 2.5V, when I turn the lamp ON I also get 2.5V.The lamp only needs 68mAEven if I do the average it will be useless i believe.I need at least to move a bit on the ADC to get something useful.Reading the datasheet I was expecting to see what is the minimum increment in current to move the output.They have there 185mV/A but how should I interpret this, can I assume each milliamp will produce 185 microVolts or it will just move when 1 amps flows producing the( 2.5V + 185mV) 2.685V?

author: PeterFW
author_rank: Frequent Contributor
timestamp: April 04, 2015, 05:07:31 pm
content: Quote from: HugoPT on April 04, 2015, 04:09:05 pmCode:Noise (VNOISE). The product of the linear IC amplifier gain(mV/G) and the noise floor for the Allegro Hall effect linear IC(?1 G). The noise floor is derived from the thermal and shotnoise observed in Hall elements. Dividing the noise (mV) by thesensitivity (mV/A) provides the smallest current that the device isable to resolve.21/185=~110mAThat means your masurement will be "of" by +-100mA, if you have a 60mA load on it and measure 0mA on the output that is withing the +-100mA accuracySeriously increasing the filter capacitance (Pin6) brings the noise down.I switched from the ACS712 to the INA226, awesome resolution and it has a digital interface.

author: HugoPT
author_rank: Contributor
timestamp: April 04, 2015, 06:06:17 pm
content: Thanks PeterFW.That clarifies me.QuoteI would also prefer to use a digital interface because using analog it would need "careful" measures to immune the signal from the sensor to the ADC.Unfortunately INA226 max input voltage is 48V, my lamp works @ 230AC .I'm wounder if there is a version for this voltage rate with a digital interface

author: nctnico
author_rank: Super Contributor
timestamp: April 04, 2015, 06:29:00 pm
content: IMHO it should be doable if you can average the noise away and filter for 50Hz or 60Hz (whatever your line frequency is). You'll need about 500Hz of bandwidth for this. I'd get some readings from the chip and save them to disk using an oscilloscope. The signal should be buried somewhere in the noise.Another option is to use a current sense transformer for line frequencies.

author: max_torque
author_rank: Super Contributor
timestamp: April 04, 2015, 08:38:59 pm
content: Assuming you are using a 5v reference, then your 10b adc gets you a theoretical resolution of 5/1024 volts/cnt, or 4.88mV/cnt.With a sensitivity of 185mV/A, each mV out of your current sensor is proportional to 5.4mA so your ADCs Lsb is equivalent to 26.4mA.The ACS712 has 21mV of noise, so thats +- 4 counts on your adc.A suitable averaging function should be able to resolve your 68mA current, but you may well need to use an AutoZero type strategy to get the highest accuracy, as you are dealling with just a few cnts.If you oversample of ocurse, then you can use that noise to your advantage! Depending on how fast you need to update your current information, you should be able to get at least 11b resolution with oversampling. Alternatively, use a hardware low pass filter on the current sensor, to "average" out the noise floor

author: Seekonk
author_rank: Super Contributor
timestamp: April 04, 2015, 08:53:11 pm
content: You should have purchased the 5A version of the ACS712 instead of the 30A. I buy only the 5A version and pair it with a shunt when I need to. I don't see how anyone would put 30A through one of those.

author: Dragon88
author_rank: Regular Contributor
timestamp: April 05, 2015, 02:05:04 am
content: Since you said your device has a resolution of 185 mV/A, I will assume you have the 5A version.Yes it's possible to use this device for your project. I built a little current monitoring device with the ACS712 that gives LED indications at 10 mA, 100 mA, 150 mA, and sounds an alarm at 200 mA. It wasn't easy though, this isn't really the right device for the task, but it was what I had on hand. I had to use a low noise opamp to amplify the signal, then carefully tweak the threshold values in the code (ATTINY85) controlling the whole thing. I seem to recall I used a low pass filter as well, and a very large cap on the filter pin of the device. Much larger than called for in the data sheet.Use a good opamp, then carefully adjust the threshold value in your code. Since you just need to trigger at 68 mA, that's within the capabilities of the device from my experience.

author: nuno
author_rank: Frequent Contributor
timestamp: April 05, 2015, 12:24:00 pm
content: Quote from: HugoPT on April 04, 2015, 06:06:17 pmYour signal being AC will average 0 current if you don't measure "at the right time".

author: HugoPT
author_rank: Contributor
timestamp: April 05, 2015, 06:38:50 pm
content: Dragon88 can you share your circuit?I will do some test with my scope and an Op-amp to get some conclusions

author: Dragon88
author_rank: Regular Contributor
timestamp: April 05, 2015, 08:47:29 pm
content: The circuit was very similar to Sparkfun's breakout for this chip:https://www.sparkfun.com/products/8883http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Current/ACS712%20Low%20Current%20Sensor%20Board%20v14.pdfBut I used a fixed gain of 100, and a much larger cap on the filter pin of the ACS712. They have a 1nF on their schematic, so I probably used like 100 nF. It made a big difference. However your requirements will be a little different with an AC signal.

author: Dragon88
author_rank: Regular Contributor
timestamp: April 06, 2015, 02:47:11 am
content: It occurred to me that you should be able to do what you need with a very simple circuit. Use a lot of gain on the opamp to have a noticeable change when current is flowing. Then use a peak detector circuit with a silicon diode. This will do two things: drop the quiescent output below a logic high when no current is flowing, and also maintain the positive peak through the negative alterations (actually the other way around since the opamp is inverting). Send that to a schmitt inverter or buffer. Then you'll have a logic level you can do whatever you want with. The adjustment in the circuit will be with the gain of the opamp, to get a logic output change when the 68 odd milliamps is flowing. A rough adjustment should be enough, i.e. something over 50 milliamps or so means the lamp is on.

author: HugoPT
author_rank: Contributor
timestamp: April 06, 2015, 11:08:17 am
content: Hi Gragon88Last night I do some measures with the scope.In my test I used the lamp I'm trying to get the status running @ 230VAC and measure the output of the ACS712 with the scope. Like I notice before even on the scope the voltage does not change when I turn the lamp ON! I discover why does this happen when I set the channel of the scope to AC coupling. Turns out when I'm sensing AC current the hall-sensor outputs a AC signal, that in fact changes the voltage(AC) when the lamp is ON. This explains what I was troubleshooting .Just to confirm then I disconnect the lamp an put a DC current flowing in the sensor, and I works as expected I can see the output in DC mode changing on the scope and on the multimeter.This solves the mystery in my head, next step I will use your suggested circuit and suppress those 2.5V base in a differential Op-Amp using a virtual ground, then I will amplify the little AC signal to a minimum of 1V(I still need to calculate the gain) and rectify the AC signal at the end of the op-amp to get something I could use.Do you think this will work?This is a critical detail the manufacturer should have include on the datasheetThis guy explains well the problem when probing AC signal

author: nctnico
author_rank: Super Contributor
timestamp: April 06, 2015, 12:19:53 pm
content: I'd AC couple the signal from the current sensor to the opamp. There is no way you can match the 2.5V accurate enough to not cause a large DC offset in the output. Just watch out for the frequency dependant behaviour (simulate first).

author: Dragon88
author_rank: Regular Contributor
timestamp: April 06, 2015, 09:02:01 pm
content: Quote from: nctnico on April 06, 2015, 12:19:53 pmThis is true. I was just making a one off device, so I didn't need to correct for the offset precisely. I used a small trimmer resistor added in the 10k/10k divider setting the reference voltage, and this was close enough. The remaining offset was corrected in software, or actually just ignored because my threshold values took them into account. Sparkfun went with trimmers for their board, which is ok. But I bet a lot of people that buy that product don't calibrate it correctly.HugoPT, since you just need to know when current is flowing, I would completely ignore the negative alteration. The ACS712 already has the 2.5V offset on the output, so there's really no need to couple that to AC just to rectify and go back to DC. If you go with the peak detector I described above or something similar, the presence of the positive peak will be held long enough for the micro to read it and know the lamp is on. When the lamp is off the DC value will fall back to 2.5V minus the diode drop.Again I'm saying this assuming that you don't care exactly how much current is flowing, just that something around 70 mA is flowing meaning the lamp is on. Otherwise the lamp is off. That's very simple and I would keep the circuit simple.

author: HugoPT
author_rank: Contributor
timestamp: April 06, 2015, 10:23:19 pm
content: Hey friendsI already make some progress.I mount on the breadboard the circuit you recommend to me with the peak detector. It can produce something useful to get the lamp status.I still need to try different gains in the op-amp since right now the difference between Off and ON are just about 640 mV on the output. This is fine to get the lamp status but I would like to get the output more saturated when the lamp is ON to get a larger hysteresis.I notice on the scope that when I switch the lamp ON the signal spikes a bit.I don't want get multiple samples on the micro controller because it will be busy on other things, I will just ask the lamp status to the sensor about every 2 seconds.Just to confirm the formula to calculate the gain I'm using is:Gv=(R1+R2)/R1Is this correct?Thanks for your great help and support

author: Dragon88
author_rank: Regular Contributor
timestamp: April 07, 2015, 12:25:45 am
content: Gain equation for an inverting opamp is -Rf/Ri.http://www.elexp.biz/tips/invert.gifOnce you get the circuit working, you'll have to consider how long the peak detector takes to discharge, or more specifically the cap. That's going to depend on the size of the cap, the load, and if you add a bleeder resistor in parallel. You'll need a balance between holding the peak during negative alterations, and the delay before being able to detect the lamp was switched off.If you get the voltage levels right you should be able to sample this with a digital input instead of analog. Though a single reading of either is pretty trivial unless you have some really tight timing.

author: Seekonk
author_rank: Super Contributor
timestamp: April 07, 2015, 06:31:27 pm
content: I would do a non inverting op amp with a fairly low gain 36K/10K with the low side resistor going to a 100uF electrolytic to common. That will keep the DC output nicely at half the supply voltage and slightly amplify the AC portion.