Translate

ARDUINO DETEKSI RGB WARNA MENGGUNAKAN SENSOR TCS3200

ARDUINO DETEKSI RGB WARNA MENGGUNAKAN SENSOR TCS3200


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk mendeteksi RGB warna sehingga akan tampak di LCD 16x2. alat ini cuma menampilkan nilai RGB saja. untuk lebih jelasnya berikut adalah komponen dan programnya.




a. Arduino Uno




b. Sensor Warna TCS3200




c. LCD 16x2 + I2C






d. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library

//LiquidCrystal_I2C lcd(0x27, 16, 2);
LiquidCrystal_I2C lcd(0x3F, 16, 2);

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

int frequencyr = 0;
int frequencyg = 0;
int frequencyb = 0;
int jumlah;


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);

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
}


void loop() {
  lcd.setCursor(0, 0);
  lcd.print("R  G  B ");
 
  lcd.setCursor(0, 1);
  // Setting red filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  // Reading the output frequency
  frequencyr = pulseIn(sensorOut, LOW);
  // Printing the value on the serial monitor
  lcd.print(frequencyr);//printing RED color frequency
  lcd.print(" ");
  delay(100);
  // Setting Green filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequencyg = pulseIn(sensorOut, LOW);
  // Printing the value on the serial monitor
  lcd.print(frequencyg);//printing RED color frequency
  lcd.print(" ");
  delay(100);
  // Setting Blue filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequencyb = pulseIn(sensorOut, LOW);
  // Printing the value on the serial monitor
  lcd.print(frequencyb);//printing RED color frequency
  lcd.println("        ");
  delay(100);


}




e. VIDEO HASILNYA








No comments:

Post a Comment