Translate

Deteksi Warna Color Sensor TCS3200 Arduino

Deteksi Warna Color Sensor TCS3200 Arduino


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan sensor warna tcs3200 untuk deteksi warna. jadi alat ini sangatlah sederhana cuma untuk mendeteksi warna lalu menampilkan ke lcd. untuk lebih jelasnya berikut adalah komponen dan kodingnya.



a. Arduino Uno




b. Sensor warna TCS3200




c. LCD 16x2 + I2C






d. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6
int frequency = 0;
int frequencyr;
int frequencyg;
int frequencyb;

void setup() {

  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  
  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);
 
  Serial.begin(9600);
}

void loop() {

  // Setting red filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  // Reading the output frequency
  frequencyr = pulseIn(sensorOut, LOW);
  delay(100);
  
  // Setting Green filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequencyg = pulseIn(sensorOut, LOW);
  delay(100);
  
  // Setting Blue filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequencyb = pulseIn(sensorOut, LOW);
  delay(100);

if((frequencyr > 100)&&(frequencyr < 200)&&(frequencyg > 100)&&(frequencyg < 200)&&(frequencyb > 100)&&(frequencyb < 200)){
//warna  
lcd.setCursor(0,0);
lcd.print("PUTIH  ");
}

if((frequencyr > 250)&&(frequencyr < 300)&&(frequencyg > 220)&&(frequencyg < 270)&&(frequencyb > 210)&&(frequencyb < 250)){
//warna  
lcd.setCursor(0,0);
lcd.print("HIJAU  ");
}

if((frequencyr > 300)&&(frequencyr < 350)&&(frequencyg > 200)&&(frequencyg < 250)&&(frequencyb > 100)&&(frequencyb < 200)){
//warna 
lcd.setCursor(0,0);
lcd.print("BIRU   "); 
}

lcd.setCursor(0,1);
lcd.print(frequencyr);
lcd.print("/");
lcd.print(frequencyg);
lcd.print("/");
lcd.print(frequencyb);
lcd.print("   ");

}




e. VIDEO HASILNYA







No comments:

Post a Comment