Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Based Coffee Bean Sorting System with Color Sensor and Servo Motors

View and Edit Project In Cirkit DesignerImage of Arduino-Based Coffee Bean Sorting System with Color Sensor and Servo Motors

Circuit Documentation

Summary

This circuit is designed to sort coffee beans based on their color using a TCS3472 color sensor, two servo motors, a pushbutton, and a 16x2 I2C LCD display. The system is controlled by an Arduino UNO microcontroller. The color sensor detects the color of the coffee beans, and based on the detected color, the servo motors sort the beans into defect and non-defect categories. The pushbutton is used to reset the counting of defect and non-defect beans, and the LCD display shows the count of each category.

Component List

Arduino UNO

Servo Motor (2 units)

Pushbutton (2 units)

TCS3472 Color Light-to-Digital Converter with IR Filter

16x2 I2C LCD

Wiring Details

Arduino UNO

Servo Motor 1

Servo Motor 2

Pushbutton 1

Pushbutton 2

TCS3472 Color Light-to-Digital Converter with IR Filter

16x2 I2C LCD

Documented Code

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

// Inisialisasi sensor warna
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

// Inisialisasi servo motor
Servo servoSort, servoGate;
int servoSortPin = 3;    // Pin servo untuk sortir
int servoGatePin = 5;   // Pin servo untuk gate
int posDefect = 30;      // Posisi servo sortir untuk defect
int posNonDefect = 150;  // Posisi servo sortir untuk non-defect
int gateOpen = 0;        // Posisi servo gate terbuka
int gateClose = 180;     // Posisi servo gate tertutup

// Inisialisasi LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); // Alamat I2C untuk LCD 16x2

// Pin untuk push button reset
const int buttonPin = 7;
int buttonState = 0;

// Variabel counting
int countDefect = 0;
int countNonDefect = 0;

void setup() {
  Serial.begin(9600);

  // Setup sensor warna
  if (tcs.begin()) {
    Serial.println("TCS34725 ditemukan");
  } else {
    Serial.println("TCS34725 tidak ditemukan");
    while (1); // Berhenti jika sensor tidak terdeteksi
  }

  // Setup servo
  servoSort.attach(servoSortPin);
  servoGate.attach(servoGatePin);
  servoSort.write(posNonDefect); // Posisi awal servo sortir
  servoGate.write(gateClose);   // Posisi awal servo gate

  // Setup LCD
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Defect: 0");
  lcd.setCursor(0, 1);
  lcd.print("Non-Def: 0");

  // Setup push button
  pinMode(buttonPin, INPUT_PULLUP); // Gunakan pull-up internal
}

void loop() {
  // Operasikan servo gate untuk membuka dan menutup pintu awal
  operateGate();

  // Membaca dan memproses warna biji kopi
  processBean();

  // Cek tombol reset
  checkResetButton();
}

// Fungsi untuk mengoperasikan servo gate
void operateGate() {
  static unsigned long lastGateTime = 0;
  static bool isGateOpen = false;

  if (millis() - lastGateTime >= 4000) { // Delay selama 4 detik
    if (isGateOpen) {
      servoGate.write(gateClose); // Tutup pintu
    } else {
      servoGate.write(gateOpen);  // Buka pintu
    }
    isGateOpen = !isGateOpen;
    lastGateTime = millis(); // Reset waktu
  }
}

// Fungsi untuk membaca dan memproses warna biji kopi
void processBean() {
  uint16_t r, g, b, c;
  float redRatio, greenRatio, blueRatio;

  // Membaca data RGB
  tcs.getRawData(&r, &g, &b, &c);

  // Normalisasi nilai RGB untuk proporsi
  redRatio = (float)r / (r + g + b);
  greenRatio = (float)g / (r + g + b);
  blueRatio = (float)b / (r + g + b);

  // Analisis warna
  if (isRed(redRatio, greenRatio, blueRatio)) {
    Serial.println("Biji tidak defect (merah)");
    servoSort.write(posNonDefect); // Gerakkan ke jalur non-defect
    countNonDefect++; // Tambah counting non-defect
  } else {
    Serial.println("Biji defect (selain merah)");
    servoSort.write(posDefect); // Gerakkan ke jalur defect
    countDefect++; // Tambah counting defect
  }

  // Update LCD
  updateLCD();

  delay(1000); // Tunggu sebelum membaca biji berikutnya
}

// Fungsi untuk mendeteksi warna merah
bool isRed(float redRatio, float greenRatio, float blueRatio) {
  // Threshold untuk menentukan warna merah
  if (redRatio > 0.5 && greenRatio < 0.3 && blueRatio < 0.3) {
    return true; // Warna merah
  }
  return false; // Selain merah
}

// Fungsi untuk mengupdate tampilan pada LCD
void updateLCD() {
  lcd.setCursor(8, 0);
  lcd.print(countDefect);
  lcd.setCursor(9, 1);
  lcd.print(countNonDefect);
}

// Fungsi untuk mengecek tombol reset
void checkResetButton() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) { // Tombol ditekan
    countDefect = 0;
    countNonDefect = 0;
    updateLCD(); // Reset tampilan LCD
    Serial.println("Counting direset");
    delay(500); // Debounce tombol
  }
}

This documentation provides a comprehensive overview of the circuit, including a summary, component list, wiring details, and the embedded