Get Resistance from Analog In?

Hi! I am new to the competition, but I am fairly competent in C. I need to read a resistance value using the analog input. I know ohm’s law, etc. but I am uncertain of how to apply it, or even how to read rc_ana_in01 correctly.

Help greatly appreciated.

The analog input measures voltage; your task is to create a voltage proportional to the unknown resistance.

This assumes you really want to measure resistance, as opposed to some physical phenomenon that the resistance represents (such as the position of something). If the latter, calibrate manually (One end reads “47” on the analog input, the other end reads “984”, so midpoint would be around 468 or so).

One way is to create a voltage divider and feed it with a known fixed voltage. If your unknown resistance can be narrowed down to a range, the reference resistance can be about equal to half the maximum value. So, from the +5v source, you go through the unknown resistance, then the known (reference) resistance, and end at Ground. Sense the analog voltage between the two resistances…5 volts (1023 counts) means zero resistance, and 2.5 volts (511 counts) means equal to reference, and 5/3 volts (about 341 counts) means twice the reference.

Another way (if the range of unknown resistance is very high, or completely unknown) is to create a constant current source and measure the voltage across the resistor - R=V/I, and if I is known and V is measured (make sure it doesn’t exceed the analog input range, 5 volts on a 2008 RC) you can calculate R.

Hope that gets you started…

Don

Ah, basics: I can’t say exactly how to read in the value, but it is a simple command like “Get Analog Input 1”, returning a value from 0 to 1023 which corresponds to 0 volts and 5 volts respectively. Search “Potentiometer” on this forum for code examples.

V = IR

Doesn’t work the other way around, unfortunately.

With my limited knowledge of physics, I can say that one way to do this might be to connect the two outer terminals of a potentiometer to +5v and G, then connect the wiper to the sense pin of the RC. At one end of the pot, the sense pin would be at a 5v potential difference from ground, and at the other, a 0v potential difference. Definitely use a pot of significant resistance, though, or you’ll draw too much current and break something. Find the max current draw from the RC, take a small fraction of that, plug it and 5v into Ohm’s law and solve for R.

That is exactly how you wire it. If you are using Kevin’s code you type in Get_ADC_Result(CHANNEL) =. Channel must be from 1-16 depending on which port you plug it into. It returns in 10 bit resolution so if you are saving it to a byte, do Get_ADC_Result(CHANNEL)/4. If you want to make it slightly faster you can use >>2 instead of /4.

D’oh - no, of course it doesn’t. Thanks, my brain was asleep but my fingers were still typing.

He never mentioned a potentiometer…