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?