Sensing Color With a LED and Op Amp

Sensing Color With a LED and Op Amp

BreadboardRobot Room’s David Cook shows how an LED and op amp, along with a resistor and cap, can be built into an amplified color sensor.

Makezine_COTM_OpAmp-BadgeUnfortunately, even under the best conditions, photodiodes (and reversed LEDs) don’t provide a lot of current flow. The output of the photodiode needs to be amplified for the light-detection signal to be useful in most circuits. A photodiode amplified by a built-in transistor is called a phototransistor.

You can connect a standalone photodiode to the input of a standalone transistor. But, it isn’t easy to control the gain of a single-transistor amplifier, and there are issues with signal noise and the amount of input current required. Instead, a better method for amplifying low-power signals in a high-quality repeatable way is an op amp chip (operational amplifier).

4 thoughts on “Sensing Color With a LED and Op Amp

  1. Dax says:

    Common mistake: you can’t directly judge colors of real world objects with RGB leds because they are sensitive to light in a different way than your eyes are, and they are narrow band emitters.

    A LED is sensitive to light shorter than its wavelenght, whereas the eye is sensitive to specific bands of wavelenghts. A red LED for example is sensitive to all wavelenghts from red to ultraviolet, whereas the red cones in your eyes are mostly sensitive to just red hues and a bit of yellow. That’s why the output from RGB leds under natural light cannot be translated directly to RGB values.

    Now if you’re just interested in measuring some sort of difference to tell red balls from blue balls from green balls, you don’t have to care about that. It will work sufficiently to see that the blue LED isn’t returning much signal so the object isn’t blue; but if it’s pink/magenta then you are in trouble because those are a combination of red and blue. If you really want to measure the color of an object, you have to get a little more elaborate.

    You may think to bypass the problem by using a light source of specific wavelenght – another LED – but the problem here is that LEDs are very narrow band emitters while real objects have a full spectrum of color, so you are only probing the peaks and valleys of the object’s color spectrum at very specific spots, which doesn’t yield enough information to make a good judgement of how your eye would see it under natural light. The color sensitivity of your eye for red, green, and blue actually overlap whereas the spectra of the RGB leds largely don’t, so the result is different. It’s what you would see if you were to look at the object under very poor lighting conditions, in other words, if the only light around was that coming off of your device’s RGB lightsource, which has a color rendering index of maybe 50/100.

    A properly working color sensor would use a full spectrum lightsource, like a small halogen bulb with a known spectrum, break the light up with a prism and then sweep the target with the resulting rainbow of colors, measuring the response to dozens of different wavelenghts and normalizing that with the known spectrum of the bulb. Then you’d have a rough estimate of the continuous color spectrum of the object, which you would use to compute the RGB values by integrating the spectrum over the human response curves for the different color components. And then of course you’d have to correlate that to some known color space standard, like sRGB or AdobeRGB to actually make any use of it.

  2. Erik Kringen says:

    David Cook is an excellent read. I have his Intermediate Robot Building book and I refer to it all the time. His explanations are very easy for the beginner to understand yet he still goes into enough detail to explain the “how’s” and “why’s” of the circuit.

Comments are closed.

Discuss this article with the rest of the community on our Discord server!

My interests include writing, electronics, RPGs, scifi, hackers & hackerspaces, 3D printing, building sets & toys. @johnbaichtal

View more articles by John Baichtal


Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).