Short version: How do I measure the value of a variable resistor (i.e. a resistor which changes values, not a potentiometer which acts as a voltage divider) via the analog input of a VEX controller?
Long version: This is not for a FIRST project, but I will be using a VEX controller. I am trying to find the color of several different objects, or rather to group the objects of the same color together (I don’t actually care what the absolute colors are). I plan to do this by shining an RGB LED (http://www.sparkfun.com/commerce/product_info.php?products_id=105) at each object and measuring the reflected light of each color using a photoresistor (http://www.radioshack.com/product/index.jsp?productId=2062590). The question is: what’s the best way to make this measurement?
I have experimentally determined that the photoresistor has a range from about 50 ohms (when illuminated by a white LED flashlight held very closely) to about 1.8 megaohms (when covered by my hand).
I have several possible solutions and would like opinions on which might be best, and ideas for any other possible solutions.
Option (1) is probably the easiest. I take a fixed value resistor, and connect it to the photoresistor to make a voltage divider, and measure that value with the VEX’s ADC on the analog input, something like this:
+5 ---<photo>---<analog in>---<resistor>--- GND
The big question with this is what value to use for the fixed resistor? The larger the resistor, the less of the full range of the ADC is used. If the resistor is too low, however, then when the photocell is low, you’ve got a very low resistance connection directly from power to ground. On the FRC controller, this causes a problem with the symptom of the “code error” light, and the code not running; I assume the VEX controller is similar.
Option (2) is to build an RC circuit as follows:
GND ---<capacitor>---<photo>--- I/O Pin
This takes advantage of the fact that the I/O pins on the VEX controller can do digital output as well as both analog and digital input. The idea is to set the pin “low” for a “long” time, to fully discharge the capacitor. Then set the pin “high” for a “short” time. This will partially charge the capacitor. Finally set the pin to “analog in”, and read the value. A lower resistance on the photoresistor will have allowed the capacitor to charge more. (2b) Would be to first fully charge the capacitor, and then discharge it for a short time and then measure the value.
I have not yet calculated values for the capacitor or for a “long time” or a “short time”.
The advantage to option (2) over option (1) is that it allows you to have the full range of your ADC values. The disadvantage is that it requires more complex programming, which means the potential for more errors in the system. Additionally, I think that the ADC on the processor uses the charging of an internal RC circuit to do its ADC conversion. This might potentially be a problem when trying to use that to measure an external RC circuit.
Option (3) is like option (2), but move the I/O pin to the middle:
GND ---<capacitor>---<I/O Pin>---<photo>--- X
X could be either +5 or ground, possibly through an additional fixed resister, to ensure that you always have a minimum resistance between +5 and ground.
I’m not sure that (3) has any real advantages or disadvantages over (2).
Like so many things in engineering (and in life), there is more than one way to do it. I believe all of these methods would work. (If you think any wouldn’t work, why wouldn’t it work?) What other methods can you think of that would work? Which of all the methods discussed (here and as hopefully suggested by others below) do you think is best, and why?
–AJY