Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Uno RGB LED Controller with TCS34725 Color Sensor

View and Edit Project In Cirkit DesignerImage of Arduino Uno RGB LED Controller with TCS34725 Color Sensor

Circuit Documentation

Summary

This circuit consists of an Arduino Uno R3 microcontroller, a TCS3472 color light-to-digital converter with an IR filter, and an RGB LED module. The Arduino Uno R3 reads color data from the TCS3472 sensor and uses this data to control the color of the RGB LED.

Component List

Arduino Uno R3

TCS3472 COLOR LIGHT-TO-DIGITAL CONVERTER with IR FILTER

RGB LED Module

Wiring Details

Arduino Uno R3

TCS3472 COLOR LIGHT-TO-DIGITAL CONVERTER with IR FILTER

RGB LED Module

Code Documentation

Arduino Code

#include <Wire.h>
#include <Adafruit_TCS34725.h>

#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11

// Initialize the TCS34725 color sensor
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
  // Initialize Serial Monitor
  Serial.begin(9600);

  // Initialize color sensor
  if (!tcs.begin()) {
    Serial.println("Couldn't find TCS34725 sensor!");
    while (1);
  }
  
  // Initialize RGB LED pins
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop() {
  uint16_t r, g, b, c;

  // Get RGB color values from the sensor
  tcs.getRawData(&r, &g, &b, &c);

  // Map the raw sensor values to an 8-bit range (0-255)
  int red = map(r, 0, 65535, 0, 255);
  int green = map(g, 0, 65535, 0, 255);
  int blue = map(b, 0, 65535, 0, 255);

  // Print RGB values to Serial Monitor
  Serial.print("R: "); Serial.print(red);
  Serial.print(" G: "); Serial.print(green);
  Serial.print(" B: "); Serial.println(blue);

  // Set RGB LED color
  analogWrite(RED_PIN, red);
  analogWrite(GREEN_PIN, green);
  analogWrite(BLUE_PIN, blue);

  // Delay for a moment
  delay(1000);
}

This code initializes the TCS34725 color sensor and reads RGB values from it. These values are then used to set the color of the RGB LED module. The RGB values are also printed to the Serial Monitor for debugging purposes.