I am going to show you how you can use an RGB LED and a Cds photocell as a colour sensor for a micro-controller. I will illustrate the method to retrieve a colour using Arduino, and I will show you a how you can verify the colour being scanned with a small Processing sketch.
We will be making this colour sensor on a breadboard, but it is easily transferred onto a prototyping board, and for those who fab their own boards, this would be an awesome kit that is super cheap to throw together. I am sure it would only take about two minutes to write a gerber file for this circuit and make a nice little finished sensor.
Step 1: Gather Some Parts
For this sensor you will need
- a breadboard (not required, but it is how I will walk you through it.)
- an RGB LED (alternatively you could use 3 LEDs)
- A 220 ohm resistor
- A CdS photocell (these can be salvaged out of all kinds of things like nightlights or garden lamps)
- An Arduino, or a clone. I am using a RBB in this example
Tools you will need
- A computer
- a cable to upload to your Arduino
Step 2: A Little Theory
Some of you might be wondering how a CdS photocell can detect colours. Well it is surprisingly simple and provides pretty accurate results.
We see colour as a frequency of light reflected from an object. So different colours reflect different wavelengths which our eyes then interpret as colours. (Maybe brain…I am no scientist)
A common CdS photocell has a very similar response to colour as the human eye.
Because colours absorb certain wavelengths and reflect certain wavelengths, we can use different wavelengths(colours) of light and take readings(from a sensor that has nearly human responses) and thereby make a pretty good guess at what colour the sensor is being exposed to.
Step 3: Build the Circuit
I have included both images of the breadboard arrangment, and a small diagram to show you how to wire up the sensor to the Arduino.
The circuit is really simple. First we will look at the RGB LED half of the sensor. It is simply a common cathode RGB LED connected to pins 2,3, and 4 of the Arduino with a 220 ohm resistor going out to ground. This will allow us to turn each of the LEDs within the package on and off individually when we need to.
On the other side of the circuit we have a Cds photocell being fed 5 volts from the arduino. combined with the resistor going out to ground this effectively creates a voltage divider which allows us to read a changing analog value on analog pin 0.
This sensor works great on a breadboard, but it works even better if you put it into a more permanent enclosure to minimilize ambient light interference. The photo of the light tight (ish) enclosure was used in another one of my projects and is included here only to illustrate what I meant. (Feel free to check it out though, here.)
For More Details: Using an RGB LED to Detect Colours