0
\$\begingroup\$

Three test cases

These 3 diagrams represent 3 test cases.

Dia 1:

When I perform an analogRead of analog port 0, then I get a high value obviously. According to the manual, the analogRead method obtains the resistance. I expected it would say that it returns the voltage. Anyway, in this case both are directly proportional.

Dia 2:

With a resistor + pull-down resistor, the reading of the analog port 0 decreased.

Dia 3:

However, I would have expected that dia3 would also result in a decreased value.

My reasoning was: The supplied voltage of 5V is constant. So, it must be divided between the resistor and analog port 0. A bigger resistor should result in a higher voltage for the resistor, and a lower one for the analog input. --> But that seems to be incorrect.

Second attempt: The analog port reads resistance and not voltage. Maybe that's important. R = V / I. Apparently the resistance remains the same. So, applying this formula: if resistance remains constant and voltage decreases, then it could be caused by an increasing current. But it doesn't make sense that the current would increase by adding a resistor.

PS: if I add the analog pin to ground, then I get a low reading.

Where exactly is my reasoning flawed ?

EDIT:

As many people have pointed out. I have indeed wrongfully interpreted the following phrase in this tutorial. Thank you for pointing that out to me.

in the main loop of your code, you need to establish a variable to store the resistance value.

\$\endgroup\$
  • 1
    \$\begingroup\$ Dia 3. The current into the analog input is negligible. That's the same current that flows through the resistor. Since the current is negligible, the voltage drop across the resistor is zero. So, the analog input "sees" the supply voltage like in Dia 1. \$\endgroup\$ – Nick Alexeev May 30 '15 at 9:31
6
\$\begingroup\$

Analog inputs measure voltages, not resistance. It is possible to infer the value of a resistor by setting up a circuit in a certain way and measuring voltage on an analog input. But analog inputs on their own only measure voltage. Can you show the context from the manual you're referring to that claims an analog input obtains resistance?

The results you're getting for your three experiments sound perfectly correct. In Dia 1, as you seem to understand, the analog pin sees 5V and reports it. Analog inputs draw extremely little current. So little, in fact, that the current can be ignored in most cases*.

In Dia 2, you've created a resistor divider between 5V and GND. It's not really appropriate to call the 2nd resistor a "pull-down" resistor in this context. Redrawn, Dia 2 looks like:

schematic

simulate this circuit – Schematic created using CircuitLab

The analog input pin draws no current, but there is a current path from 5V to GND. This causes a voltage drop across both resistors. The voltage at the middle is easily solved using Ohm's Law. The equation for the divided voltage looks like: $$V_{divide}=5V\frac{R2}{R1+R2}$$ The "decreased value" you observed was in fact the divided voltage value. Choosing different values for R1 and R2 will give you a different analog voltage readings.

For Dia 3, consider the effect of Ohm's Law on that resistor. Remember, virtually no current is consumed by the analog input pin. If there's no current, then the I in \$V=IR\$ is zero. If the I is zero, then the voltage drop V is zero. If the voltage drop is zero, then there's no change in voltage on either side of the resistor. Therefore, both sides of the resistor read 5V and the analog pin will read a high value, exactly as you observed.

*There are times when this assumption is not correct and will result in measurement errors. But those cases can be safely ignored for introductory purposes.

\$\endgroup\$
3
\$\begingroup\$

According to the manual, the analogRead method obtains the resistance.

Either the manual is incorrect or you have misinterpreted this statement. Any analog read will return a digital number that represent the voltage at that input. It does not convey any value of resistance that might be fitted at that input.

I expected it would say that it returns the voltage.

So would I.

I would have expected that dia3 would also result in a decreased value.

It all depends on the value of the resistor and "other things". For values below 10kohm (generalism alert) I would expect it to be 1024 (10 bit ADC resolution) because the input impedance of the ADC is so much higher than the 10kohm and therefore does not form a significant potential divider.

Note than an input impedance of (say) 10 Mohms would result in the 5V source being lowered (due to the 10k and 10M) by about 0.1% - maybe you would read 1023 instead of 1024: -

enter image description here

Rtop would be 10k and Rbottom would be 10M in this example.

On the other hand if you were scanning around those inputs in software and the ADC inputs were fed (internally) to a ccommon ADC via a multiplexer you might see variations in the read value. This is due to the finite time it takes to charge internal capacitors at the ADC input (after the multiplexer): -

enter image description here

The sample and hold capacitors need to charge up to within 0.1% of the output of the multiplexer and, if the multiplexer is scanning around very quickly, an error can result on some inputs because there might not be enough time to charge the capacitors.

\$\endgroup\$
2
\$\begingroup\$

As far as I know analogRead return a value (10bit wide by default) which represents the fraction of the ref. voltage being read. For example if you have 5V hooked up to the ADC and your ref. voltage is 5V you will get a value of 1023 (or something just below it). Your resolution is 5V / 2^10 = about 4.9mV per ADC code. so 1023 * 4.9mV is about 5V.

When you are shorting 5v to the ADC you are causing 5V to drop over the ADC so you get max. code for 10bit ADC = 1023. When you hook up 5v through a resistor you will still get about 5V on the ADC input because the input impedance of the ADC is very large so almost all the voltage drops on the ADC and almost none on the resistor. Your ADC resolution is not fine enough to show these differences. When you hook up two resistors with ends going to 5V and GND you have created a voltage divider which according to the resistors value relation will be some fraction of the 5V voltage. For example if you have 2 10K resistors you will get 2.5V at their junction. This voltage is sampled by the ADC so you will get a code about 512 (512 * 4.9mV = about 2.5V right?).

It would not be correct to call the resistors pull up or pull down as that term is usually used for resistors that introduce a certain voltage level to a digital pin which is floating.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.