Arduino In True Color

As part of a larger project, I needed to have a way to allow a computer to “see” the color of an object.  In this case, size and shape of the object were unimportant, however the position of the objects that need to be sorted means that the detector must be able to fit into a very small space.  This ruled out using cameras and the like.

In order to accomplish this, I turned to my Arduino, and started brainstorming.  My initial thought was to use a very bright light and three photoresistors with RGB screens over the top.  This has the benefit of being *very* fast, but it still requires a good amount of space as well as finding the right material to use for gels.  I’ve tried to find good colors like that in hobbyist quantities before, and it was always a pain.

The solution I decided on was to using a single tri-color LED paired with a single phototransistor.  By cycling through the colors and measuring the resistance at certain times, I should be able to retrieve something very close to the correct color.  I placed the phototransistor in one of the analog read pins.  I hooked my common anode LED up by placing the anode to +v, and the cathodes to PWM leads set to “OUTPUT”.  They work a bit opposite of what you may be used to, requiring you to bring the pin low (via an analog write of 0) to turn them on.

It is very easy calibrate by measuring a black object for your minimums, and then a white object for your maximum values.   After that quick setup you have a working color detector that can fit into the area of a single LED and a photoresistor.  You can see it in action below.

Leave a Reply

Your email address will not be published. Required fields are marked *