Translate

Membuat Alat Deteksi Warna TCS3200 ARDUINO

Membuat Alat Deteksi Warna TCS3200 ARDUINO


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membueat sebuah alat yang digunakan untuk mendeteksi suatu warna tertentu yang diinginkan dengan menggunakan tombol, jadi alat ini tujuan utamanya yaitu untuk mendeteksi suatu warna tertentu sesuai warna yang disimpan sebelumnya, jika warna yang dideteksi sama dengan warna yang disimpan maka akan menghidupkan relay sebagai tanda kalau warna yang deteksi sudah mencapai target, alat ini menggunakan Arduino sebagai kontroller utamanya dan sensor warna yang digunakan adalah TCS3200. selain fitur warna alat ini juga dilengkapi dengan fitur countdown timer, jadi saat waktu habis relay akan menyala, waktu kita bisa setting sesuai dengan tombol atau input yang diberikan melalui tombol, untuk lebih jelasnya berikut adalah skema dan programnya 




a. Arduino Uno





b. Sensor Warna TCS3200





c. LCD + I2C






d. Program Arduino IDE

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);

#define S0 7
#define S1 5
#define S2 2
#define S3 4
#define sensorOut 3
int frequency = 0;

int btset = A0;
int btup = A1;
int btdown = A2;
int btok = A3;

int btsetx = 0;
int btupx = 0;
int btdownx = 0;
int btokx = 0;

int fmerah;
int fgreen;
int fblue;

int simfmerah;
int simfgreen;
int simfblue;

int detik = 0;
int menit = 0;
int jam = 0;
int tanda = 0;

int relay = 8;

int fmerahatas; 
int fmerahbawah; 
int fgreenatas; 
int fgreenbawah; 
int fblueatas; 
int fbluebawah;

int range; 
int simrange; 
int simjam; 
int simmenit; 
 

void setup()
{

 lcd.begin();
 lcd.clear();
 lcd.noCursor();

  pinMode(btset, INPUT_PULLUP);
  pinMode(btup, INPUT_PULLUP);
  pinMode(btdown, INPUT_PULLUP);
  pinMode(btok, INPUT_PULLUP);
 
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);

 pinMode(relay, OUTPUT);
 digitalWrite(relay,HIGH);

  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
 
}


void loop(){

  btsetx = digitalRead(btset);

  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
 
  if(btsetx == 0){
  delay(200);
  lcd.clear();
  setrange();
  lcd.clear();
  delay(1000);
  scanning();
 
  }
 
  btokx = digitalRead(btok);
 
  if(btokx == 0){
  delay(200);
  lcd.clear();
  delay(1000);
  setjam();
  lcd.clear();
  delay(1000);
  setmenit();
  tanda = 1;
  }
 
  if(btupx == 0){
  delay(200); 
  lcd.clear();
  tanda = 0;
  }
 
  if(btdownx == 0){
  delay(200);
  lcd.clear();
  tanda = 0;
  }
 
  if(tanda == 0){ 
  lcd.setCursor(0,0);
  lcd.print("SETTING PLEASE   ");
  digitalWrite(relay,HIGH);
  }
 
  if(tanda == 1){
  
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  frequency = pulseIn(sensorOut, LOW);
  fmerah = frequency;
 
  lcd.setCursor(0,0);
  lcd.print("R=");
  lcd.print(fmerah);
  lcd.print(" ");
  delay(100);
 
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  frequency = pulseIn(sensorOut, LOW);
  fgreen = frequency;

  lcd.print("G=");
  lcd.print(fgreen);
  lcd.print(" ");
  delay(100);

  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  frequency = pulseIn(sensorOut, LOW);
  fblue = frequency;
 
  lcd.print("B=");
  lcd.print(fblue);
  lcd.print("     ");
  delay(800);
 
  fmerahatas = simfmerah + range; 
  fmerahbawah = simfmerah - range; 
  fgreenatas = simfgreen + range; 
  fgreenbawah = simfgreen - range; 
  fblueatas = simfblue + range; 
  fbluebawah = simfblue - range; 
   
  if((fmerah < fmerahatas)&&(fmerah > fmerahbawah)&&(fgreen < fgreenatas)&&(fgreen > fgreenbawah)&&(fblue < fblueatas)&&(fblue > fbluebawah)){
    digitalWrite(relay,LOW);
  } 
   
  lcd.setCursor(0,1);
  lcd.print(simjam);
  lcd.print(":");
  lcd.print(simmenit);
  lcd.print(":");
  lcd.print(detik);
  lcd.print("     ");
 
  if((simjam == 0)&&(simmenit == 0)&&(detik == 0)){
  digitalWrite(relay,LOW);
  }

  detik--;
 
  if(detik <= 0){
  if(simmenit == 0){ 
  detik = 0; 
  }
  if(simmenit > 0){ 
  detik = 59; 
  simmenit--;
  }
  }
  if(simmenit <= 0){
  if(simjam == 0){
 
  }
  if(simjam > 0){
  simjam--; 
  simmenit = 59;
  }
  }
 
  if(simjam < 0){
  simjam = 0;
  }
  if(simmenit < 0){
  simmenit = 0;
  }
  if(detik < 0){
  detik = 0;
  }
 
  }
 
 
}


