Reflectance Sensor Input Issue

microcontrollersensorteensy

I have a Teensy 3.1 and I am wanting to receive data from a reflectance sensor, specifically this one from pololu: https://www.pololu.com/product/2459

!Pololu Schematic for Reflectance Sensor QTR-1RC

This is the circuit of the reflectance sensor from pololu's website. The Vin is meant to be 5V according to the datasheet.

To operate it, you set the OUT pin to high, and then set it to low and see how long it takes for it to discharge.

I have a 5V input, but my Teensy 3.1 will only output 3.3V. So, this means when I set the OUT pin to high, there will actually be a 1.7V difference between VIN and OUT. Will this cause current to flow into the OUT pin? (1.7V / 220ohms = ~7mA) Will that cause any issues?

I understand the purpose of setting OUT to high is to discharge the capacitor and that will still happen even with 3.3V applied to OUT.

Best Answer

Sorry, but you've misread the data sheet. You use this by first applying a "high" voltage to the output. Then you remove (as in disconnect) the voltage, not set it low. Then you can measure the decay rate of the output voltage as it goes to zero, which is techinically charging the capacitor to 5 volts, not discharging it. I've never used a Teensy, so I cannot speak from experience, but a quick look at the data sheet suggests that you can set a digital pin to either input or output. You may be able use a Teensy, although there are no guarantees. You will have to dedicate 8 digital pins to the job, even though you only use 1. You'll need to configure a port as output, set the sensor pin as high, wait for charging to be complete, then reconfigure the port as input without pulldown resistors, and monitor the pin with the ADC. This will affect all 8 pins on the port, so it seems unlikely you'll be able to use then for anything else. Since the Teensy data sheet does not specify the input characteristics either of a digital pin in input mode or the ADC, there is no way to tell how well this will work for this sensor. I'd assume both are fairly high, but you know what they say about when you assume. ("When you assume, you make an ass out of u and me.")

It really doesn't matter what voltage you use to discharge the capacitor as long as it's below the point at which you damage the phototransistor. 3.3 should work about as well as the intended 5 volts. You will get 7 mA, but only very briefly, like a few microseconds, and this current is less than you would get if you used 5 volts, so no worries there.