3

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:

enter image description here

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?

6
  • Would you consider using a comparator (op amp) too complicated?
    – Marla
    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.
    – Cerin
    Commented Dec 25, 2015 at 3:48
  • @Marla, Yes, that would be too complicated.
    – Cerin
    Commented Dec 25, 2015 at 4:29
  • 1
    @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

2 Answers 2

1

Near the bottom of:

https://learn.sparkfun.com/tutorials/qrd1114-optical-detector-hookup-guide

shows a graph of the voltage for a white surface and a black surface. If I understand your question correctly, I think you can get your desired results by controlling the distance between the sensor and the surface. For example, at 0.5mm white reads about 0.1V while black reads about 3.2V
A 330Ω current-limiting resistor and a 10kΩ pull-up resistor were used in their circuit.
Hope this helps.

0

First if you just want a faster analog read look at this article(http://www.microsmart.co.za/technical/2014/03/01/advanced-arduino-adc/). Second is that your approach to determining resistor values is incorrect. The sensor acts as a phototransistor so it passes different amount of current, upto 1 mA. so you only need a single resistor and the sensor to make an analog output. If you really want to digital read you can use an op amp as a voltage comparator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.