void setrange(){

btupx = digitalRead(btup); 
btdownx = digitalRead(btdown); 
btokx = digitalRead(btok); 
 
  lcd.setCursor(0,0);
  lcd.print("SET RANGE=");
  lcd.print(range);
  lcd.print("  ");
 
 
if(btupx == 0){
delay(200);
range++;

if(btdownx == 0){
delay(200);
range--;


if(btokx == 0){
delay(200);
simrange = range;
return;


if(range < 0){
range = 0;

 
setrange();
}


void scanning(){

btokx = digitalRead(btok); 
 
  lcd.setCursor(0,0);
  lcd.print("SCAN MERAH=");

  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  frequency = pulseIn(sensorOut, LOW);
  fmerah = frequency;
 
  lcd.setCursor(0,1);
  lcd.print("R=");
  lcd.print(fmerah);
  lcd.print(" ");
  delay(100);
 
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  frequency = pulseIn(sensorOut, LOW);
  fgreen = frequency;

  lcd.print("G=");
  lcd.print(fgreen);
  lcd.print(" ");
  delay(100);

  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  frequency = pulseIn(sensorOut, LOW);
  fblue = frequency;
 
  lcd.print("B=");
  lcd.print(fblue);
  lcd.print("     ");
  delay(100);
 
 
if(btokx == 0){
delay(200);

simfmerah = fmerah;
simfgreen = fgreen;
simfblue = fblue;

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("R=");
  lcd.print(fmerah);
  lcd.print(" ");
  lcd.print("G=");
  lcd.print(fgreen);
  lcd.print(" ");
  lcd.print("B=");
  lcd.print(fblue);
  lcd.print("    ");
  delay(3000);
  lcd.clear();
return;
}

scanning();
}


void setjam(){
btupx = digitalRead(btup); 
btdownx = digitalRead(btdown); 
btokx = digitalRead(btok); 
 
  lcd.setCursor(0,0);
  lcd.print("SET JAM=");
  lcd.print(jam);
  lcd.print("  ");
 
 
if(btupx == 0){
delay(200);
jam++;

if(btdownx == 0){
delay(200);
jam--;


if(btokx == 0){
delay(200);
simjam = jam;
return;


if(jam < 0){
jam = 0;

 
setjam();
}




void setmenit(){
btupx = digitalRead(btup); 
btdownx = digitalRead(btdown); 
btokx = digitalRead(btok); 
 
  lcd.setCursor(0,0);
  lcd.print("SET MENIT=");
  lcd.print(menit);
  lcd.print("  ");
 
 
if(btupx == 0){
delay(200);
menit++;

if(btdownx == 0){
delay(200);
menit--;


if(btokx == 0){
delay(200);
simmenit = menit;
return;


if(menit < 0){
menit = 0;

 
setmenit();
}






e. VIDEO HASILNYA
















1 comment: