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

Arduino UNO Controlled Color Sorting System with TCS3200 and Pneumatic Actuation

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Color Sorting System with TCS3200 and Pneumatic Actuation

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a TCS3200 color sensor and an 8-channel relay module to control various devices, including pneumatic solenoid valves and an AC synchronous motor. The Arduino UNO reads the color detected by the TCS3200 and activates the corresponding relay channel to control the connected device. The circuit is powered by a 12V power supply and a 240V power source for the AC motor.

Component List

Arduino UNO

TCS3200 Color Sensor

5V 8-Channel Relay Module

12V Pneumatic Solenoid Valve (x4)

AC Synchronous Motor (5/6R/min)

12V Power Supply

240V Power Source

Wiring Details

Arduino UNO

TCS3200 Color Sensor

5V 8-Channel Relay Module

12V Pneumatic Solenoid Valves

AC Synchronous Motor

12V Power Supply

240V Power Source

Documented Code

// Pines del TCS3200
#define tcsOut 8
#define tcsS0 9
#define tcsS1 10
#define tcsS2 11
#define tcsS3 12

// Pines de los relés
#define releTolva 0
#define releRojo 1
#define releVerde 2
#define releAzul 3
#define releCinta 4

void activarRele(int relePin) {
  digitalWrite(relePin, HIGH);
}

void apagarRele(int relePin) {
  digitalWrite(relePin, LOW);
}

void activarTolva() {
  activarRele(releTolva);
  delay(1000);  // Mantén la tolva encendida por 1 segundo
  apagarRele(releTolva);
}

void activarCinta(int segundos) {
  activarRele(releCinta);
  delay(segundos * 1000);  // Mantén la cinta encendida por el tiempo especificado
  apagarRele(releCinta);
}

// Funciones para leer colores del TCS3200
int leerColorRojo() {
  digitalWrite(tcsS2, LOW);
  digitalWrite(tcsS3, LOW);
  return pulseIn(tcsOut, LOW);
}

int leerColorVerde() {
  digitalWrite(tcsS2, HIGH);
  digitalWrite(tcsS3, HIGH);
  return pulseIn(tcsOut, LOW);
}

int leerColorAzul() {
  digitalWrite(tcsS2, LOW);
  digitalWrite(tcsS3, HIGH);
  return pulseIn(tcsOut, LOW);
}

// Función para detectar color dominante
String detectarColor() {
  int rojo = leerColorRojo();
  int verde = leerColorVerde();
  int azul = leerColorAzul();

  if (rojo < verde && rojo < azul) {
    return "rojo";
  } else if (verde < rojo && verde < azul) {
    return "verde";
  } else if (azul < rojo && azul < verde) {
    return "azul";
  } else {
    return "otro";
  }
}

void secuenciaColor(int releColor, int segundosCinta) {
  activarTolva();  
  activarCinta(segundosCinta);  // Activa la cinta por el tiempo especificado

  if (releColor != -1) {
    delay(100);  // Pausa de 0.1 segundos
    activarRele(releColor);  // Enciende el relé del color
    delay(1000);  // Mantén encendido el relé de color por 1 segundo
    apagarRele(releColor);  // Apaga el relé de color
  }
}

void setup() {
  // Configuración de pines
  pinMode(releTolva, OUTPUT);
  pinMode(releRojo, OUTPUT);
  pinMode(releVerde, OUTPUT);
  pinMode(releAzul, OUTPUT);
  pinMode(releCinta, OUTPUT);

  pinMode(tcsOut, INPUT);
  pinMode(tcsS0, OUTPUT);
  pinMode(tcsS1, OUTPUT);
  pinMode(tcsS2, OUTPUT);
  pinMode(tcsS3, OUTPUT);

  // Configuración de escala de frecuencia del sensor TCS3200 al 20%
  digitalWrite(tcsS0, HIGH);
  digitalWrite(tcsS1, LOW);
}

void loop() {
  String colorDetectado = detectarColor();  // Leer color desde el sensor

  if (colorDetectado == "rojo") {
    secuenciaColor(releRojo, 5);  // Secuencia para el color rojo
  } else if (colorDetectado == "verde") {
    secuenciaColor(releVerde, 10);  // Secuencia para el color verde
  } else if (colorDetectado == "azul") {
    secuenciaColor(releAzul, 15);  // Secuencia para el color azul
  } else if (colorDetectado == "otro") {
    activarTolva();  // Secuencia para otro color
    delay(100);
    activarCinta(20);
  }
}

This code is designed to run on the Arduino UNO. It initializes the pins connected to the TCS3200 color sensor and the relay module. The loop function continuously reads the color detected by the TCS3200 and activates the corresponding relay to control the pneumatic solenoid valves or the AC synchronous motor based on the color detected. The activarRele and apagarRele functions are used to turn the relays on and off, while the activarTolva and activarCinta functions control the timing of the devices. The leerColorRojo, leerColorVerde, and leerColorAzul functions read the intensity of the red, green, and blue colors, respectively, and the detectarColor function determines the dominant color. The secuenciaColor function orchestrates the sequence of operations based on the detected color.