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

Arduino UNO-Based Automated Sorting System with Ultrasonic Sensing and Moisture Detection

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Automated Sorting System with Ultrasonic Sensing and Moisture Detection

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a set of sensors and actuators for environmental sensing and response. It includes two Tower Pro SG90 servos, a Humidity YL-69 sensor, an HC-SR04 Ultrasonic Sensor, and a Buzzer. The Arduino UNO is programmed to control the servos based on the distance measured by the ultrasonic sensor and the moisture level detected by the humidity sensor. When an object is detected within a certain range, the system reads the moisture level, sorts the material accordingly, and signals the event with a buzzer.

Component List

Wiring Details

Arduino UNO

Tower Pro SG90 Servo

Humidity YL-69 Sensor

HC-SR04 Ultrasonic Sensor

Buzzer

Documented Code

#include <Servo.h>

// Ultrasonic Sensor Pins
const int trigPin = 2;
const int echoPin = 3;

// Moisture Sensor Pin
const int moisturePin = A0;

// Servo Pins
Servo servoLid;    // Servo 1 for Lid
Servo servoSeparator; // Servo 2 for Separator

// Buzzer Pin
const int buzzerPin = 11;

// Variables
long duration;
int distance;
int moistureValue;

void setup() {
  // Ultrasonic Sensor Setup
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Moisture Sensor Setup
  pinMode(moisturePin, INPUT);

  // Servo Setup
  servoLid.attach(9);        // Attach servo 1 (lid) to pin 9
  servoSeparator.attach(10); // Attach servo 2 (separator) to pin 10

  // Buzzer Setup
  pinMode(buzzerPin, OUTPUT);

  // Initial Servo Positions (Lid closed, Separator in neutral position)
  servoLid.write(0);          
  servoSeparator.write(90);   
  
  Serial.begin(9600); // Start serial communication for debugging
}

void loop() {
  // Measure distance using Ultrasonic Sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  // If object detected within 20 cm
  if (distance < 20) {
    // Open Lid (Servo 1)
    servoLid.write(90);
    delay(1000); // Wait for the lid to open

    // Read Moisture Sensor
    moistureValue = analogRead(moisturePin);
    
    if (moistureValue > 500) { 
      // Wet material detected, move separator (Servo 2) to wet side
      servoSeparator.write(0);
    } else {
      // Dry material detected, move separator (Servo 2) to dry side
      servoSeparator.write(180);
    }

    // Activate Buzzer for 1 second
    digitalWrite(buzzerPin, HIGH);
    delay(1000);
    digitalWrite(buzzerPin, LOW);

    // Return Separator (Servo 2) to neutral position within 1 second
    servoSeparator.write(90);
    delay(1000); // Wait for the separator to return

    // Close Lid (Servo 1) after 2 seconds from sorting
    delay(1000); // Wait an additional second before closing lid
    servoLid.write(0);

    delay(2000); // Wait before scanning again
  }
}

This code is designed to run on the Arduino UNO and controls the various components based on sensor inputs. It initializes the sensors and actuators in the setup() function and continuously checks for objects within range in the loop() function. When an object is detected, it reads the moisture level, actuates the servos, and sounds the buzzer accordingly.