Arduino UNO-Based Automated Sorting System with Ultrasonic Sensing and Moisture Detection
View and Edit Project In Cirkit Designer
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
- Arduino UNO: A microcontroller board based on the ATmega328P, with a variety of digital and analog I/O pins.
- Tower Pro SG90 Servo (x2): Small and lightweight servos used for moving parts of the system.
- Humidity YL-69 Sensor: A sensor for detecting the moisture level in the soil or other materials.
- HC-SR04 Ultrasonic Sensor: A sensor for measuring distances using ultrasonic waves.
- Buzzer: An electronic buzzer for audible alerts.
Wiring Details
Arduino UNO
- 5V: Powers the servos, humidity sensor, and ultrasonic sensor.
- GND: Common ground for the servos, humidity sensor, ultrasonic sensor, and buzzer.
- A0: Connected to the Humidity YL-69 sensor for moisture level readings.
- D2: Connected to the TRIG pin of the HC-SR04 Ultrasonic Sensor.
- D3: Connected to the ECHO pin of the HC-SR04 Ultrasonic Sensor.
- D9: Connected to the signal pin of one Tower Pro SG90 servo.
- D10: Connected to the signal pin of the other Tower Pro SG90 servo.
- D11: Connected to the positive pin of the Buzzer.
Tower Pro SG90 Servo
- Signal: Receives PWM signal from the Arduino UNO to control the servo position.
- +5V: Powers the servo from the Arduino UNO's 5V output.
- GND: Common ground with the Arduino UNO.
Humidity YL-69 Sensor
- A0: Outputs an analog signal to the Arduino UNO's A0 pin representing moisture level.
- VCC: Powered by the Arduino UNO's 5V output.
- GND: Common ground with the Arduino UNO.
HC-SR04 Ultrasonic Sensor
- VCC: Powered by the Arduino UNO's 5V output.
- TRIG: Receives trigger signal from the Arduino UNO's D2 pin.
- ECHO: Sends echo signal to the Arduino UNO's D3 pin.
- GND: Common ground with the Arduino UNO.
Buzzer
- POSITIVE: Receives signal from the Arduino UNO's D11 pin.
- NEGATIVE: Common ground with the Arduino UNO.
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.