read analog voltage example

I have a 500k pot attached to the A0 port. The analog reading is 2.519 on my meter. However I am not getting a fixed reading on the serial monitor. the numbers fill up the whole page and are changing continuously.
What is wrong? is the pot too large perhaps? I am using 5v and 0v on the outside terminals of the pot and the inside terminal is reading 2.519 on my multimeter. This should be the reading on the serial monitor.

500K is pretty high impedance and will pick up lots of noise, a 10k would be better, but try adding a 0.1 to 1 uF capacitor from analog pin to GND and try averaging 10 readings.

int total, val;
void setup()
{
  Serial.begin(9600);
  val = analogRead(A0);
}
void loop()
{  
  total = 0;
  for(int i = 0; i < 10;i++)
    total += analogRead(A0);
  val = total / 10;
  Serial.println(val * 5.0 / 1024);
  delay(500); 
}

You'd be better off using 5k pots, 100 times lower impedance.

500k pots should work fairly well though, so long as the lead to it was screened, and you didn't read from
more than one analog pin in your sketch. I guess you had random wiring spread out over an area, not a
screened cable?

For impedances > 10k you should add a capacitor between the pin and ground of about 10 to 100nF to
hold the impedance low enough for stable readings when switching between analog pins.

This would go much better if you posted your code. JCA34F posted a good example, I suggest you use it. Also, read up on how the A/D function works.

Ron

And ... unless set otherwise the A/D uses the 5v supply as it’s reference - if that varies it might affect your reading

If the 5V supply varies it won't affect the readings, potentiometers are the definitive ratiometric sensor, just
make sure the pot gets its supply from whatever the ADC reference is.