Build a Color Detector — scan any object and watch its name pop up on screen!
This little gadget uses an Arduino UNO, a TCS3200 color sensor, and a 0.96" OLED screen, all connected with colorful jumper wires. Hold any object under the sensor, and the OLED instantly names its color — Red, Green, or Blue. Here's exactly how to build it, with the full circuit and code.
How a color sensor actually "sees" color
The TCS3200 doesn't take a photo — it measures light. Inside it are tiny light detectors covered with red, green, and blue filters. Each filter lets through mostly its own color of light, so by comparing how much light passes through each filter, the Arduino can work out which color is strongest and print its name.
3 filters, 1 sensor chip
The TCS3200 switches between red, green, and blue filters super fast to measure each one in turn.
Reads light as a signal
Each filter reading comes out as a stream of electrical pulses — more light means a faster pulse rate.
OLED shows the answer
The Arduino compares the three readings and prints the winning color's name straight onto the little screen.
What you'll need
A short, beginner-friendly parts list — everything here is common in hobby electronics starter kits.
Arduino UNO
Runs the code, talks to the color sensor, and controls the OLED display.
TCS3200 color sensor module
Detects red, green, and blue light levels reflecting off any object placed in front of it.
0.96" OLED display (I2C, SSD1306)
Shows the detected color's name in big, easy-to-read text.
Breadboard + colorful jumper wires
Connects everything without any soldering — color-coding the wires makes it easy to follow.
USB cable
Powers the Arduino directly from a computer or a USB power bank.
Red, green, and blue objects
LEGO bricks, colored paper, or bottle caps work great for testing the detector.
How the circuit works
The TCS3200 needs four control pins to choose which filter it's reading, plus one output pin that sends pulses back to the Arduino. The OLED just needs two wires for I2C, since it shares the same "conversation line" style as many other small sensors.
Arduino UNO
5V -----------------------> VCC (TCS3200) + VCC (OLED)
GND -----------------------> GND (TCS3200) + GND (OLED)
D4 -----------------------> TCS3200 S0
D5 -----------------------> TCS3200 S1
D6 -----------------------> TCS3200 S2
D7 -----------------------> TCS3200 S3
D8 -----------------------> TCS3200 OUT
A4 (SDA) -------------------> OLED SDA
A5 (SCL) -------------------> OLED SCL
Step-by-step build
Follow these steps in order, and test after each wiring stage if you can.
Place the parts on the breadboard
Position the TCS3200 module and OLED display on the breadboard with enough space between them for wires.
Power both modules
Run a red wire from Arduino 5V and a black wire from GND to both the TCS3200 and OLED power rails.
Wire the TCS3200 control pins
Connect S0, S1, S2, and S3 to Arduino pins D4–D7 using four different colored wires, as shown in the circuit map.
Wire the sensor's output pin
Connect the TCS3200's OUT pin to Arduino pin D8 — this is the wire that carries the light readings back.
Wire the OLED display
Connect the OLED's SDA and SCL pins to Arduino A4 and A5.
Install the libraries
In the Arduino IDE, install Adafruit_SSD1306 and Adafruit_GFX through the Library Manager.
Upload the code
Paste in the sketch below, select "Arduino UNO" as your board, and click Upload.
Test with colored objects
Hold red, green, and blue objects close to the sensor one at a time and watch the OLED name each color.
The Arduino code
This sketch switches the TCS3200 between its red, green, and blue filters, measures each one's pulse timing, and prints whichever color came back strongest on the OLED screen.
// Color Detector — Arduino UNO + TCS3200 + OLED // Beginner-friendly Arduino sketch #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define S0 4 #define S1 5 #define S2 6 #define S3 7 #define OUT_PIN 8 Adafruit_SSD1306 oled(128, 64, &Wire, -1); void setup() { pinMode(S0, OUTPUT); pinMode(S1, OUTPUT); pinMode(S2, OUTPUT); pinMode(S3, OUTPUT); pinMode(OUT_PIN, INPUT); digitalWrite(S0, HIGH); // 20% frequency scaling (good default) digitalWrite(S1, LOW); oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); oled.setTextColor(SSD1306_WHITE); } long readFilter(bool s2, bool s3) { digitalWrite(S2, s2); digitalWrite(S3, s3); return pulseIn(OUT_PIN, LOW); // shorter pulse = stronger color } void loop() { long red = readFilter(LOW, LOW); long green = readFilter(HIGH, HIGH); long blue = readFilter(LOW, HIGH); String colorName; if (red < green && red < blue) colorName = "RED"; else if (green < red && green < blue) colorName = "GREEN"; else colorName = "BLUE"; oled.clearDisplay(); oled.setTextSize(1); oled.setCursor(10, 6); oled.println("Detected Color:"); oled.setTextSize(2); oled.setCursor(20, 28); oled.println(colorName); oled.display(); delay(300); }
Frequently asked questions
Why does a shorter pulse mean a stronger color?
The TCS3200 outputs a frequency signal — more detected light means faster pulses, which show up as a shorter time between pulses when measured with pulseIn().
Does lighting affect the results?
Yes — bright, even lighting gives the most reliable readings. Testing in a dim room or with a shadow over the sensor can throw off the comparison.
Can it detect more than just red, green, and blue?
Yes, with more advanced code — comparing the three raw readings together (instead of just picking the smallest) lets you detect colors like yellow, purple, or white too.
Is this project safe for kids to build?
Yes — it only uses safe, low-voltage USB power, but building alongside a grown-up is still recommended, especially for first-time breadboard wiring.
Comments
Post a Comment