How analog input pin work

I have a potentiometer of 10k and I connected it this way:

5v -> potentiometer -> analogic input pin of arduino

When I turn the potentiometer I change the resistance of the circuit but in the arudino documentation they say that an analogic pin in INPUT mode will have 1 megahom resistance. So, for example, if I turn the potentiometer to the middle it will generate 5k of resistance + 1 megahom of the analog pin it will result in a tiny, very tiny current. If I use U = R x I across the potentiometer it will be:

U = 5000 x 0.0000001

U ~ 0 across the potentiometer. So U will be 5v at the analog input cause there was no drop of voltage in the circuit. If will turn the potentiomer all way up to 10k resistance the voltage in the analog input will also be 5v cause the voltage drop across the potentiometer is still really small.

I know that an analogic pin as INPUT mode will read 0v as 0 as 5v as 1023. But as I showed you it should always read 5v even when I turn the potentiometer all way up cause the voltage is not being changed. I know I am wrong cause when I log the input pin it shows differentes values as I turn the potentiometer. So how does this work?

Take a look at the [u]Analog Read Serial Example[/u]. With the pot in the center, it should read about 512. (Assuming its a linear pot, and not an audio pot.)

The input isn't 1M. It's not a "resistor", it's not a pull-up resistor connected to +5V or pulled-down to ground. I believe it's closer to 100M and in most cases it should just be treated as infinite.

If the analog input was a 1M resistor to ground, the pot would make very little difference. You'd have a [u]voltage divider[/u] where the voltage would be 5V with the pot at zero, and with the pot set to the maximum, you' have 5V x (1,000,000/1,010,000) which is still very-nearly 5V.

5v -> potentiometer -> analogic input pin of arduino

What voltage values do does the arduino display when the pot is at the end stops? Have you measured the wiper resistance with a multimeter to see what the actual resistance is across the pot and at the wiper when the pot is at the end stops?

Your Arduino cannot measure resistance.
It can sample a voltage.
So if you need to know the position of the potentiometer (still not the actual resistance), you'll need to use a well known property of it.
A potentiometer can also be seen as two resistors in series.
Two resistors in series are called a voltage divider.
Because the voltage of the joining point of these 2 resistors depends on their resistance ratio.

If your sampling device (the Arduino) has a too low resistance, it will be part of the divider, as a 3rd resistor and therefore mess up the measurement.

inside the analogic pin

Please stop calling it that. The correct term is an analog pin.

The voltage keeps the same, isnt?

No you have what is known as a potential divider
see:-

if the resistance inside the analog pin is 100M (or about infinite) it will always register 5v cause the other resistors in the circuit will be very small compared to the analog pin resistance. What am I missing?

You are missing how electricity works. The 100M has nothing to do with the voltage divider action. The two resistors in the formula are the top part and the bottom part of the pot's track.

But if the analog pin will measure the voltage and it has an internal really high resistance it should be accounted isnt?

No. Look at the attached diagram. The pot acts as a potential divider and in effect is R1 and R2.
The input impedance of the analogue pin is represented by R3. If we measure the voltage with an ideal voltmeter as shown the the value of R3 has absolutely no effect on the voltage you measure no matter what the value of R3 is. A series resistor in of itself does not change the voltage.

I just would like to know how does the analog pin knows the voltage, just that.

It uses a system known as successive approximation comparing the input voltage with a known voltage. It uses a comparator to see if the input is lower that known voltage. Then depending on the result it changes the known voltage to another one and looks at the comparator again. Each time the change in the unknown voltage gets smaller and smaller until it homes in on the closest voltage it can measure.

This is a link to the wiki page on the topic.

pot.png

gilperon:
But if the analog pin will measure the voltage and it has an internal really high resistance it should be accounted isnt? I just would like to know how does the analog pin knows the voltage, just that.

If a tree falls in the woods but there's nobody there, does it still make a noise?

If your circuit were not even connected to the input pin, would there still be a voltage present?

Do you have the pot connected correctly? It sounds like you're missing something on the wiring

Pots have 3 pins in a line. If you want a pot to connect to an Analog pin, so you can read the position of the pot, the middle pin goes to the Analog pin. Then, one of the pins on the end goes to +5v, and the other end goes to ground.

Thus, the voltage on the middle pin will be determined by the position of the pot.

In this case, the "resistance" of the analog pin you speak of is not relevant, because that's not where the current is flowing. The input resistance, or input impedance, is only relevant if the resistance of the source of the input (in this case, the potentiometer), was of similar or higher resistance, which would result in inaccurate measurements.