Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Controlled Color Sorting System with TCS3200 and Pneumatic Actuation

Image 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

  • Microcontroller board based on the ATmega328P
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

TCS3200 Color Sensor

  • A color sensor that can detect and measure a nearly limitless range of visible colors.
  • Pins: GND, OUT, S2, S3, VCC, LED, S0, S1

5V 8-Channel Relay Module

  • An 8-channel relay module that can be used to control various appliances and other equipment with large current.
  • Pins: GND, IN1 to IN8, VCC, NC, C, NO

12V Pneumatic Solenoid Valve (x4)

  • An electrically-controlled valve used for controlling the flow of air.
  • Pins: VCC, GND

AC Synchronous Motor (5/6R/min)

  • A motor that operates at a constant speed up to 6 revolutions per minute.
  • Pins: Positive, Negative

12V Power Supply

  • Provides a 12V output to power the relay module and solenoid valves.
  • Pins: +, -

240V Power Source

  • Provides a 240V AC supply for the AC synchronous motor.
  • Pins: Live, Neutral

Wiring Details

Arduino UNO

  • 5V connected to TCS3200 VCC and LED
  • GND connected to TCS3200 GND and 8-Channel Relay GND
  • D12 connected to TCS3200 S3
  • D11 connected to TCS3200 S2
  • D10 connected to TCS3200 S1
  • D9 connected to TCS3200 S0
  • D8 connected to TCS3200 OUT
  • D4 to D0 connected to Relay IN5 to IN1 respectively

TCS3200 Color Sensor

  • VCC and LED connected to Arduino 5V
  • GND connected to Arduino GND
  • S3 connected to Arduino D12
  • S2 connected to Arduino D11
  • S1 connected to Arduino D10
  • S0 connected to Arduino D9
  • OUT connected to Arduino D8

5V 8-Channel Relay Module

  • GND connected to Arduino GND
  • IN1 to IN5 connected to Arduino D0 to D4 respectively
  • VCC connected to 5V power supply
  • NO of each relay connected to VCC of each corresponding solenoid valve
  • C of each relay connected to 12V power supply + and 240V Power Source Live for the AC motor

12V Pneumatic Solenoid Valves

  • VCC of each valve connected to NO of corresponding relay
  • GND of each valve connected to 12V power supply -

AC Synchronous Motor

  • Positive connected to NO of corresponding relay
  • Negative connected to Neutral of 240V Power Source

12V Power Supply

    • connected to C of relays and VCC of solenoid valves
    • connected to GND of solenoid valves

240V Power Source

  • Live connected to C of relay for AC motor
  • Neutral connected to Negative of AC motor

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.