Inaccurate analog reading and interrupt problem

The analog reading will be the ratio of the input voltage over Vref, multiplied by 1023.

If Vref is 5V (the default, unless you supply a different Vref), the only way to get a 1023 out is to put 5V in.