The basic idea to this color sensor is that you can represent almost any color if you know how much red, green, and blue is in the color. The way this sensor will work, is I will have three LEDs. A red, a green, and a blue LED. There will also be a light sensor. The entire thing will need to be surrounded by some kind of dark shield to prevent external light from getting in. The sensor will be pressed against a colored object and first, the red light will turn on. The sensor will take a reading. Then the green light, and then the blue light. This way I can get readings of how much red, green, and blue light is reflected back to the sensor. With this information I should be able to roughly determine the color of the object.
The article is really detailed, including the code, and explanation of how it all works. It is always great to see 3D printed enclosures on projects like this.
TSL2561 digital luminosity / lux / light sensor. The TSL2561 luminosity sensor is an advanced digital light sensor, ideal for use in a wide range of light situations. Compared to low cost CdS cells, this sensor is more precise, allowing for exact lux calculations and can be configured for different gain/timing ranges to detect light ranges from up to 0.1 – 40,000+ Lux on the fly. The best part of this sensor is that it contains both infrared and full spectrum diodes! That means you can separately measure infrared, full-spectrum or human-visible light. Most sensors can only detect one or the other, which does not accurately represent what human eyes see (since we cannot perceive the IR light that is detected by most photo diodes)
The sensor has a digital (i2c) interface. You can select one of three addresses so you can have up to three sensors on one board – each with a different i2c address. The built in ADC means you can use this with any microcontroller, even if it doesn’t have analog inputs. The current draw is extremely low, so its great for low power data-logging systems. about 0.5mA when actively sensing, and less than 15 uA when in powerdown mode.
Of course, we wouldn’t leave you with a datasheet and a “good luck!” – we wrote a detailed tutorial showing how to wire up the sensor, use it with an Arduino and example code that gets readings and calculates lux.