Analog Inputs seeing incorrect values when reading from bread board.

Hi,

I'm new to Arduino, and recently bought the Arduino Uno Rev3. I was just testing out how analogRead works, and am having some issues. My code is the following:

int sensorValue; void setup() { // initialize the digital pin as an output. Serial.begin(9600); }

void loop() { sensorValue = analogRead(A4); Serial.println(sensorValue); delay(10); }

I'm just looking to get the current analog value every 10 msec. To test, I connect pin A4 to the on-board 5V analog output on the Arduino, and I see a value of 1023 being outputted. When I connect pin A4 to the on-board 3.3 V, I see 667 (with a few 668) being outputted. Lastly, connecting to the on-board analog GND gives a value of zero.

However, when connecting A4 to the output of a voltage divider (EXTERNAL 5V source voltage, with two 1K resistors in series, and EXTERNAL GND), I expect to see a number that corresponds to 2.5 V (as my multimeter shows). However, I seem to just be getting random values, as follows:

613 808 970 557 1008 753 661 1023 589 859 919 559 1008 706

Am I using this Arduino incorrectly? Should note that when I use the onboard 5V and GND for my 1K/1K voltage divider, I see a value of 510, as expected. Any help is appreciated.

What do you mean by external 5v source and external ground?

If you take a perfectly isolated source like a battery, totally unrelated to whatever is powering the arduino, and make a voltage divider across it, and connect the output of that to the addition input without connecting the ground of the battery to the ground of the arduino, you will get random voltages.

This is because voltages only have meaning relative to another voltage. When your Arduino pin says you have one volt, it means that the voltage is one volt higher than ground.

But what is the output of our isolated 2.5v divider battery? It's 2.5v above the voltage of ITS ground reference, aka it's negative terminal.

If the voltage at the negative terminal of the battery is the same as arduino ground, you get the expected voltage. But if the grounds are not connected, and the only union between arduino and the divider is one wire, then there is no reason the two voltages should be equal. In effect, the batteries, the divider, and the wire, form a big antenna, to pick up all that random electrical noise you see in the ADC readings.

Another note, you can't always just connect the grounds of two circuits like you can with the batteries. If the grounds are at different voltages, but not isolated, there could be a short circuit.

And if I misread your description and your circuit is not as I described, my apologies for the long winded post!

1 Like

In short you must common the grounds.

By the way, an insidious form of this problem can arise with USB ground-loops. Lets say we have two Arduinos UNO's and send signals between them. I have occasionaly had erratic results. I then realized that I was inadvertently depending on grounding back thru the USB circuitry. Connecting the grounds of the Arduino's directly cured the problem.

Joe

One year later, I too have just experienced analogRead() behaving the same way and wondered why. I am so happy to have found this post.

EternityForest, if you see this: your response was perfect!

Can anyone clarify this:

Another note, you can't always just connect the grounds of two circuits like you can with the batteries. If the grounds are at different voltages, but not isolated, there could be a short circuit.

How can they be connected but isolated or whatever is meant here?

At first I want to assume I could just connect the grounds; but if that's not true, I'd like to know how to avoid problems.

Thanks! -Phillip