Color Detection Using Raspberry Pi & Python Animation Tools

About the project

In this tutorial we are going present how to detect colors using Raspberry Pi, TCS34725 sensor, and Python animation tools.

Project info

Difficulty: Moderate

Platforms: DFRobotRaspberry Pi

Estimated time: 1 hour

License: MIT license (MIT)

Items used in this project

Hardware components

DFRobot Gravity: TCS34725 RGB Color Sensor For Arduino DFRobot Gravity: TCS34725 RGB Color Sensor For Arduino x 1
RGB Diffused Common Cathode RGB Diffused Common Cathode x 1
Raspberry Pi 3 Model B Raspberry Pi 3 Model B x 1


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 Library

To install the library from source (recommended) run the following commands on a Raspberry Pi:

HardwareDesign and Implementation

Connect the Sensor as bellow:

Pin 3V3 to sensorVIN

Pin GND to sensorGND

Pin SCL to sensorSCL

Pin SDA to sensorSDA


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.

Mycode :

Note: The code in progress to test new colors

I hope you found it useful!

Schematics, diagrams and documents

Hardware Design and Implementation

CAD, enclosures and custom parts

Color Detection Using Raspberry Pi _ Pdf File

Go to download


My code :

Color Sensing Python Code Note : The code in progress to test new colors


Photo of Aula_Jazmati



Leave your feedback...