How to wire an analog IR sensor for digital input?

How do you wire a phototransistor so that it outputs a clean digital signal in response to certain light levels?

I've wired a QRD1114 to an Arduino analog pin to detect a white or black surface. However, I want to use this sensor to detect fast movement of a black/white color strip, and since `analogRead()` can take up to 100µs and I'd rather use the ADC pin for other sensors, I want to rewire this so I can read the same signal with `digitalRead()`.

In order to do this, the sensor needs to output less than 2.3V for white and more than 2.5V for black. I'm pretty close, but I'm having trouble with black. For white, the voltage drops to 0.7V, so that reads perfectly, but black still reflects a lot of IR, so it typically reads 2.3V, which still translates as a LOW value.

My sensor's circuit is a pretty basic voltage divider:

R1 is the Arduino's built-in 20k pullup. R2 is a variable resistor I've tried using to "shift" the voltage level up for the black case. Unfortunately, I've found this very difficult to calibrate. The larger I make R2, the higher the black-case voltage gets...but so does the white-case voltage. By the time I make R2 large enough so that black registers as HIGH, white also registers as high. Through trial and error, I found 25.7k ohms is the sweet spot, but the difference in voltage between the two is about 0.5V, which makes me nervous about getting false readings.

I've measured the phototransistor's resistance in each case, and for black it reads as 12.5k ohms while for white it reads as 9.7k ohms.

Given my 25.7k calibration resistance, the voltage divider should output for black:

``````Vout = Vin * R2/(R1 + R2)

5 * (12500+25700)/(20000 + 12500+25700) = 3.2V
``````

and for white:

``````5 * (9700+25700)/(20000 + 9700+25700) = 3.1V
``````

However, for black, my meter reads 2.3V for black and 2.0V for white.

Why do my meter measurements not match the voltage divider formula? Am I wiring this voltage divider correctly?

What can I do to get a cleaner digital output without complicating the circuit too much?

• Would you consider using a comparator (op amp) too complicated? Commented Dec 25, 2015 at 3:04
• Per datasheet, the QRD1113 / QRD1114 is a "Reflective Object Sensor", not a color sensor. If the sensor does its job properly, you will get about the same signal for a black object as for a white object. That said, what happens if you add an external 5KΩ – 15KΩ pullup in place of the internal pulllup? You might also try a bridge arrangement Commented Dec 25, 2015 at 3:11
• @jwpat7, When you're only talking about two colors, as in my case, then yes, it's very much a color sensor, and many people successfully use it for this purpose. You see the color black because a black material doesn't reflect most wavelengths... And no, a different pullup does nothing. Commented Dec 25, 2015 at 3:48
• @Marla, Yes, that would be too complicated. Commented Dec 25, 2015 at 4:29
• @Gerben, I'm puzzled by this. The input impedance of most modern meters is quite high, mine is rated at '> 10 MΩ' I would think that that should make little or no difference to the voltages in this circuit. Or am I missing something?
– dlu
Commented Dec 28, 2015 at 8:04