Step 3: Build the Colour Sensor
Start by wiring up the CdS photocell. One side should go to a 5V pin on the Arduino. The other end should go out to ground via a 10k resistor, and also to analog pin 2 on the Arduino. (see wiring diagram, it is marked pin 0, but the code uses pin 2, either will work, just make the appropriate changes)
The sensitivity of the sensor can be changed by altering the resistor. A higher resistance will provide a better sensitivity to darker colours. Anywhere from 1k up to 10k should be decent. I used a 10k because it was what I had on hand, but I believe that a lower value would have been better for this application.
Once the the Cds photocell is wired up, wire in the 3 LEDs with their grounds going through the 220 ohm resistor. The red LED will connect to digital pin 2 on the Arduino. The green to pin 3, and the blue to pin 4.
Try to arrange the LEDs so that they are equidistant from the photocell. Another hint is to try and leave a little bit of wire leads above your proto-board so that you can gently bend them in order to fine tune the beams. You want the LEDs to illuminate the area beneath the photocell as equally as you can manage. (see wiring diagram)
Use some heat shrink tubing or something else to shroud the CdS from direct exposure from the LEDs. While we will be doing balancing to our readings, we don't want to contend with to much extra light. We are trying to detect what light is detected, and having too much exposure to direct light will throw the reading off. I used a section cut from a cheap black pen to make my shroud, and hot glued it in place.
Once the circuit is built and the shroud is added to the CdS photocell, you can go ahead and shroud the entire sensor ensemble. It is not necessary, but will help the sensor to keep a decent balance even when the ambient light changes. An added bonus is that it hides all the flashing from the sensor doing it's thing. I used a bit of black plastic I had kicking around from a garden light to make mine.
I cut it to fit my project, and also a bit to allow the sensor to sit, and then glued my board in place.
To further cut back on ambient light interfering, I went on to wrap the whole ensemble in black electrical tape.