int sensorValue = analogRead(A1);
Serial.println(sensorValue);
to print the value on analog pin 1. When I connect A1 to the Arduino 5v pin, i get 1023 (as expected), when i connect it to the Arduino ground pin, i get 0 (also as expected), but if I connect my pin to a 5V supply, I get
1023
0
0
445
1023
0
0
0
1023
. The 445 is usually a random number between 0 and 1023. Why does this happen? When I have the A1 pin not connected to anything it just gives random values between 0 and 1023 (as expected), but as soon as I connect a wire to the pin even if that wire isn't connected to anything, I start getting this weird pattern again. If I connect the pin to ground the same thing happens. Moreover, my multimeter doesn't measure any voltage on the Arduino 5v pin, what is going on? I am powering my Arduino Nano through a usb cable, and it's using the old bootloader.
Analog (and digital) inputs will show garbage (noise) when not terminated. If your analog input is not connected to a circuit, then it is just picking up electrical noise from the environment. Attaching a wire that is not terminated at the other end will only make the issue worse, as the wire will act as an antenna.
Do you have a common ground? The ground on the 5V supply needs to be connected to the ground on Arduino in order for it to measure voltage on the supply.
The problem was fixed by connecting the Arduino's ground to the supply's ground. I am still curious as to why the Arduino was reading the data in such a pattern, if it was random noise, it wouldn't be this rhythmic, would it? (1023, three 0-s, 1023, two 0-s, random number, repeat).
If the noise is BAD is mostly going to be randomly above 5V (maxed-out at 1023) about half the time and negative (reading zero) about half the time. And the little internal "protection diodes) in the chip will clamp the voltage to slightly above 5V and slightly negative, relative to the Arduino's ground.