Get Adobe Flash player
English Arabic French German Italian Portuguese Russian Spanish

Did you know?

Replacing old model air conditioners with Energy Star units can cut cooling bills by 20 percent or more

Help us stay online:

small donate


color-sensor-devicesLight .Visible light is an electromagnetic wave in range of 400 to 700nm. This is just a small part of all existing wavelengths. The light that we see is not one wavelength but a combination of many wavelengths.
The spectral power distribution - SPD shows the precise dependence of the color in function of light source in the form of diagram that represents energy at each wavelength in the visible spectrum.





 SPD diagram of sunlight at noon, for example, clearly shows a very balanced light source. All wavelengths of visible light are present and approximately equal. Compared to artificial light source, sunlight is a large amount of energy in the blue and red part of the spectrum. SPD diagrams can be very useful for understanding the different sources of light. The following figure shows a spectral power distribution of a few typical light sources.



The Eye and Color Perception . he human eye works basically like a camera. Each neuron is a stick (rod) or conical (cone). Just conical neurons are sensitive to color. The man has a special cell in the eye for color detection. These cells are also known as cones because of their similarity with the aforementioned geometrical object. There are three types of cones for every of the three primary colors: red, green and blue. Each of these cells responds different to frequencies of light. Next figures show the spectral sensitivity of the cone cells and the light efficiency of the human eye.

human eye response

Color signal goes to the brain as a result of the cone cells of the three primary colors of the observed spectrum. This signal can be represented by three values:

color signal formula                                                                                                

where E is the spectral power distribution and S the spectral sensitivity function.

Color can be represented as the sum of three colors. This means that the colors form a three-dimensional vector space. The following charts show the appearance of the three primary colors needed to represent all wavelengths of the visible spectrum.

color sensitivity for color representation

