I am using an Arduino Uno. analogRead(A0)
(or whichever channel I use) returns 0 when it is grounded with Arduino Gnd, and 1023 when connected to Arduino 5v. But when I connect it to a current sensor (ACS712) it is always fluctuating like this:
0, 0, 0, 0, 0, 0, 1023, 1023, 1023, 1023, 1023, 441, 446, 0, 0, 0, 0, 1023, 1023...
I also tried it with a potentiometer (10K) and analog joystick: the results are the same. I tried changing different power supplies (both Arduino's and the sensor's (ACS712, potentiometer, joystick)). I even tested it on an Arduino Mega, but no luck. Such extreme fluctuation are making no sense to me. Kindly help me what could be the issue.
My wiring diagram is attached to this post. And I use an external supply to the ACS712. Is it possible that Static electricity is causing this issue?
Code:
void setup() {
Serial.begin(9600);
}
void loop() {
float value = analogRead(A0);
Serial.print("Raw:");
Serial.println(value);
delay(500);
}
Thanks.
-
1please add a schematic of your connectionsjsotola– jsotola01/07/2018 17:34:50Commented Jan 7, 2018 at 17:34
-
You say you are supplying the ACS712 from an external supply. Do you have the Arduino ground and the external supply ground connected? A full schematic would be more useful because possibly the problem is not in the part shown.Mark Smith– Mark Smith01/07/2018 17:43:11Commented Jan 7, 2018 at 17:43
-
2Maybe you are just measuring an AC current, in which case the "fluctuations" are normal and expected.Edgar Bonet– Edgar Bonet01/07/2018 17:45:30Commented Jan 7, 2018 at 17:45
-
@Mark Smith I am not using Arduino Gnd ACS712 is using Gnd from External PowerSupply....From Arduino I am only using its Analog Pin 0Hassaan Shah– Hassaan Shah01/07/2018 17:46:05Commented Jan 7, 2018 at 17:46
-
@Edgar Bonet I am using DC supply as current source to ACS712Hassaan Shah– Hassaan Shah01/07/2018 17:48:07Commented Jan 7, 2018 at 17:48
2 Answers 2
You need to connect together the grounds from your external power supply and the Arduino.
At the moment the two devices are floating - there's no commonly-agreed 0v point.
-
You are awesome...Thanks for your help much appreciated. Solved my problemHassaan Shah– Hassaan Shah01/07/2018 18:00:28Commented Jan 7, 2018 at 18:00
I had a similar issue with fluctuating values. Make sure you are setting in your code the analog PIN as INPUT
pin. On some boards you have to specify it explicitly, like this:
pinMode(A1, INPUT);