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

Arduino UNO-Based Ultrasonic Waste Segregator with Servo Actuation and Soil Moisture Sensing

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Ultrasonic Waste Segregator with Servo Actuation and Soil Moisture Sensing

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with an HC-SR04 Ultrasonic Sensor, a Servo motor, a Humidity YL-69 soil moisture sensor, and an I2C LCD 16x2 Screen. The primary function of this circuit is to measure the distance to an object using the ultrasonic sensor and determine the soil moisture content using the YL-69 sensor. Based on these measurements, the circuit can differentiate between wet and dry waste, actuating the servo motor accordingly to segregate the waste. The I2C LCD screen displays status messages and readings from the sensors.

Component List

Arduino UNO

HC-SR04 Ultrasonic Sensor

Servo

Humidity YL-69 Soil Moisture Sensor

I2C LCD 16x2 Screen

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

Servo

Humidity YL-69 Soil Moisture Sensor

I2C LCD 16x2 Screen

Documented Code

/* Code created by @Skynet Robotics */

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

// LCD configuration
LiquidCrystal_I2C lcd(0x27, 16, 2, POSITIVE);

// Servo configuration
Servo servo1;

// Ultrasonic sensor pins
const int trigPin = 12;
const int echoPin = 11;

// Moisture sensor pin
const int potPin = A0;

// Variables for sensor readings
long duration;
float distance = 0;
int soil = 0;
int avgSoilMoisture = 0;

void setup() {
  Serial.begin(9600);
  
  // Initialize LCD
  lcd.begin(16, 2);
  lcd.print("Skynet Robotics");

  // Sensor and servo setup
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  servo1.attach(8);
  
  delay(2000);  // Initial welcome message display
}

void loop() {
  // Display title on LCD
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Dry Wet Waste");
  lcd.setCursor(3, 1);
  lcd.print("Segregator");

  // Measure distance using ultrasonic sensor
  distance = getDistance();
  Serial.println(distance);

  if (distance < 15 && distance > 1) {
    delay(1000);  // Short delay before reading moisture
    
    // Get average soil moisture
    avgSoilMoisture = getAverageSoilMoisture();
    Serial.print(avgSoilMoisture);
    Serial.println("%");

    // Determine wet or dry waste
    if (avgSoilMoisture > 3) {
      displayMessage("WET");
      servo1.write(180);  // Open for wet waste
    } else {
      displayMessage("DRY");
      servo1.write(0);    // Open for dry waste
    }

    delay(3000);  // Wait before resetting servo
    servo1.write(96);  // Reset servo to neutral
  }

  // Reset variables
  distance = 0;
  avgSoilMoisture = 0;
  delay(1000);  // Prevent too frequent readings
}

// Function to get distance from ultrasonic sensor
float getDistance() {
  long totalDuration = 0;

  for (int i = 0; i < 2; i++) {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(7);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin, HIGH);
    totalDuration += duration;
    delay(10);  // Short delay between readings
  }

  // Calculate average distance
  return (totalDuration / 2.0) * 0.034 / 2.0;
}

// Function to get average soil moisture reading
int getAverageSoilMoisture() {
  int totalSoil = 0;

  for (int i = 0; i < 3; i++) {
    soil = analogRead(potPin);
    soil = constrain(soil, 485, 1023);  // Constrain within valid range
    totalSoil += map(soil, 485, 1023, 100, 0);  // Map to percentage
    delay(75);  // Short delay between readings
  }

  return totalSoil / 3;  // Return average moisture value
}

// Function to display message on LCD
void displayMessage(const char* type) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Garbage Detected!");
  lcd.setCursor(6, 1);
  lcd.print(type);

  Serial.println(type);
}

This code is responsible for initializing the components, reading sensor data, and controlling the servo based on the sensor inputs. It also handles the display of messages on the LCD screen.