In this tutorial I showed you how to perform color detection using TCS34725 RGB color sensor with IR filter and Python turtle tools.
The TCS34725 color sensor can detect a wide variety of colors based on their wavelength. This sensor is specially useful for color recognition projects such as color matching, color sorting, test strip reading and much more.
The TCS34725 is a highly accurate RGB color and ambient light sensor that includes interrupts based on color thresholds.
The module combines the sensor with a logic controllable white LED for illuminating the object to be measured and it comes with the easy to use I2C interface.
The module includes logic level shifting on the I2C bus for easy interfacing to both 3.3V and 5V microcontrollers.
It is important to note that the color detection of the photodiodes themselves is affected by infrared and toget a better result that is not affected by infrared you have to use an infrared filter
RGB full color LED Module KY-009, emitsa range of colors by mixing red, green and blue. The amount of each primary color is adjusted using PWM.
A Brief Note on Python Turtle Module
Python Turtle is something that evolved from Logo programming language, invented in 1966 by Wally Feurzig. With the aid of Object Oriented Programming approach, we can create an impressive set of animations easily.
TCS34725 color sensor LibraryTo install the library from source (recommended) run the following commands on a Raspberry Pi:
Hardware Design and Implementation
Connect the Sensor as bellow:
β’Pin 3V3 to sensorVIN
β’Pin GND to sensorGND
β’Pin SCL to sensorSCL
β’Pin SDA to sensorSDA
Experiment
When we place the blue objectin front of the sensor (1-3 cm), the blue frequency (B) values oscillate between 5 and 40.
Check the values displayed onTerminal. R & G & B readings β see figure below.
I Repeat this process with a green and red objects and write down the upper and bottom frequency limits for each color.
To distinguish between different colors we have three conditions:
β’When the R is the maximum value (in RGB parameters) we know we have a red object
β’When G is the maximum value, we know we have a green object
β’When B is the maximum value, we know we have a blue object
Now, place something in front ofthe sensor. It should print the color detected: red, green or blue.
The sensor can also detect other colors with more conditions.
My code :
https://gist.github.com/aula9/69473ef635e3f8610dcc36815116b4f4
https://drive.google.com/file/d/15ABWtYKKCOR3ZTmqzluHFvd4Qtql49Ut/view?usp=drive_open
Note: The code in progress to test new colors
I hope you found it useful!
Comments