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

Arduino-Based Recycling Station with Load Cell, Servo Motor, and Ultrasonic Sensor

View and Edit Project In Cirkit DesignerImage of Arduino-Based Recycling Station with Load Cell, Servo Motor, and Ultrasonic Sensor

Circuit Documentation

Summary

This circuit is designed to interface various sensors and actuators with an Arduino UNO microcontroller. The primary components include a load cell with an HX711 amplifier for weight measurement, an HC-SR04 ultrasonic sensor for distance measurement, an SG90 servo motor for mechanical actuation, and a 16x2 I2C LCD screen for user feedback. The circuit is powered by the Arduino's 5V output, which is distributed to the necessary components. The Arduino runs embedded code to process sensor data, control the servo based on specific conditions, and display system status messages on the LCD.

Component List

Load Cell - Red/white/black/green

Arduino UNO

HC-SR04 Ultrasonic Sensor

SparkFun Load Cell Amplifier - HX711

SG90 Servo Motor

LCD Screen 16x2 I2C

12V Power Supply

Wiring Details

Load Cell - Red/white/black/green

Arduino UNO

HC-SR04 Ultrasonic Sensor

SparkFun Load Cell Amplifier - HX711

SG90 Servo Motor

LCD Screen 16x2 I2C

Documented Code

// Libraries for sensors, servo, and LCD display
#include <HX711.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Ultrasonic sensor pins
const int trigPin = 9;
const int echoPin = 10;

// Load cell pins (HX711)
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
HX711 scale;

// Servo motor for paper reward
Servo rewardServo;
const int servoPin = 6;

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 chars, 2 lines

void setup() {
  // Start serial communication for debugging
  Serial.begin(9600);

  // Initialize ultrasonic sensor pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Initialize load cell
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  // Initialize servo motor
  rewardServo.attach(servoPin);
  rewardServo.write(0); // Start with the servo at 0 degrees

  // Initialize LCD display
  lcd.init();  
  lcd.backlight();  
  lcd.setCursor(0, 0);
  lcd.print("System Ready!");

  Serial.println("System Initialized");
}

void loop() {
  // Ultrasonic sensor reading
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = (duration * 0.034) / 2; // Convert to cm

  // Check if a bottle is detected within 20 cm
  if (distance < 20) {
    Serial.println("Bottle detected by Ultrasonic Sensor!");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Bottle Detected");

    // Load cell reading
    if (scale.is_ready()) {
      float weight = scale.read();
      
      // Check if weight is within a valid range (bottle weighs between 50g to 1000g)
      if (weight > 50 && weight < 1000) {
        Serial.println("Valid plastic bottle detected!");
        lcd.setCursor(0, 1);
        lcd.print("Valid Bottle");

        // Dispense the reward
        dispenseReward();
        
        // Provide feedback on reward
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Reward Dispensed!");
        Serial.println("Reward Dispensed!");
        delay(3000);  // Wait to show message
      } else {
        lcd.setCursor(0, 1);
        lcd.print("Invalid Weight!");
        Serial.println("Object weight out of range");
      }
    } else {
      lcd.setCursor(0, 1);
      lcd.print("Load Cell Error!");
      Serial.println("Load Cell not ready");
    }
  } else {
    lcd.setCursor(0, 0);
    lcd.print("Insert Bottle...");
    Serial.println("No bottle detected");
  }

  delay(1000); // Delay to avoid rapid sensor readings
}

// Function to handle reward dispensing
void dispenseReward() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Dispensing Reward...");
  
  // Move servo to 90 degrees to dispense reward (paper)
  rewardServo.write(90);
  delay(2000);  // Wait for 2 seconds
  
  // Move the servo back to 0 degrees (reset)
  rewardServo.write(0);
}

This code is designed to run on the Arduino UNO microcontroller. It initializes and manages the operation of the ultrasonic sensor, load cell, servo motor, and LCD display. The system detects the presence of a bottle using the ultrasonic sensor, measures its weight with the load cell, and dispenses a reward if the weight is within a specified range. The LCD display provides feedback to the user throughout the process.