Understanding infrared reflective colour sensors

Most teams participating in DIT’s annual RoboSumo tournament use reflective infrared (IR) sensors to detect the colour of the arena surface under their robot. Most of the ones I see are similar to the OPB704 sensor which is manufactured by OPTEK Technology Inc. The cost of this sensor varies widely depending on the supplier, but if you shop around you can usually get it (or one similar to it) for €2-€3 (for example, see here – as of 18-4-2013).

The OPB704 contains two semiconductor components, an IR LED and an IR phototransistor. The LED is used to illuminate the surface under the sensor with infrared light. The phototransistor is used to sense the intensity of the light reflected back from the surface (which depends on its colour).

Typical circuit

In order to use this sensor in a 5V circuit, two resistors are generally required:

  • The first is a current-limiting resistor in series with the LED which sets the current to an appropriate level. The current must be large enough to illuminate the surface adequately with IR light, but not so large that the LED burns out. The calculation of this resistance value is described below, but values of about 200-300Ω are typical.
  • The second resistor is used in conjunction with the phototransistor to form a light-to-voltage transducer – i.e. to output a voltage that rises and falls with changing light intensity.

The circuit I have seen used most frequently with the OPB704 (and similar sensors) is the following:

Typical OPB704 circuit

LED Circuit

The LED part of the circuit is quite straightforward. According to page 4 of the OPB704 datasheet, the maximum permitted current in the LED is 40mA, at which point the maximum expected voltage across the diode will be 1.7V. Although the current in the LED should be set to a value comfortably below the permitted maximum, let’s assume for the time being that the voltage across the diode will be close to 1.7V (a reasonable approximation). Since the supply voltage is 5V, the voltage across the current-limiting resistor will be 3.3V (because 5V – 1.7V = 3.3V).

Suppose we want the LED current to be 15mA (which would produce reasonably bright light from a typical LED). Voltage and current in a resistor are related by Ohm’s Law (V = IR ). Applying Ohm’s Law to the current-limiting resistor:

R = \frac{V}{I} = \frac{3.3}{15 \times 10^{-3}} = 220\Omega

Please note that the diode voltage of 1.7V is a rough approximation. According to the graph on the final page of the OPB704 datasheet, the expected diode voltage when the current is 15mA is about 1.2V (at room temperature). However, because this value is close enough to 1.7V, the 220 Ohm value should be acceptable.

Please note that there is no significant difference between the following two circuits:

Two equivalent circuit options for the IR LED in the OPB704

In each case, the LED and resistor are in series and the exact same current therefore flows through both components.

Phototransistor Circuit

The phototransistor part of the circuit is structurally simple, comprising the phototransistor “in series” with a large resistance. I put inverted commas around the words “in series” because the node where the resistor and phototransistor meet is also connected to the analog input of a microcontroller. Strictly speaking, two components are only in series if the current in both is identical – i.e. that they are the only two elements meeting at a particular circuit node. However, in this case, the third branch meeting at the node in question is connected to the high impedance analog input of a PIC microcontroller which can reasonably be assumed to load the circuit only very slightly. When analysing the voltage at the node, we will therefore make the reasonable assumption that the current flowing into the PIC is negligible and that the resistor and phototransistor are in series.

One way of thinking of the phototransistor is as a light-activated valve for electric current. The higher the intensity of infrared light that falls on it, the more electric current it allows to flow through it. By placing the phototransistor in series with a resistor, we are allowing the current in the resistor to be controlled by light intensity. Ohm’s Law tells us that resistor voltage and current are proportional. Therefore the voltage across the resistor is also controlled by the light intensity experienced by the phototransistor.

Predicting the phototransistor current precisely is difficult in the complete circuit. However, the datasheet provides some useful ballpark figures:

  • As stated on page 4 of the datasheet, the dark current is <= 250nA for a collector-emitter voltage of 10V (twice the maximum voltage that will ever occur in the colour sensor circuit). Let's assume therefore that the dark current (i.e. when no light is reflected from the surface) is below 250nA.
  • Assuming a resistance of 100kOhm, this current would generate a resistor voltage of 0.25V.
  • According to page 4 of the datasheet, the collector current in the on-state (i.e. when lots of infrared light is falling on the phototransistor) is somewhere between 0.2mA and 2.5mA. Admittedly, these values refer to a collector-emitter voltage of 5V (as well as an LED current of 40mA and a white reflective card 3.8mm from the sensor), which is higher than will occur in our circuit once the phototransistor turns on. Nevertheless, the low figure will serve as a useful guide to check our resistance value.
  • A current of 0.2mA through a 100kOhm resistance would generate a voltage of 20V. Clearly this cannot occur in our circuit, where the supply voltage is only 5V. However, it is clear that the magnitude of current of admitted by the phototransistor when activated are more than adequate to generate volatge swings across the 100kOhm resistance of anything up to 5V.

Consider the following two alternatives:

Two options for the phototransistor circuit

In the circuit on the left, Vout decreases as light intensity increases. A white surface, which reflects more light, will therefore drive Vout closer to 0V, whereas a black surface, which reflects less light, will drive Vout closer to 5V.

Conversely, in the circuit on the right, Vout increases as light intensity increases. A white surface drives Vout closer to 5V and a black surface drives Vout closer to 0V.

There is no particular objective reason that one of these two alternatives is better than the other. However, all other things being equal, I personally favour the second alternative. When we deal with greyscale pixels in digital images, the convention is that 0 denotes black and 255 denotes white. I therefore find it more intuitive that the microcontroller should read a higher number for white and a lower number for black.

The complete circuit revisited

I began by showing the circuit I have seen most people use with the OPB704. Here is a slightly modified version of the circuit that works in a very similar fashion, but produces an output voltage that is high for white and low for black.

Revised circuit for the OPB704 colour sensor


Download an editable SVG copy of all illustrations from this post (created using Inkscape).


  1. OPB704 datasheet
This entry was posted in Uncategorized and tagged , , , , , , , , . Bookmark the permalink.

4 Responses to Understanding infrared reflective colour sensors

  1. Derek says:

    Nice post I have found this site very handy thanks.

  2. Eric says:

    What would this circuit look like with two sensors? Would you just halve the resistor values to 220 and 50k?

    • batchloaf says:

      Hi Eric,

      Assuming you want the two sensors to work independently, you just reproduce the entire circuit twice without changing any resistor values. The output signals will be connected to two different input pins on your microcontroller.

      There are ways you can combine two sensors to feed into a single input on the microcontroller, but unless you really need to do that, I recommend just wiring up each sensor separately using the normal resistor values.

      If you’re using a different reflective IR sensor, you may want to change the resistor values. For example, the specific sensor I’m using these days is the TCRT5000 which works the same as the one described above, but I use a 220 ohm resistor for the IR LED and at 10 kOhm resistor for the phototransistor.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s