Negative values indicate that some colors may not exactly produce by simply adding the primary colors. For easy color synthesis is necessary that all the values are positive. That is why the International Commission on Illumination (CIE - Commission Internationale de L'Eclairage) has defined standards for three primary colors (X, Y, Z). The basic color of Y is deliberately chosen to be identical to the efficiency as a function of light the human eye. The following charts show the values of X, Y, and Z that are required to accurately reproduce any color from the visible spectrum.

CIE spectral sensitivity

Basic colors can now be presented with the following formula:

CIE spectral sensitivity folmula                                                                                                             

All colors are visible in the "horseshoe" shaped cone in XYZ space. If you look at the plane X + Y + Z = 1 and its projection on the XY plane, we get the CIE chromaticity diagram which is given in the figure.

CIE chromaticity diagram 


Edges represent pure color i.e. sinusoidal waves at the appropriate frequency. White color is the black point on picture, and white light is same as light emitted from black body at a temperature of 6447 K. When you add, any two colors (i.e. the point at CIE color diagram) the resulting color is point located on the line between these points.

For finding and presenting complementary colors Lab (L * a * b) model is used, where L is the brightness (luminance), "a" the distance between the green and red "b" the distance between the blue and yellow color.

Lab color model 

Color sensors . Color sensors can be made from discrete components (such as photo resistors, photo transistors), or they are build in integrated techniques. In this way, the color sensors are becoming smaller, more accurate, reliable and affordable. Robotics and various industrial manufacturing processes have greatly contributed and continue to contribute to the development of integrated sensors color.

Many of the color sensors are based on the same principles, i.e. on measuring the intensity of light reflected from a particular surface. Reflected light is detected by photo detectors mostly made in semiconductor technology. Most of the colors that have been detected belong to a group consisting of green, blue and red color. Combined usage of these sensors it is possible to detect and different color.

The simplest color sensor can be made using photo resistor known as LDR. In same condition (ambient light, temperature) objects with different color makes different terminal resistance. Using comparators it is possible to detect color, but when you use sensor in different condition resetting must be made again.

The most popular color sensors are integrated semiconductor sensors and generally represent LED that generates current according to detected light. With embedded wavelength filter it is possible to make sensor for every color. Generally, block diagram of color sensor is next circuit.


Since output of LED detector is very small current it is necessary to convert current in voltage and amplify signal. Common circuit known as transimpedance  amplifier is used. Resistor is about few hundred MOhms.

Not all color sensor has transimpedance amplifier an in that case user have to make processing. Color sensor can have different type of outputs, but most popular are frequency and voltage outputs. There are 3 lines for every basic color, red, green or blue. Very simple usage is to make comparator circuit for every channel and generate digital output. Advanced usage of sensor use ADC and digital processing that is presented on next picture.

ADC uC color sensor 

On this way it is possible to detect other colors than red, green and blue. Detection process is much better if there is a source of light that emit lights close to day light (white light). White LEDs are commonly used. In this case it should be known that white LED specter is not ideal to white lights as it shown on picture.

 White LED specter

Color models . The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The main purpose of the RGB color model is for the sensing, representation, and display of images in electronic systems, such as televisions and computers, though it has also been used in conventional photography. Before the electronic age, the RGB color model already had a solid theory behind it, based in human perception of colors.

RGB is a device-dependent color model: different devices detect or reproduce a given RGB value differently, since the color elements (such as phosphors or dyes) and their response to the individual R, G, and B levels vary from manufacturer to manufacturer, or even in the same device over time. Thus an RGB value does not define the same color across devices without some kind of color management.

Typical RGB input devices are color TV and video cameras, image scanners, and digital cameras. Typical RGB output devices are TV sets of various technologies (CRT, LCD, plasma, etc.), computer and mobile phone displays, video projectors, multicolor LED displays, and large screens such as JumboTron, etc. Color printers, on the other hand, are not RGB devices, but subtractive color devices (typically CMYK color model).

The CMYK color model (process color, four color) is a subtractive color model, used in color printing, and is also used to describe the printing process itself. CMYK refers to the four inks used in some color printing: cyan, magenta, yellow, and key (black).

color models 

The RGB color model isn't very intuitive, so here's a table containing some common RGB values:

RGB model 

When you use ADC just scale this values for proper color representation.

By doing calculations on the RGB values of the pixels of an image you can perform various color effects. Here's a table of the operations you can do with RGB color. These operations are given for the 24-bit color model with 8 bit per channel, so 255 is the maximum value of a color. Colors channels can also be represented as floating point numbers between 0.0 and 1.0, and then you have to replace the value "255" by "1.0". C represents the channel together or the total color, while R, G and B represent the Red, Green and Blue channel separately.


The HSL Color Model . HSL is another way to describe color with 3 parameters. RGB is the way computer screens work, but not very intuitive. HSL is more intuitive, but you need to convert it to RGB before you can draw a pixel with it. The nicest application of this color model is that you can easily create rainbow gradients or change the color, lightness or saturation of an image with this color model.

HSL color obviously has the parameters H, S and L, or Hue, Saturation and Lightness. Hue indicates the color sensation of the light, in other words if the color is red, yellow, green, cyan, blue, magenta, ... This representation looks almost the same as the visible spectrum of light, except on the right is now the color magenta (the combination of red and blue), instead of violet (light with a frequency higher than blue).

HSL model 

Hue works circular, so it can be represented on a circle instead. A hue of 360° looks the same again as a hue of 0°.

HSL circle 

Saturation indicates the degree to which the hue differs from a neutral gray. The values run from 0%, which is no color, to 100%, which is the fullest saturation of a given hue at a given percentage of illumination. The more the spectrum of the light is concentrated around one wavelength, the more saturated the color will be.

HSL saturation2 

Lightness indicates the illumination of the color, at 0% the color is completely black, at 50% the color is pure, and at 100% it becomes white. In HSL color, a color with maximum lightness (L=255) is always white, no matter what the hue or saturation components are. Lightness is defined as (maxColor+minColor)/2 where maxColoris the R, G or B component with the maximum value, and minColor the one with the minimum value.

HSL lightness 

The HSV Color Model . The HSV color model (sometimes also called HSB), uses the parameter Value instead of Lightness. Value works different than Lightness, in that the color with maximum value (V=255) can be any color like red, green, yellow, white, etc..., at it'smaximum brightness. Value is defined as maxColor, where maxColor is the R, G or B component with the maximum value. So the colors red (255,0,0) and white (255,255,255) both have a Value of 255 indeed.

In HSL, the Lightness showed the following behavior when increased:

HSL lightness 

In HSV, Value does the following:

HSV Value 

The Hue and Saturation parameters work very similar to the ones in HSL. HSV is generally better at representing the saturation, while HSL is better at representing the brightness. However, HSV is again better to decrease the brightness of very bright images. We can compare the HSL and HSV model a bit better by comparing their plots. Here is the plot of HSL (left) and HSV (right) with S=255, Hue on the horizontal axis, and Lightness/Value on the vertical axis (maximum lightness at the top):


While the top of the HSL curve is white because white is the color with maximum brightness, the top of the HSV curve contains all colors, because the saturation is 255 and in HSV, saturation 255 has to be a color while white should have 0 saturation. The top of the HSV curve is the same as the center horizontal line of the HSL curve, and the complete HSV curve is exactly the same as the bottom half of the HSL picture.


Color Model Conversions . To draw the plots given above, color model conversion functions have to be used: first you describe the color as HSL or HSV, but to plot it on screen, it has to be converted to RGB first. Transformations from RGB to HSL/HSV are handy as well, for example if you load an RGB image and want to change it hue, you have to convert it to HSL or HSV first, then change the hue, and then change it back to RGB.


More information and source code is avaiable at: