David Cook
Robot Room
a robot

2. Schematic and Breadboard for Reversed LED Color Sensor Using an Op Amp

(article continued from previous page)

The prior page introduced the photovoltaic effect of a reversed LED and the theoretical method for turning it into a useful color sensor. Now, let's move on to a practical implementation.

Rather than starting with a partial circuit and building up, I'm going to cheat a bit and show a complete working implementation. Although this circuit is still based on the photodiode op amp core, the complete circuit also includes:

  1. An LED emitter to act as a matching wavelength light source. With this LED, you can reflect the correct color off your hand into the reversed LEDs.
  2. More than one reversed LED to increase the input signal strength.
  3. An ultra-bright red LED, as red requires less energy than other visible colors to provide a decent current flow. (Ask a physics teacher.)
  4. The other half of the op amp has been configured like a comparator to turn on/off an LED to indicate when it sees colored light.

Officially, the circuit can work with a single reversed LED of any color without requiring a matching LED light source. But, by starting out with this best-case configuration, it is more likely that you'll have successful results on your first try. Later on, if you choose a different color (like green or blue) you'll need to use higher resistor values and a lot more LEDs to get this to work on a leaky solderless breadboard.

Complete Schematic

If it seems complex at first, don't panic. Note that there are a lot of extra parts to provide an interactive experiment.

Complete schematic for detecting color with a reversed LED and a high-gain op amp.

Complete schematic for detecting color with a reversed LED and a high-gain op amp.

  • C1 and C2: Standard 0.1 µF ceramic and 10 µF tantalum power-supply capacitors to reduce electrical noise. Readers of Intermediate Robot Building will recognize that using capacitors near integrated circuits (chips) provides a clean local power supply. Although the circuit may work without these capacitors, the device deals with such small amounts of signal power that every bit of reduction in electrical noise helps.
  • LED5 and R5: An LED and current-limiting resistor in the usual configuration to provide a light source. Make sure that LED5 is the same color as LED1. R5 can be reduced to 220 ohms to provide more light. These two parts are not required for the color sensor, but they make experimentation more convenient by allowing you to reflect the matching wavelength of light of LED5 into LED1.
  • LED1 x 2 Two parallel ultrabright red LEDs in reverse orientation to act as photosensors. Additional LEDs could be added to further increase detection current flow. Even though they won't light up in this orientation, use the brightest LEDs you can find with clear lenses for the strongest results. Old technology LEDs with tinted lenses won't provide enough current to work at all.
  • IC1: The current flow from LED1 is connected to this op amp which amplifies the signal. The National Semiconductor LMC6482 op amp requires less input current than previous generations of op amps.
  • R1 x 3: Three 10 megohm resistors in series create a 30 megohm resistance. This resistance allows a small amount of current to flow from the op amp and into the reversed LEDs (LED1 x 2) such that the op amp output falls into a usable range between 0V and 5V. If the output voltage is too low on your board, use additional resistors. If the output voltage is too high on your board, use fewer resistors.

    If you happen to find a single 30 megohm resistor (instead of three 10 megohm resistors) that's even better. But, the largest resistor value I could find at Mouser Electronics and Digi-Key was 20 megohms. Instead, I just used several 10 megohm resistors that I had on hand.
  • R8: A 10 kilohm variable resistor trimpot. This has 0V (GND) connected to one pin, 5V connected to the other, and an adjustable voltage (0V-5V) output from the middle pin. Whatever voltage you dial on this potentiometer will be compared to the amplified output of the reversed LED (IC1 pin 6). LED9 will turn on or off to indicate which voltage is higher. This portion of the circuit is not necessary for the color sensor, but it makes experimentation easier because you can see the detection results without an oscilloscope or volt meter.
  • R6: A 1 megohm resistor feeds back a tiny amount of the output from the op amp to provide comparison hysteresis. See page 4 for details. Basically, it encourages the op amp to stay in a stable state.

    Without this resistor, LED9 would blink on and off rapidly when the R8 trimpot voltage and the LED1 color sensor voltage were approximately equal. That's not a big deal for an LED, but it is preferable to have a steady digital output if a microcontroller or other chip uses the digital signal from pin 7 for detection purposes.
  • R7: This 100 kilohm resistor balances the trip level signal from trimpot R8 with the feedback from R6. If this resistor didn't exist, and R8 were turned down to 1 ohm (for example), then R6 would have almost no impact on the voltage at pin 5. So, hysteresis would only work for values toward the middle of R8's resistance. But, by adding R7 (100 kilohm) the effect of R6 (1000 kilohm) is fairly consistently about 10% of the voltage regardless of the resistance of trimpot R8.
  • LED9 and R9: An LED and current-limiting resistor in the usual configuration to provide a light source. LED9 can be any color you want, but I'd choose a different color than LED5 and LED1 so that the light from LED9 doesn't affect the color sensor. R5 can be reduced to 220 ohms to provide a brighter indicator. These two parts are not required for the color sensor, but they make experimentation more convenient by turning on to indicate when LED1 senses light.

LED Color Sensor Implemented on a Solderless Breadboard

I always like to include a photograph of a circuit on a solderless breadboard to help people lay it out.

Solderless breadboard with a pair of reversed LEDs and a low-input current op amp to act as a color sensor.

Solderless breadboard with a pair of reversed LEDs and a low-input current op amp to act as a color sensor.

When the circuit receives 5V from a power supply not pictured, indicator LED9 will turn on when light reflects from LED5 into either or both reversed LEDs that are labeled LED1. This is usually accomplished by placing a hand or a piece of paper an inch or so over LED5 and angling the light into LED1.

If you have an overhead lamp or sun shining onto the board, the reversed LEDs may always be detecting light and LED9 may always be turned on. Remember, white light is a combination of multiple colors and wavelengths. Cover the board with a cloth or cardboard box and then move your hand up and down above the reversed LEDs to vary the amount of reflected light.

Trimmer R8 determines the detection voltage needed to turn on indicator LED9. If LED9 turns on with too little light or turns off with too much light, adjust R8.

Connect a multimeter in voltage mode to the start or the end of the green wire (IC1 pin 1 or pin 6) to measure the amplified voltage level of the reversed LEDs. If the voltage is too high and doesn't seem to decrease when LED1 is shadowed, remove some resistance from R1 or pull out one of the reversed LEDs. If the voltage is too low and doesn't seem to increase when LED1 is placed under a bright light, add some resistance to R1.

Don't attempt to measure the voltage directly from LED1 or IC1 pin 2. Most multimeters require too much current at their inputs and will simply drive down the already faint voltage on the reversed LEDs. Instead, measure the amplified voltage at IC1 pin 1 or pin 6.

A better way to measure the voltage of a low-power analog signal is to use an oscilloscope. Because many readers don't own oscilloscopes, the remainder of this article consists of a group of oscilloscope traces I took along the way of developing this circuit.