Академический Документы
Профессиональный Документы
Культура Документы
forum.arduino.cc
Hello everyone!
1 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
work just fine when there is current flowing? I don't get it.
I guess I should mention that I have tried three different Arduino
boards (2x Uno and 1x Mega) and two separate ACS712 sensors
and I always get the same results.
The idea to measure the zero current was to establish the base
sensor voltage to get accurate starting point. Then a small current
is applied to the load (about 100mA) for 500ms to check if the
load is still present and connected. At this point I absolutely
cannot set the zero point and I cannot check the presence of the
load. With no current and 100mA my readings are just crazy.
An example:
The code starts by checking the input voltage on analog in to
establish sensor zero point. Supply and load are disconnected.
The reading I get is... pretty much anything from -10A to 10A.
Let's say that it gets 3.0A as an example here. Then about
100mA is applied for 500ms and the reading goes from -5A to 4A.
As it is averaged as a result I might get the final result as -1A and
that's it. It's a lot less than the expected 100mA and the circuit
goes into error mode saying that the load is disconnected.
If the check current is set to about 1A it might work better but the
initial zero point reading is all over the place so as a result the
circuit will go into shutdown mode anyway.
Thanks!
Yes, the capacitors are installed. I got those little boards with
ACS712, two caps and terminals. Both are from the same eBay
seller but like I said, it seems more like a problem with the
Arduino analog pin than the ACS itself.
2 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
Thanks
When I disconnect the sensor from Arduino and just let the
analog pin float I get similar wild fluctuations.
Is schematic really needed for this? It's a very simple circuit with
Arduino UNO and the ACS712 - 20A on a separate board with it's
own capacitors. Both are connected to a 9V power supply (tried a
different supply and got the same result). +5V goes from the
power line on the Arduino board as does the GND and the signal
wire (this one goes to one of the analog pins). The 9V coming
directly from the power supply goes through a MOSFET, then the
sensor board and then goes to a light bulb. This is just a test
setup. In the final version the circuit is suppose to drive a large
12V fan. That's it.
I can draw a schematic but with such a simple circuit I don't have
one. It's all just done "one the fly".
This is the code that I'm using to get the current reading:
3 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
float current;
As you can see I'm trying to average out the current value by
doing 50 measurements. That does help a little but it's still not
enough because of the large spread that I'm getting. With just one
measurement the results were totally unusable.
Keep in mind that my current readings are correct. I checked
them with my Fluke meter and everything checks out all the way
to over 12 amps. The problem is only when the current is very low
- about 100mA or less and it's just crazy when there is no current
flowing. The closer to 0 the worst the problem is.
It doesn't make sense to me because if it was caused by noise or
improper grounding then I should see it all the time and not just at
0. It would make sense if 0 current was equal to 0V on the output
but since 0A equals about 2.5V on the output it doesn't seem like
noise or interference to me.
Is my code wrong?
4 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
A test sketch:
// Arduino Uno clone
// Arduino IDE 1.6.0
// Test for ACS712 5A
void setup()
{
Serial.begin(9600);
Serial.println("Started");
}
void loop()
{
Serial.println( analogRead(A0));
delay(200);
}
504
497
504
514
511
510
515
512
503
499
512
512
509
508
509
506
5 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
514
503
506
506
508
509
509
508
506
506
517
506
510
515
Using average:
void loop()
{
6 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
That results into something more stable, but it still is not very
stable.
507.39
507.76
507.34
508.48
507.54
507.44
508.07
507.42
507.70
507.80
507.48
507.23
508.52
507.11
508.31
Then I tried your snippet (inclusive the bad float to int conversion
for the return value).
7 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
void loop()
{
Serial.println( analogCurrent(A0));
delay(200);
}
0
0
0
0
0
8 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
0
0
0
0
0
0
0
0
0
Perhaps you should get another ACS712 module and test that.
Can you make a photo of your wiring ? and a schematic would be
very helpful because I don't know what you mean with: power
line.
Can you do a few of these tests, and confirm that you have the
same results as me ?
knut,
I don't understand why my calculation would return negative
values. Actually it doesn't.
That long decimal value calculates amp value from analog read
value (0 to 1023), then -2.5 is to get a zero point (ACS712 puts
out 2.5V when no current is flowing), 0.1 is the value in volts for
each Amp flowing though (20 amp version of ACS712). The final
value is the offset for my particular chip that is always reading
120mA too high and without it I would get 2.12A for actual
2Amps, and 3.12A for actual 3Amps and so on.
I don't understand what you mean by "try: read once -> return a
float". Like I said, I'm a novice when it comes to Arduino. Can you
explain?
Peter,
Your averaged result would be perfectly fine for me. The problem
9 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
is that I'm getting junk. I run it a bit more today and now I got
some really interesting results. I didn't make any changes
(software or hardware), yet it was different. For example, I got a
reading of -129 amps that was steady for a few seconds! Then it
went to positive 104A for another few seconds. It seemed to be
"sticking" at those extreme values. Weird... BTW, I wasn't trying to
measure the charge current on a Tesla Model S, there was
nothing connected to the sensor board - no current flowing and
no magnetic field present. After connecting a load (about 1.2A)
the reading was pretty much steady and accurate.
Anyway, the bad float to int conversion for the return value is my
mistake. What I did before was this: the reading was taken 50
times and then divided by 5. I just had this idea for using a
decimal value without actually using any decimal values. It did
work, but I was getting 10 instead of 1.0. I tried simplifying it for
you guys and actually made a mistake. Sorry about that.
10 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
As far as I can tell, what you did is okay. The cause is still a
mystery.
If both ACS712 modules are from the same seller, they both can
be from a bad factory batch. It happens.
The analog section of the Arduino can be damaged.
To solve this the fastest way: Use a new Arduino Uno, new wires,
new ACS712 module from a different seller and connect only the
ACS712. If that works, you can add the mosfet and the load.
Peter,
11 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
30mA) but not for long. No more than 10 - 20 seconds and then
the crazy dance comes back. The readouts I've seen today were
totally crazy... I mean, how could it get to some -120 odd Amps?
That's not even possible, is it? I would suspect the ACS but the
values I've seen are not possible with anything this chip is
capable of. Heck, that is not possible for the analog IN on the
ATmega chip! 100A would mean that there was -10V on the
analog IN pin and the A/D converter somehow went into negative
values. I've seen similar values a few days ago and that's why
I've borrowed some Arduino boards from a friend just to see the
same thing happen again today.
Either I'm doing something wrong or my PC is possessed Or
both.
The USB power could also have some influence. You could try a
power supply to the DC power jack of 7.5 to 12V.
Hey everyone,
I think I have found what the main problem was and it seems to
be a bit better now. I don't get the wild swings as I used to get
before. The culprit here was the number I was using in converting
12 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
Thanks!
This number was just too long and a buddy of mine told me that if
there is more than six digits after the decimal point it will start
acting up.
void setup() {
Serial.begin(115200);
float x = 0.0048875855327468;
float y = 0.0048876; //rounded slightly
Serial.println("x");
Serial.println(x,3);
13 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
Serial.println(x,6);
Serial.println(x,8);
Serial.println("y");
Serial.println(y,3);
Serial.println(y,6);
Serial.println(y,8);
Serial.print("y-x = ");
Serial.println(y-x,8);
}
void loop(){}
X
0.005
0.004888
0.00488759
y
0.005
0.004888
0.00488760
y-x = 0.00000001
14 of 15 02/11/2018 11:39
[SOLVED] ACS712 unstable and wild zero current reading (DC) about:reader?url=http://forum.arduino.cc/index.php?topic=306720.0
return current;
}
15 of 15 02/11/2018 11:39