# Qtr-rc

Hi,
I’m using the qtr-rc sensor with a pic micro so I have to write my own code. I just need some clarification from the application note.
the procedure is listed as

1. Set the I/O line to an output and drive it high
2. Allow at least 10 us for the 10 nF capacitor to charge
3. Make the I/O line an input (high impedance)
4. Measure the time for the capacitor to discharge by waiting for the
I/O line to go low

In 1. is this referring to the vin on the sensor from a pin on the micro? I have seen in another post that this can be tied to the 5v. Which is how I wish to connect it. So step 1 becomes redundant does it?
And could you explain how the capacitor discharges in the circuit. Is it triggered by setting the io pin connected to out on the sensor to high Z input?

The QTR-RC sensors use a single I/O line connected to out to charge the capacitor then monitor it as it discharges. Vin can be at 5V. Step 1 is about setting that I/O line to an output and driving it high, so it is not redundant, and step 3 is about setting to an input, so the answer to your second question is yes.
-Paul

That is easy enough to implement but I was a little puzzled at how this would work by the circuit.
I wouldn’t mind understanding how the circuit works as I’m sure it would help at some later point.

Okay, did you look over circuit for the sensor? I do not really know what more to say than this: you charge up the capacitor with current from your I/O line, then (with the I/O line acting as an high-Z input) the charge flows through the phototransistor to ground. The more light there is, the faster the capacitor can discharge.

-Paul

Does the cap charge in 2 directions?
I thought it would charge through vin to ground. And then I guess that allows a high on io to charge it the other way and then discharge finally when the io is taken to high z input. Sorry for my ignorance. Is this the way it works?

I guess I should say that technically you are discharging the capacitor by presenting the high output, than letting it charge up across the potentiometer. But that really does not matter - a capacitor to ground acts almost exactly the same as a capacitor to Vin from the point of view of your microcontroller, since all it knows is the voltage on the out pin. (The only differences are the voltage you will get when initially powering up and potential for breaking if too much voltage is applied.) Sorry if that confused you! Does it make more sense now?

-Paul

I’m still lost with the circuit workings but at least I can get it working now I confirmed the 4 steps are the same whether you supply constant 5v to vin or it is supplied on demand from a second io pin.
That is all that is important for now. Maybe as I play with the electronics a bit more it will come to me.