analogRead for pot, gives low value

Hello, I've looked around pretty good and cannot find an answer to my problem.

I was having this problem in a much larger program so I wrote a dead simple one and am having the same problem.

When I read a pot, it only returns the range 0-1021 instead of 0-1023. It wasn't always like this and I don't know what changed. Trying to fix it, I added a 1uF decoupling cap to the Arduino's 5V to GND with no change.

I'm using an Arduino Mega 2560

And here is my code:

#define rail_speed_pot 3

void setup()
  pinMode(rail_speed_pot, INPUT); 

void loop()
int rail_pot_val = 0;
rail_pot_val = analogRead(rail_speed_pot);
Serial.print("Rail Pot Value: ");

Why worry about a ~10 mV difference (1 part in 500) between the maximum value that you measure and the value that is theoretically possible?

I guess its not that big of a deal, I was just worried about the values changing further in the future, this project is for a friend that lives a few states away and I won't be able to fix it if there are further problems.

thanks, I'll just map it using 1021

Simple suggestion: did you try another pot ? Maybe a small physical problem on the pot imself. When simply wiring the input to 5V what is the reading ?

I'm using 3 different pots and they are all doing this now. It just seems unstable, now the values are changing slightly on their own over time when maxed out.

Wiring an input to 5V gives a value of 1023.

I found the problem, incase anyone is interested. Once I soldered the prototyped circuit to a solderable breadboard, the problem disappeared. I think there was some resistance from slightly bad connections in the prototype breadboard.

Thanks for the suggestions

I'm glad it was usefull :) Always try to test each parts individualy when doing troubleshoot.