Using the Mega 2560 and pin A0 to measure 0 - 4.5 volts. Analog reference set to DEFAULT.
The problem is that the measurement with analogRead() works as it should only as long as the Arduino is connected to the PC via the USB cable.
As soon as I disconnect the USB cable, the measurement returns either 0 or 1023 but nothing in between.
I don't have anything connected to the AREF pin, but I think I don't have to if I'm using DEFAULT reference.
I'm using a serial LCD display to print the measurement values. I'm powering the board through its Vin pin via an external 5 volt regulated supply. Do you think that might be the cause?
Any pointers on what I might be doing wrong? Why would the analogRead() work fine when the board is connected to the PC, and not work when it's disconnected from the PC?