Colour sensing with a Raspberry Pi
In their latest video and tutorial, Electronic Hub shows you how to detect colour using a Raspberry Pi and a TCS3200 colour sensor.
What is a TCS3200 colour sensor?
Colour sensors sense reflected light from nearby objects. The bright light of the TCS3200’s on-board white LEDs hits an object’s surface and is reflected back. The sensor has an 8×8 array of photodiodes, which are covered by either a red, blue, green, or clear filter. The type of filter determines what colour a diode can detect. Then the overall colour of an object is determined by how much light of each colour it reflects. (For example, a red object reflects mostly red light.)
As Electronics Hub explains:
TCS3200 is one of the easily available colour sensors that students and hobbyists can work on. It is basically a light-to-frequency converter, i.e. based on colour and intensity of the light falling on it, the frequency of its output signal varies.
I’ll save you a physics lesson here, but you can find a detailed explanation of colour sensing and the TCS3200 on the Electronics Hub blog.
Raspberry Pi colour sensor
The TCS3200 colour sensor is connected to several of the onboard General Purpose Input Output (GPIO) pins on the Raspberry Pi.
These connections allow the Raspberry Pi 3 to run one of two Python scripts that Electronics Hub has written for the project. The first displays the RAW RGB values read by the sensor. The second detects the primary colours red, green, and blue, and it can be expanded for more colours with the help of the first script.
Use it in your projects
This colour sensing setup is a simple means of adding a new dimension to your builds. Why not build a candy-sorting robot that organises your favourite sweets by colour? Or add colour sensing to your line-following buggy to allow for multiple path options!
If your Raspberry Pi project uses colour sensing, we’d love to see it, so be sure to share it in the comments!
Perhaps a hydroponics project could use it to tell you when your tomato is perfectly ripe? :)
It would be a great help for colour blind/other types of blindness people, who say need to read a graph that uses colours for instance, among many other colour indicated things…
Or cannot tell the difference between a Brown Bin (food and garden waste here) and the Green Bin (all other watse not recyclable) They are the same large wheelie bins but look the same with certain type of colour blindness.
Or they need to see the pH or other indicator colour changes in Sciences at school…
I’ll also add a note, the often used Pimoroni EnviropHAT has the TCS3472 version of this sensor.
reading resisters has always been a problem for me.
I have purchased one of these devises and had a few ideas for using it. This could be the boost I need.
Can you use this to read an arbitrary color of an object? We are trying to figure out how the read the color of a given liquid (non-transparent), and compare it to a given standard, so as to find out whether it is substantially different.