In this easy CircuitMagic tutorial you will build detect object colors using esp32 and tcs34725 sensor using ESP32 DevKit and one simple sensor. The project needs only a few connections and a short Arduino IDE sketch.
What does the sensor do?
The TCS34725 measures red, green, blue and clear-channel light levels. Comparing readings over colored paper provides a simple demonstration of optical sensing.
Required components
ESP32 DevKit, 3.3V-compatible TCS34725 breakout, jumper wires, USB cable, colored paper.
Connection diagram
The diagram below is a pin-to-pin connection map: each colored line shows one separate wire between labeled terminals, not a photograph of a particular board’s header layout.

Pin connections
Unplug USB power before wiring. The pin table is authoritative; always verify your board’s printed pin labels and your module’s pinout.
| ESP32 DevKit pin / connection | TCS34725 RGB color sensor breakout connection |
|---|---|
| 3V3 | Sensor VIN / VCC |
| GND | Sensor GND |
| GPIO21 | Sensor SDA |
| GPIO22 | Sensor SCL |
Arduino IDE setup
Install Adafruit TCS34725 and dependencies via Arduino IDE Library Manager. Select the matching board and serial port, then upload this sketch.
Complete Arduino code
#include <Wire.h>
#include <Adafruit_TCS34725.h>
Adafruit_TCS34725 tcs(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!tcs.begin()) {
Serial.println("TCS34725 not found");
while (true) delay(1000);
}
}
void loop() {
uint16_t r, g, b, c;
tcs.getRawData(&r, &g, &b, &c);
Serial.printf("R:%u G:%u B:%u Clear:%u\n", r, g, b, c);
delay(300);
}
Expected output
Hold red and blue paper in turn: the RGB channel readings will change. Open Serial Monitor at the baud rate specified by Serial.begin().
Troubleshooting
Illumination, distance and sensor gain strongly influence readings. This example prints raw channels rather than claiming precise color classification.
If there is no output, double-check the board and port, USB data cable, common ground, sensor pin labels and Serial Monitor speed.
Try next
Once the basic example works, experiment with the sampling delay, add an LED indicator, or log the sensor output to a computer. See more CircuitMagic electronics projects for related beginner tutorials.










