Analog inputs not working properly

Hi everyone!

I'm using an Arduino Uno board and I'm having some problems with analog inputs. I have tried measuring the voltage applied to the analog pin, but regardless of the voltage supplied, I would get weird results every time. I'm using analogRead for this, and always would get the result between 350 and 360. If I connect the pin to 5V, analogRead returns values varying around 360. If I connect it to GND, I get values around 350. I can't figure out why I don't get 0 when analog pin is connected to GND, and 1023 when it is connected to 5V. Here's my code:

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);
}

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

I have tried this with all the analog inputs. Does that mean that something is wrnog with my board? Any help is appreciated.

Hey, I'm quite new to this myself so could be completely wrong, but why are you reading A0? doesn't this mean pin 160?

I have been following this tutorial: https://www.arduino.cc/en/Tutorial/AnalogReadSerial. According to it, everything should work as it is. When I try connecting my analog input to different voltages, I do get slightly different results, but not the correct ones. I am really new to this, could you explain how it is pin 160 and how to use that in code?

grobocop: I have been following this tutorial: https://www.arduino.cc/en/Tutorial/AnalogReadSerial. According to it, everything should work as it is. When I try connecting my analog input to different voltages, I do get slightly different results, but not the correct ones. I am really new to this, could you explain how it is pin 160 and how to use that in code?

Ah! But you have not followed the tutorial. Your line 3 does not exist in the tutorial. You are issuing a digital I/O configuration against your analog. What happens if you follow the example without the PinMode command?

And you have verified the potentiometer wiring +5V, GND, and A0 pins?

Hi grobocop

I've just tried your code on a Uno and get 0 when pin A0 is connected to GND, 1023 when it's connected to 5V and random values (as expected) if the pin is not connected and picking up electrical noise.

Suggest you check your wiring.

A0 through A5 are the names given to the six analog input pins on the Uno, the ones marked as such on the board. They are not hexadecimal values.

Regards

Ray

I have tried following the example also without the pinMode command, and I have tried it with all the pins, but every time the result is the same. When I connect the pins to different voltages, I do get different results, so I believe the problem is not the wiring, or could I be wrong? I suspect that there is something wrong with the board, but I'm not sure. Is there a way to check if the AD converter is working properly?

Hard to tell what's wrong without info. What values and results are you getting?

Just to check, you are using a jumper wire to connect A0 to GND or 5V on the Arduino? And you get values of 350 - 360, not 0 and 1023?

I'm sure you will have tried this, but have you used different jumper wires?

That is correct. When the pin is connected to 5V, at first one or two seconds I get high values (around 500) dropping rapidly to around 360, and the values stay from that point near 360 with minor fluctuations (value changes from 355 to maybe 365). When the pin is connected to GND, I also get the values dropping from around 500, but this time stopping at around 350 (values change from 345 to 355, more or less).

Same for all 6 analog pins? Have you checked for 5V on the 5V pin with a meter?

And try different jumper wires. Also, to eliminate the socket, turn the Uno over and use a fresh jumper wire to touch the solder pad under A0 (or whichever analog pin) and the pad under GND or 5V.

That solved it! I tried touching the solder pad under A0, and now I get the steady stream of 0 when I connect it to GND and 1023 when I connect it to GND. Thank you all very much for your help! This was driving me crazy

So it could be a faulty / dirty socket, or a "dry joint" in the soldering. If you have a small soldering iron, you could try touching the solder pad to melt the solder briefly to reform the joint.

I will try to do that. Thanks for the advice!