Fluctuating measurements (+-15) with ACS712 current sensor

Hi guys,
first of all I have to thank you. I'm pretty new to Arduino and this Forum has already helped me a lot.

But lets go straight to the problem.

I want to measure the current and voltage of a mobile speaker. The voltage is measured correcly, but the current measurement is giving me a headache.
I'm using the ACS 712 5A current sensor on a Arduino Nano (china clone). The measured value fluctuates way to much for my application. This seems to be a quite common problem, but normaly the values are spread by +-2 or something. I did some testing and the best results I got were +-10.

There is nothing else hooked up to the Arduino.

And here are some of the results from my testing:

You can see 4 different measurements packed into one diagramm (its not really important which one is which). Bevor you wonder why 512 isn't the average, my PC somehow only outputs around 4V on the USB port. I can't see any pattern in the values. Sometimes they jump 15 up or down, sometimes they don't change at all.

I tried which impact the following changes have (and they all made almost no difference):
-Cable length of the sensor (20cm and 5cm)
-Time between two measurements (25ms to 250ms)
-Premeasurement (Measurment thats not used, 2ms Delay, Measurement thats used, 25ms Delay)
-Power Source (Desktop PC / Laptop without the Powersupply hooked up)
-0,1µF Capacitors between the 3 Pins of the Sensor (I tested every possibility)
-Pullup/Pulldown Resitor on the measurement pin
-No Current Flow through the Sensor/2A Current Flow
-Different Arduino Nano
-Tieing all the other analog Pins to ground
-Making a Lowpass Filter out of a Resistor (1k) and a Capacitor (0,1µF).
-Displaying the Voltage on a LCD screen, so I have no PC hooked up.

My cheap multimeter says that the output voltage is stable. I don't have an osciloscope on hand.
I even had another current sensor bevor, that showed the same behaviour. It was a ACS 711EX (+-15,5A).
I thought about smoothing the Value inside the Arduino, but the Problem seems to be so fundamental, that I decided to ask for help.

Here's the code I did the testing with:

const int analogPin = A0;  
int sensorValue = 0;

void setup() {
  Serial.begin(9600); 
}

void loop() {
  sensorValue = analogRead (analogPin);
  Serial.print(millis()); 
  Serial.print(" ");  
  Serial.println(sensorValue);
  delay(250);                     
}

Is there anyone else with these problems? Or is there someone with the same hardware and no problems?

I hope, I didn't forget any important information.

Thank you in advance,
Leo

Ok, I got a little bit of improvement.
The ACS711EX (15,5A) works fine now. But I didn't change a thing...

The ACS712 has capacitors on the board installed, like the datasheet recomments. I made Cf a lot higher. I think there was a 1nF capacitor mounted bevor, now I put in a 1000µF one (yes, 1000000x the original value). I get fluctuations of +-2 which i'm fine with. But I've heard, that such a big capacitor lowers the response time.

Tomorrow I will run a test with an audio amplifier as the load to see if I get accurate results.

It seems you have connected sensor supply to V-in.
And are running the Nano on USB supply.
Can't do that.
USB 5volt will now backflow through the onboard 5volt regulator to the ACS712.
The ACS will get 4volt at best, and you could destroy the onboard regulator that way.
Connect sensor supply to the 5volt pin.

Current measurements will depend on the 5volt supply.
That could fluctuate more on USB supply.
Don't expect very acurate results.

Put the 1n cap back in. A larger value cap only cuts the high frequencies.

Your code is for measuring DC.
Sound is AC.
All you do now is take a snaphot 4x per second
Leo..

Hall sensors are noisy, its not reasonable to try to measure small currents with them as
they require a reasonable magnetic field to work. Use a shunt current sensor for small
currents.

Thanks for the advice with V-in. I don't know what I was thinking there :smiley:

Wawa:
Your code is for measuring DC.
Sound is AC.
All you do now is take a snaphot 4x per second
Leo..

I get a little confused with AC and DC, because in germany it's called "Direct Voltage" and "Alternating Voltage", but they get use as synonyms to AC and DC most of the time. I want to measure the current that comes out of the battery, thats direct voltage, but alternating current. But but it's not alternating like a sine wave, it just changes in irregular patterns. And there is always a part direct current, the quiescent current. The Board shoud also be able to monitor the charging process (which is DC and DV).
I don't see how you can approach this without taking snapshots.

MarkT:
Hall sensors are noisy, its not reasonable to try to measure small currents with them as
they require a reasonable magnetic field to work. Use a shunt current sensor for small
currents.

Sounds logic. This whole project is just an excuse to get into Arduino and electronics in general, so testing different sensors fits me well :slight_smile:

Thanks for your support.
Leo

So you want to measure voltage and current draw (charging and discharging) of a mobile speaker/amplifier.
I would have used an INA219 breakout board.

If you want to use that ACS712 current sensor,
Amp current draw is DC but varies a lot.
Take as many samples as you can, and average them.
Leo..

That's what I was looking for :slight_smile: Thanks a lot!