When I run the Potentiometer example (http://www.arduino.cc/en/Tutorial/Potentiometer) on my Mega 2560 board, I keep getting only 9 distinct values. In the table below, the first column is the input voltage measured on the input pin by a multimeter , the second column is the corresponding analogRead() output.
0V-1.36V
0
1.36V-1.72V
15
1.72V-1.80V
31
1.80V-2.04V
527
2.04V-2.11V
559
2.11V-2.17V
591
2.17V-2.19V
799
2.19V-2.35V
1007
2.35V-5.00V
1023
So for example for any voltage in the 1.36V-1.72V range, analogRead() returns 15. This behavior is the same on all analog pins and is not definitely caused by an incorrect wiring. I tried this on a UNO board and it works as expected - 0-5V is correctly linearly mapped to 0-1023.
I'm getting 527 (no fluctuation) without the potmeter.
I also tend to think that this is a hardware problem. Do you have any idea what could cause this? I'm not 100% sure but I think that analogRead() worked fine on this board before.
Yep sounds like HW problem. As the ADC is multiplexed for all pins they will all fail. It might be broken with some experiment or an accident. I blew up an LCD once by connecting the backlight to 12V iso 5V (was a nice short flash).
The pins might still work as digitalOut pins. pinMOde(A0, OUTPUT); digitalwrite(A0, HIGH/LOW) etc.