ardikha_candrafata0606RonaldoFPnia_safitri
Published

Automatic Color Sorter Prototype 1.0

This prototype serves to group objects according to their respective colors.

IntermediateProtip7,215
Automatic Color Sorter Prototype 1.0

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
color sensor tcs3200
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

design on SketchUP

Schematics

wiring on fritzing

Code

sketch on Arduino IDE

Arduino
// TCS230 or TCS3200 pins wiring to Arduino
#include <Servo.h>
#define S0 2
#define S1 3
#define S2 4
#define S3 7
#define sensorOut 8

Servo myser1;
Servo myser2;
int pos = 00;

// Stores frequency read by the photodiodes
int red = 0;
int green = 0;
int blue = 0;
int benar=0, warna=0;

void setup() {
  myser1.attach(5);
  myser2.attach(6);
  
  // Setting the outputs
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  
  // Setting the sensorOut as an input
  pinMode(sensorOut, INPUT);
  
  // Setting frequency scaling to 20%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
  
   // Begins serial communication 
  Serial.begin(9600);
}
void loop() {
   myser2.write(0); //servo2 menulis arah 0
  delay(1000); //jeda 500ms
  while(benar==0) //benar = 0
  {
    detectcolor(); //deteksi warna
    posservo(); //posisi servo
    delay(100); //jeda 100 ms
  }
delay(200); //jeda 100 ms
   myser2.write(70); //servo2 menulis 90
    benar=0; //benar =0
  delay(1000); //jeda 500 ms
}

  //detectcolor();
  


void detectcolor()
{
  // Setting RED (R) filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  
  // Reading the output frequency
  red = pulseIn(sensorOut, LOW);
  
   // Printing the RED (R) value
  Serial.print("R = ");
  Serial.print(red);
  delay(100);
  
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  
  // Reading the output frequency
  green = pulseIn(sensorOut, LOW);
  
  // Printing the GREEN (G) value  
  Serial.print(" G = ");
  Serial.print(green);
  delay(100);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  
  // Reading the output frequency
  blue = pulseIn(sensorOut, LOW);
  
  // Printing the BLUE (B) value 
  Serial.print(" B = ");
  Serial.println(blue);
  delay(100);
if(blue<60 && red<150 && green<90){ //ketentuan range RGB
  warna=1;  //warna =1
  Serial.println("biru"); //menampilkan biru
  }
else if((50<red&&red<83) && (110<green && green<150) && blue<100){ //ketentuan range RGB
  warna=2; //warna 2
    Serial.println("Merah");
  }
  else if((120<red&&red<150) && (70<green&&green<90) && (60<blue&&blue<85)){ //ketentuan range RGB
  warna=3;  //warna 3
    Serial.println("Hijau");
  }
else if((43<red && red<70) && (55<green&&green<80) && (60<blue && blue<80)){ //ketentuan range RGB
  warna=4; //warna 4
    Serial.println("Kuning");
  }
else if((90<red && red<105) && (90<green&&green<115) && blue<55){ //ketentuan range RGB
 warna=5; //warna 5
   Serial.println("Ungu");
  }
  else
  {
  warna=0; //Tidak mendeteksi
    Serial.println("tidak mendeteksi");
  }
}

void posservo()
{
  if(warna==1) //jika warna = 1
  {
    myser1.write(30); //myser1 menulis 30
    benar=1;
  }
  else if(warna==2)
  {
    myser1.write(60);
    benar=1;
  }
  else if(warna==3)
  {
    myser1.write(90);
    benar=1;
  }
  else if(warna==4)
  {
    myser1.write(120);
    benar=1;
  }
  else if(warna==5)
  {
    myser1.write(150);
    benar=1;
  }
}

Credits

ardikha_candra
0 projects • 0 followers
fata0606
0 projects • 0 followers
RonaldoFP
0 projects • 0 followers
nia_safitri
1 project • 0 followers

Comments