Color shorting machine using Arduino

colour shorting machine
This content provide you Experience

Today we going to make color shorting machine using Arduino and color sensor ( TCS3200 ) where it sense the color like color of gems and place gems at different angles using servo motors by this process we can separate different color of gems using some mechanism process performed by servo motor .

Equipment required

  1. A Structure made with cardboard.
  2. Servo motor
  3. Arduino UNO
  4. Jumper cables
  5. Color Sensor (TCS3200)

Step 1 – Cut the cardboard

Cut that board like that and assemble it –

After assembly it looks like

Upload this code to Arduino IDE

#include <Servo.h>

#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6

Servo topServo;
Servo bottomServo;

int frequency = 0;
int color=0;

void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);

  // Setting frequency-scaling to 20%
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);

  topServo.attach(7);
  bottomServo.attach(8);

  Serial.begin(9600);
}

void loop() {

  topServo.write(110);
  delay(500);
  
  for(int i = 110; i > 62; i--) {
    topServo.write(i);
    delay(2);
  }
  delay(2000);
  
  color = readColor();
  delay(10);  

  switch (color) {
    case 1:
    bottomServo.write(50);
    break;

    case 2:
    bottomServo.write(75);
    break;

    case 3:
    bottomServo.write(100);
    break;

    case 4:
    bottomServo.write(125);
    break;

    case 5:
    bottomServo.write(150);
    break;

    case 6:
    bottomServo.write(175);
    break;
    
    case 0:
    break;
  }
  delay(300);
  
  for(int i = 62; i > 10; i--) {
    topServo.write(i);
    delay(2);
  } 
  delay(200);
  
  for(int i = 29; i < 110; i++) {
    topServo.write(i);
    delay(2);
  }
  color=0;
}

// Custom Function - readColor()
int readColor() {
  // Setting red filtered photodiodes to be read
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  int R = frequency;
  // Printing the value on the serial monitor
  Serial.print("R= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.print("  ");
  delay(50);

  // Setting Green filtered photodiodes to be read
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  int G = frequency;
  // Printing the value on the serial monitor
  Serial.print("G= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.print("  ");
  delay(50);

  // Setting Blue filtered photodiodes to be read
  digitalWrite(S2, LOW);
  digitalWrite(S3, HIGH);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  int B = frequency;
  // Printing the value on the serial monitor
  Serial.print("B= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.println("  ");
  delay(50);

  if(R<83 & R>76 & G<142 & G>130 ){
    color = 1; // PINK
  }
  
  if(B<120 & B>109 & G<109 & G>98 ){
    color = 3; // Green
  }
  if(R<80 & R>68 & G<98 & G>88 & B<117 & B>108 ){
    color = 4; // Yellow
  }

  if (R<160 & R>142 & B<92 &B>77){
    color = 6; // Blue
  }
  
  return color;  
}

You are done now fill gems to the cylindrical tube and this machine will Automatically Rearranging or separating gems with their color property.

If it gives you error while Sensing color of gems if might due to light present in surrounding if their is low light sensor value is different than sensor valve at light. So adjust sensor value by reading same color again and again.

Like if you Want to set value of green color put green color below the sensor or put 4 to 5 gems of green color in the tube due to which sensor reads green color again and again.

Now go to serial monitor and adjust value in this code below

if(B<120 & B>109 & G<109 & G>98 ){
    color = 3; // Green
  }

like here we get value of G = 100 and B = 115 in serial monitor for green color. so we adjust greater than or less than value by increasing and decreasing some values from average value we get from sensor.

Similarly You can perform For All color present .

Leave a Comment

Your email address will not be published. Required fields are marked *

Related post