TCS34725 + ESP32: Pinout, Wiring Diagram and Working Code
Share
TCS34725 + ESP32: Pinout, Wiring Diagram and Working Code
Quick answer: wire the TCS34725 module's VIN to the ESP32's 3V3, GND to GND, SDA to GPIO21 and SCL to GPIO22. The sensor answers on I2C address 0x29. Leave the LED and INT pins unconnected for the first test and run the sketch below, which needs no extra library, to print raw red, green, blue and clear counts.
What are the TCS34725 module pins?
The TCS34725 chip itself has five functional pins: VDD, SCL, GND, INT and SDA (ams-OSRAM datasheet, pin description). The breakout adds a voltage regulator and a white illuminator LED, so the module header carries a few extra pins. Our listing names VIN, GND, SDA and SCL in its wiring notes; the chip datasheet supplies the INT function. The table lists pin names only: the catalogue photo is too small to read the header order, so match each wire to the silkscreen on your board.
| Pin | Function | Source |
|---|---|---|
| VIN | Module supply input; the listing says 3.3 V or 5 V via the on-board regulator | Compoden listing |
| GND | Ground | Chip datasheet + listing |
| SDA | I2C data | Chip datasheet + listing |
| SCL | I2C clock | Chip datasheet + listing |
| INT | Interrupt output, open-drain, active low (optional) | Chip datasheet |
| LED | Controls the board's white illuminator LED (board-specific, not in the chip datasheet) | Board design; confirm on yours |
| 3V3 | 3.3 V rail of the module; do not use as your supply input unless your board's documentation says so | Board design; confirm on yours |
How do you wire the TCS34725 to an ESP32?
| TCS34725 pin | ESP32 DevKit pin | Why this pin |
|---|---|---|
| VIN | 3V3 | Keeps the module and its I2C pull-ups at 3.3 V, which ESP32 pins accept |
| GND | GND | Common ground |
| SDA | GPIO21 | Default I2C data pin of the ESP32 Arduino core |
| SCL | GPIO22 | Default I2C clock pin of the ESP32 Arduino core |
| LED | Not connected | Optional illuminator control; test without it first |
| INT | Not connected | Only needed for interrupt-driven reading |
Which ESP32 pins should you avoid?
Every GPIO choice on this page follows the same rules for the 30-pin ESP32-WROOM-32 DevKit (the board Compoden stocks as the ESP32 30-pin CP2102 development board). Espressif's ESP32 GPIO reference is the source:
- Never use GPIO6–11. They connect to the module's SPI flash.
- Avoid the strapping pins GPIO0, 2, 5, 12 and 15 for sensors. Their level at reset decides boot mode and flash voltage, so a sensor holding one of them can stop the board booting. GPIO0 is not even on the 30-pin header; it only goes to the BOOT button.
- GPIO34, 35, 36 and 39 are input-only and have no internal pull-up or pull-down. They are ideal for analog inputs and useless for outputs or clocks.
- Use ADC1 (GPIO32–39) for analog readings. ADC2 pins (GPIO0, 2, 4, 12–15, 25–27) cannot be read while Wi-Fi is running.
- Leave GPIO1 and GPIO3 alone. They carry the USB serial link used for uploads and the Serial Monitor.
- ESP32 GPIOs are 3.3 V only. They are not 5 V tolerant.
What voltage does the TCS34725 need?
The ams-OSRAM datasheet gives the TCS34725 chip a supply range of 2.7–3.6 V (3 V typical) and an absolute maximum of 3.8 V. The TCS34725 variant's I2C inputs are referenced to VDD, which suits a 3.3 V ESP32 directly. The module's regulator is what lets the listing accept 5 V on VIN; the chip itself must never see 5 V. With VIN on the ESP32's 3V3 pin, everything on the bus stays at 3.3 V.
The listing states that pull-up resistors are already fitted, so you do not need external ones on SDA and SCL for a short connection.
Working Arduino code for the TCS34725 on ESP32
No extra library is needed: the sketch uses the registers from the ams-OSRAM datasheet directly. It checks the ID register, sets a 154 ms integration time and 4x gain, powers the sensor on, then prints raw counts whenever the STATUS register reports a finished integration. Raw counts are not calibrated colour values: compare them against readings of known reference colours under the same light.
// TCS34725 colour sensor + ESP32 DevKit (ESP32-WROOM-32)
// Wiring: VIN -> 3V3, GND -> GND, SDA -> GPIO21, SCL -> GPIO22 (LED and INT unconnected)
// Registers from the ams-OSRAM TCS3472 datasheet: address 0x29, COMMAND bit 0x80,
// auto-increment 0xA0, ENABLE 0x00, ATIME 0x01, CONTROL 0x0F, ID 0x12, STATUS 0x13, data 0x14-0x1B.
#include <Wire.h>
const int SDA_PIN = 21;
const int SCL_PIN = 22;
const uint8_t TCS_ADDR = 0x29;
void writeReg(uint8_t reg, uint8_t value) {
Wire.beginTransmission(TCS_ADDR);
Wire.write(0x80 | reg); // COMMAND bit + register address
Wire.write(value);
Wire.endTransmission();
}
uint8_t readReg(uint8_t reg) {
Wire.beginTransmission(TCS_ADDR);
Wire.write(0x80 | reg);
Wire.endTransmission(false);
Wire.requestFrom(TCS_ADDR, (uint8_t)1);
return Wire.available() ? Wire.read() : 0;
}
void setup() {
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
uint8_t id = readReg(0x12); // datasheet: 0x44 = TCS34725, 0x4D = TCS34727
if (id != 0x44 && id != 0x4D) {
Serial.printf("TCS34725 not found (ID 0x%02X). Check VIN, GND, SDA and SCL.\n", id);
while (true) delay(1000);
}
writeReg(0x01, 0xC0); // ATIME: (256 - 0xC0) x 2.4 ms = 154 ms integration
writeReg(0x0F, 0x01); // CONTROL: AGAIN = 4x
writeReg(0x00, 0x01); // ENABLE: PON (power on)
delay(3); // datasheet: at least 2.4 ms after PON
writeReg(0x00, 0x03); // ENABLE: PON + AEN (start RGBC)
Serial.println("TCS34725 ready");
}
void loop() {
if (!(readReg(0x13) & 0x01)) { // STATUS.AVALID: integration finished
delay(10);
return;
}
Wire.beginTransmission(TCS_ADDR);
Wire.write(0xA0 | 0x14); // auto-increment read starting at CDATAL
Wire.endTransmission(false);
Wire.requestFrom(TCS_ADDR, (uint8_t)8);
uint16_t v[4] = {0}; // clear, red, green, blue
for (int i = 0; i < 4 && Wire.available() >= 2; i++) {
uint8_t lo = Wire.read();
uint8_t hi = Wire.read();
v[i] = (uint16_t)hi << 8 | lo;
}
Serial.printf("R=%u G=%u B=%u Clear=%u\n", v[1], v[2], v[3], v[0]);
delay(500);
}
Compile check: this exact sketch compiled for the esp32:esp32:esp32 board (ESP32 Dev Module, ESP32 Arduino core 3.3.10) on 5 October 2026. A clean compile proves the code and libraries agree. It does not prove your wiring, so test it on the bench with the Serial Monitor at 115200 baud.
Common mistakes with the TCS34725 and ESP32
- Feeding 5 V into the 3V3 pin. Use VIN for supply; the chip's absolute maximum is 3.8 V.
-
Two sensors on one bus. The datasheet lists a single I2C address (0x29) for the TCS34725, so two modules on the same SDA/SCL clash. Use the ESP32's second I2C controller (
Wire1) on two other free GPIOs. - Sketch reports an unexpected ID. The datasheet lists 0x44 for TCS34725 and 0x4D for TCS34727 in register 0x12. Any other value means a wiring fault or a different part.
- Saturated readings in sunlight. Lower the gain or the integration time, or shade the sensor.
- Wiring SDA/SCL to GPIO34–39. Those pins are input-only and cannot drive an I2C bus.
- Expecting true colour without calibration. Light source, distance and the board's own LED all change the raw counts.
Where can you get the parts?
| Item | Role | Link |
|---|---|---|
| TCS34725 RGB colour sensor module | Colour and light sensing over I2C | View TCS34725 module |
| ESP32 30-pin CP2102 development board | Controller with Wi-Fi and Bluetooth | View ESP32 board |
Want this sensor in a bigger build? Describe the whole device in Soldr, for example “I want to build a colour sorter with an ESP32, a TCS34725 and a servo”. Soldr returns the exact parts, a wiring map and code that compiles, all from one parts list, so the pins in the code match the pins in the wiring. Compoden stocks the parts and delivers across India.
Sources
Chip pins, voltages, I2C address, registers and ID values: ams-OSRAM TCS3472 datasheet DS000390. ESP32 pin rules: Espressif ESP32 GPIO reference. Module supply, pull-ups and pin names: the Compoden listing.
Related ESP32 wiring guides
- Vibe coding hardware: build an ESP32 project from one sentence
- DHT22 temperature and humidity + ESP32
- XKC-Y25-V non-contact liquid level + ESP32
- INMP441 I2S microphone + ESP32
- 5 mm LDR light sensor + ESP32
- Capacitive soil moisture sensor v2.0 + ESP32
- HX711 and 5 kg load cell + ESP32
- Water level sensor + ESP32
- AS5600 magnetic angle sensor + ESP32
- AHT21B temperature and humidity + ESP32
Frequently asked questions
Which ESP32 pins should I use for the TCS34725?
Use GPIO21 for SDA and GPIO22 for SCL, the ESP32 Arduino core's default I2C pins. Power the module's VIN from 3V3 and connect GND. LED and INT can stay unconnected.
What is the TCS34725 I2C address?
0x29. The datasheet lists one fixed address for the TCS34725, so a second sensor needs the ESP32's second I2C bus.
Can the TCS34725 run on 5 V?
The chip cannot: its supply range is 2.7 to 3.6 V. The module's regulator lets VIN accept 5 V according to the listing, but with an ESP32 there is no reason to; power VIN from 3V3.