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.


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.

  • \$\begingroup\$ I didn't misread the datasheet, I just didn't say what I meant to say haha. You are totally right, you don't set it to low afterwards because you need to measure how long it takes it to go from high to low. Thanks for the correction, I'll make the edit. When I said that it discharges the capacitor, I mean when you set it to HIGH, I understand that it is actually charging the capacitor when you set the OUT pin to input and read from it. I'm not sure why I need to dedicate 8 digital pins to the job since it should only use one? ADC is not needed to use this sensor by the way. \$\endgroup\$ – Addison Jan 8 '15 at 16:47
  • \$\begingroup\$ Uh-oh. First, you need to check the data sheet for the Teensy. Digital I/O is done in 8-bit registers, and you set the pin configurations for an entire register at once. So you configure I/O in blocks of 8 pins. Second, yes you do need the ADC. How else are you going to determine how fast the internal capacitor discharges? You can try just looking at the state of the input pin, but the threshold level is not necessarily constant, and I doubt it's a Schmitt trigger input, so you may get a lot of noise. \$\endgroup\$ – WhatRoughBeast Jan 8 '15 at 17:20
  • \$\begingroup\$ Oh, the teensy 3.1 has a arduino addon, so I just simply specify the pin number and it will set that to 1. You're thinking of many atmel controllers that use registers; Arduino just simplifies it for you. If you look at pololu, the purpose of this sensor is that it uses digital. It just waits until the output goes low, which assumes the threshold level is constant I guess. The number that it outputs doesn't have any units, so it just gives you a range of how far away it is. \$\endgroup\$ – Addison Jan 8 '15 at 20:34
  • \$\begingroup\$ No. I'm referring to the Teensy data sheet pjrc.com/teensy/pins.html, specifically I/O Registers. Agreed, you can set an individual pin high or low, but you cannot change an individual pin from input to output, or vice-versa. That can only be done in blocks of 8. Furthermore, pjrc.com/teensy/adc.html "Configuring the Pins" suggests that when using the ADC, the corresponding pin must be set as an input with no pullup resistor. So you need to set the block of 8 as output, charge the cap, set the block to input, then use the ADC. \$\endgroup\$ – WhatRoughBeast Jan 8 '15 at 21:09

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.