const int analogPin = 0;
0 is not an analog pin , it is RX SERIAL PIN.
The sketch that works has this declaration:
const int analogInPin = A0;
Do you see the difference ?
"0" is digital pin 0, so using this for an analogRead statement will not work. (It would work with for an ATtiny85 but explaining why to you right now would just confuse you).