Arduino UNO-Based Ultrasonic Waste Segregator with Servo Actuation and Soil Moisture Sensing
View and Edit Project In Cirkit Designer
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
- Microcontroller board based on the ATmega328P
- Provides digital and analog I/O pins
- Powers the circuit and provides a platform for running the embedded code
HC-SR04 Ultrasonic Sensor
- Measures distances using ultrasonic sound waves
- Consists of a transmitter (TRIG) and a receiver (ECHO)
Servo
- A motor capable of precise angular positioning
- Controlled by sending a pulse-width modulated (PWM) signal
Humidity YL-69 Soil Moisture Sensor
- Measures the moisture content in the soil
- Outputs an analog signal proportional to the moisture level
I2C LCD 16x2 Screen
- Displays text on a 16x2 character screen
- Uses the I2C communication protocol for interfacing with the Arduino
Wiring Details
Arduino UNO
5Vconnected to VCC of all other components for powerGNDconnected to GND of all other components for a common groundA0connected to A0 of the Humidity YL-69 sensor for moisture readingA4 (SDA)connected to SDA of the I2C LCD screen for data communicationA5 (SCL)connected to SCL of the I2C LCD screen for clock communicationD8connected to the Servo's pulse input for control signalD11connected to ECHO of the HC-SR04 sensor for receiving the echo signalD12connected to TRIG of the HC-SR04 sensor for sending the trigger signal
HC-SR04 Ultrasonic Sensor
VCCconnected to 5V power supply from the ArduinoGNDconnected to common groundTRIGconnected to D12 on the Arduino for sending out ultrasonic burstsECHOconnected to D11 on the Arduino for receiving the reflected signal
Servo
vccconnected to 5V power supply from the Arduinogndconnected to common groundpulseconnected to D8 on the Arduino for control signal
Humidity YL-69 Soil Moisture Sensor
VCCconnected to 5V power supply from the ArduinoGNDconnected to common groundA0connected to A0 on the Arduino for analog moisture reading
I2C LCD 16x2 Screen
VCC (5V)connected to 5V power supply from the ArduinoGNDconnected to common groundSDAconnected to A4 (SDA) on the Arduino for data communicationSCLconnected to A5 (SCL) on the Arduino for clock communication
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.