display | more...
This handy device can tell you what color something is! For the sake of simplicity, surface attributes such as reflectivity and metallicity are not measured. Regardless, this hardware/software project can differentiate billions of colors. It is assumed that the reader has some knowledge of embedded programming, basic physics, and basic electronics.

Parts list:
  • A Motorola 68HC12 evaluation board (or any other uC system with an A/D Converter)
  • Three bright LEDs.. A Red, a Green, and a Blue. (check out www.Nichia.com or Radio Shack)
  • A CdS Photoresistor with a wide range. (Radio Shack)
  • A variable resistor with a range similar to the CdS cell's (Radio shack, again)
  • As usual, lots of wire and hot glue
  • An opaque tube with a diameter that can hold the CdS cell
  • Three resistors appropriate for connecting the LEDs to a 5 Volt supply
  • A momentary pushbutton switch


The operation of this device is fairly simple: Each LED is pointed at a single spot- an inch or so in front of the CdS cell. When an object is placed at this focus, its color can be determined by light reflected from it.

In turn, each light is turned on, the CdS cell is measured with the A/D, and the light is turned off. Then, with all lights off, another measurement is done. The result is four numbers, r, g, b, and x, which correspond roughly to the amounts of Red, Green, and Blue reflected from the object, and an offset which must be subtracted from each value.

Some calibration will also be necessary, depending on the LEDs, CdS response, and basic geometry of the system. I won't go into the details of calibration, so hopefully it will suffice to say that you can put a white object in the focus to calibrate. The result is three calibration factors, Cr, Cg, and Cb, such that (r-x)*Cr = (g-x)*Cg = (b-x)*Cb when white is measured.

The corrected values R, G, and B, are calculated as follows: R=(r-x)*Cr, G=(g-x)*Cg, and B=(b-x)*Cb.

So what happens if you put a purple object in front of the meter? It will show significant (and roughly equal) amounts for Red and Blue, but very little Green. One could devise a paint-mixing recipe from these data.

Here is a general description of the hardware design.

 +5v------(Cds Cell)-----+-----(Var. Resistor)----Gnd
                         |
                         |
               (to A/D input on uC)
  1. As shown, start by connecting the CdS cell to the +5v supply
  2. connect the other end of the Cds to the variable resistor.
  3. Connect the other end of the variable resistor to ground.
  4. The point where the the components meet should go to the A/D input.
  5. This is a voltage divider. The resistor can be adjusted to provide the maximum voltage range (0..5v) to the A/D converter.
  6. Connect the +5v supply to the reference voltage input of the A/D.
  7. The A/D on the 68HC12 has 10 bits of resolution, which means that it can read values from 0 to 1023 for each color, corresponding to 0..5 Volts.
  8. Put the CdS cell in the tube, a short distance from one end, and glue it into place.
  9. Around the outside of the tube at this end, attach the LED/Resistor pairs with enough lead so they can be focused on a spot in front of the tube.
  10. Connect all of the LED anodes to +5v. Each cathode must be connected to a different I/O bit on the uC. I used PORTB, bits 0, 1, and 2. The uC can illuminate a LED by simply writing a zero to its bit in PORTB.
  11. Connect the switch between ground and bit 3 of PORTB, and set this bit to be an input in software. Whenever PORTB.3 is zero, the switch is depressed.
  12. Now enclose the device in an opaque package with a window where the focus is.


Thanks to a harddrive crash, I leave the software design up to you. A PC debugger can be used to see the R, G, and B values, or an LCD module (www.eio.com) can be connected for a stand-alone system.

Log in or register to write something here or to contact authors.