Using AnalogSensor Class for ACS712 Current Sensor

Summary: Gave up on getting accurate current readings from ACS712 analog sensor.

I figured out how to derive an AnalogSensor class for my ACS712 current sensor.

Plugged into AD1, yellow wire (outside pin) wired to the ACS712 output.

The readings (with zero current or with known current) are not consistent through the port.

The port supplied “5V” is constantly varying from 5.09 to 5.12v on my multimeter.

The sensor’s zero reading varies from +4 to +20 above 2048.

And the real killer, was the mV_per_Amp is spec’d at 185 (+/- 5), but it did not seem close to how the sensor was reacting.

When I set the seen “5v” and the seen “reading bias”, to show readings around 0.00 amps with no load, I had to use a much larger “constant” to get the sensor to correctly report my known 43ma load, but very quickly the conditions would change and the reading was off by 50% to 100%.
So with the voltage reference changing and the zero bias changing, the readings are all over the place.

Maybe my $3.70 sensor is “wacko”, but now I definitely am…

I give up. Carl doesn’t really need to know how hard he is working as long as he stays close to the recharge dock when his juice is getting low.

Here is my code:

Sensor Description ACS712 +/-5A Current Sensor, outputs Analog Voltage 185mV/Amp around 2.5v on port AD1 
pinmode INPUT
portID 3

Maybe it might be worth trying a different library and see if the same thing happens again. If it does, then maybe your sensor is “wacko” for good and needs a replacement.

Here’s one I found on GitHub. It looks promising, although you have to do the translation into Python - it’s in C++.

1 Like

Thanks @RobertLucian for the example. It confirms my approach, and offers an auto zero calibration method and an AC current measurement method.

That and a few other net articles have put the nail in the coffin of my sensor.

Having given my robot “continuous life”, (versus the easier “contiguous life”), creates a psychological block to shutting the bot down to insert my multimeter for trusted current readings.

The reason for wanting to recheck the exact current draw is due to the decline in “playtime” seen. I believe my battery set is only delivering 70% capacity after 110 cycles, but when I put the cells, individually, into a reconditioning charger for three cycles they briefly deliver 85% capacity and then again return to delivering 70% by the third or fourth cycle in the bot.

It may turn out that Carl, (or more difficult to convince, I) will need to accept a life of 4 hours play interspersed by 3 hour limited activity recharging. (I’ve been testing pocketsphinx speech reco lately, and found that the changing load can fool the recharger into an early full detection. Then Carl gets off the dock too soon and logs an even shorter play session. )

I’m also testing using a lower playtime limit of 8.0v (1.075v/cell) which yielded 5.2 hours of playtime overnight while I was sleeping. in his current incarnation, Carl doesn’t need to be playing while I’m not around to enjoy playing with him, but I couldn’t bring myself to shut him down for the night.

Clearly I have too much time on my hands to be so worried about the amount of Carl’s playtime.