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

Arduino UNO-Based Cherry Sorting System with Color and Proximity Sensors

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Cherry Sorting System with Color and Proximity Sensors

Circuit Documentation

Summary

This circuit is designed to sort cherries based on their color using a TCS3200 color sensor, two HC-SR04 ultrasonic distance sensors, and two servo motors. The Arduino UNO microcontroller is used to control the sensors and servos. The TCS3200 color sensor detects the color of the cherries, and the ultrasonic sensors detect the presence of cherries. Based on the detected color, the corresponding servo motor is activated to sort the cherries.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. TCS3200 Color Sensor

    • Description: A color sensor that can detect the color of objects.
    • Pins: GND, OUT, S2, S3, VCC, LED, S0, S1
  3. HC-SR04 Ultrasonic Distance Sensor (x2)

    • Description: An ultrasonic sensor used to measure distance.
    • Pins: VCC, TRIG, ECHO, GND
  4. Servo Motor (x2)

    • Description: A servo motor used for precise control of angular position.
    • Pins: GND, V+, PWM

Wiring Details

Arduino UNO

TCS3200 Color Sensor

HC-SR04 Ultrasonic Distance Sensor (1)

HC-SR04 Ultrasonic Distance Sensor (2)

Servo Motor (1)

Servo Motor (2)

Documented Code

#include <Servo.h>

// Pin definitions
#define S0 2               // TCS3200 pin S0
#define S1 3               // TCS3200 pin S1
#define S2 4               // TCS3200 pin S2
#define S3 5               // TCS3200 pin S3
#define OUT_PIN 6          // TCS3200 output pin
#define PROXIMITY1_PIN 7   // First proximity sensor
#define PROXIMITY2_PIN 8   // Second proximity sensor
#define SERVO1_PIN 9       // First servo motor
#define SERVO2_PIN 10      // Second servo motor

// Servo objects
Servo servo1;
Servo servo2;

// Variables for TCS3200
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
const int thresholdReddish = 200;  // Example threshold for reddish color
const int thresholdGreenish = 200; // Example threshold for greenish color

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize TCS3200 pins
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT_PIN, INPUT);

  // Set frequency scaling to 20% (adjust as needed)
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);

  // Initialize proximity sensor pins
  pinMode(PROXIMITY1_PIN, INPUT);
  pinMode(PROXIMITY2_PIN, INPUT);

  // Attach servos
  servo1.attach(SERVO1_PIN);
  servo2.attach(SERVO2_PIN);

  // Move servos to initial position
  servo1.write(0);
  servo2.write(0);
}

void loop() {
  // Read color sensor values
  redValue = readColor(LOW, LOW);   // Red
  greenValue = readColor(HIGH, HIGH); // Green
  blueValue = readColor(LOW, HIGH);  // Blue

  // Display color values (for debugging)
  Serial.print("Red: ");
  Serial.print(redValue);
  Serial.print(" Green: ");
  Serial.print(greenValue);
  Serial.print(" Blue: ");
  Serial.println(blueValue);

  // Determine color and activate sorting mechanism
  if (redValue > thresholdReddish && greenValue < thresholdGreenish) {
    // Reddish cherry detected
    if (digitalRead(PROXIMITY1_PIN) == HIGH) {
      servo1.write(90);  // Activate first servo
      delay(1000);       // Wait for sorting
      servo1.write(0);   // Reset servo
    }
  } else if (greenValue > thresholdGreenish && redValue < thresholdReddish) {
    // Greenish cherry detected
    if (digitalRead(PROXIMITY2_PIN) == HIGH) {
      servo2.write(90);  // Activate second servo
      delay(1000);       // Wait for sorting
      servo2.write(0);   // Reset servo
    }
  } else {
    // Biased or undetectable color, do nothing
    Serial.println("Biased or undetectable color.");
  }

  delay(500); // Small delay for stability
}

// Function to read color value from TCS3200
int readColor(int s2State, int s3State) {
  digitalWrite(S2, s2State);
  digitalWrite(S3, s3State);
  return pulseIn(OUT_PIN, LOW);
}

This code initializes the TCS3200 color sensor, the HC-SR04 ultrasonic distance sensors, and the servo motors. It reads the color values from the TCS3200 sensor and activates the corresponding servo motor based on the detected color and the presence of a cherry detected by the ultrasonic sensors.