TCS3200 Color Sensor: Raspberry Pi

Model Picture
1. Introduction

The TCS3200 is a color detection sensor that can identify RGB (Red, Green, Blue) values of objects. It converts light intensity into frequency output, which can be read using GPIO pins of the Raspberry Pi.


2. Components

  • Raspberry Pi 4 Model B
  • TCS3200
  • Jumper wires
  • Breadboard (optional)

3. Circuit and Connections

Raspberry Pi Pinout Diagram
Raspberry Pi Pinout Diagram

TCS3200 Colour Sensor Module Pinout Diagram
TCS3200 Colour Sensor Module Pinout Diagram

Connection Table

TCS3200 Pin    Raspberry Pi
VCC            5V
GND           GND
S0         GPIO5
S1         GPIO6
S2        GPIO13
S3        GPIO19
OUT        GPIO26

4. Detailed Step By Step Circuit Working

  1. Sensor uses photodiodes to detect RGB colors
  2. S2 & S3 pins select color filter (Red, Green, Blue)
  3. Light intensity is converted into frequency output
  4. Raspberry Pi reads frequency from OUT pin
  5. Frequency values correspond to RGB intensity

5. Libraries to be Included

pip3 install RPi.GPIO

6. Code (Python)

import RPi.GPIO as GPIO
import time

S2 = 13
S3 = 19
OUT = 26

GPIO.setmode(GPIO.BCM)
GPIO.setup(S2, GPIO.OUT)
GPIO.setup(S3, GPIO.OUT)
GPIO.setup(OUT, GPIO.IN)

def read_color():
count = 0
start = time.time()
while time.time() - start < 0.1:
if GPIO.input(OUT) == 0:
count += 1
return count

try:
while True:
# Red
GPIO.output(S2, 0)
GPIO.output(S3, 0)
red = read_color()

# Blue
GPIO.output(S2, 0)
GPIO.output(S3, 1)
blue = read_color()

# Green
GPIO.output(S2, 1)
GPIO.output(S3, 1)
green = read_color()

print("R:", red, "G:", green, "B:", blue)
print("--------------------")

time.sleep(1)

except KeyboardInterrupt:
GPIO.cleanup()

7. Detailed Step By Step Code Working

  • S2 & S3 select color filter
  • OUT pin outputs frequency pulses
  • Pulse count represents light intensity
  • Program counts pulses for each color
  • Displays RGB values

8. Tips

  • Keep object close to sensor
  • Avoid external light interference
  • Use white LED illumination (on module)
  • Calibrate for accurate color detection
  • Use fixed distance for consistency

9. Uses

  • Color sorting machines
  • Robotics (line/color following)
  • Industrial automation
  • Object detection systems
  • Smart packaging

10. Conclusion

The TCS3200 color sensor allows Raspberry Pi to detect and analyze colors effectively. It is widely used in automation and robotics applications.

തുടക്കക്കാർക്കായുള്ള ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.