Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

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

Image 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

  • Description: A sensor used to measure weight or force.
  • Pins: E+, A-, E-, A+

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13

HC-SR04 Ultrasonic Sensor

  • Description: A sensor used to measure distance via ultrasonic sound waves.
  • Pins: VCC, TRIG, ECHO, GND

SparkFun Load Cell Amplifier - HX711

  • Description: An amplifier for the load cell to increase the signal quality.
  • Pins: VDD, VCC, DAT, SCK, GND, B+, B-, A+, A-, AVDD

SG90 Servo Motor

  • Description: A small and lightweight servo motor for simple mechanical movements.
  • Pins: PWM, 5V, GND

LCD Screen 16x2 I2C

  • Description: A liquid crystal display with 16 characters and 2 lines, using the I2C protocol for communication.
  • Pins: SCL, SDA, VCC, GND

12V Power Supply

  • Description: Provides a 12V power source for the circuit.
  • Pins: +, -

Wiring Details

Load Cell - Red/white/black/green

  • E+ connected to SparkFun Load Cell Amplifier - HX711 AVDD
  • A- connected to SparkFun Load Cell Amplifier - HX711 A-
  • E- connected to SparkFun Load Cell Amplifier - HX711 GND
  • A+ connected to SparkFun Load Cell Amplifier - HX711 A+

Arduino UNO

  • 5V pin provides power to HC-SR04 Ultrasonic Sensor VCC, SG90 Servo Motor 5V, LCD Screen 16x2 I2C VCC, and SparkFun Load Cell Amplifier - HX711 VCC
  • GND pin provides a common ground reference for all components
  • A4 connected to LCD Screen 16x2 I2C SDA
  • A5 connected to LCD Screen 16x2 I2C SCL
  • D10 connected to HC-SR04 Ultrasonic Sensor ECHO
  • D9 connected to HC-SR04 Ultrasonic Sensor TRIG
  • D6 connected to SG90 Servo Motor PWM
  • D3 connected to SparkFun Load Cell Amplifier - HX711 SCK
  • D2 connected to SparkFun Load Cell Amplifier - HX711 DAT

HC-SR04 Ultrasonic Sensor

  • VCC connected to Arduino UNO 5V
  • TRIG connected to Arduino UNO D9
  • ECHO connected to Arduino UNO D10
  • GND connected to Arduino UNO GND

SparkFun Load Cell Amplifier - HX711

  • VCC connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND and Load Cell - Red/white/black/green E-
  • DAT connected to Arduino UNO D2
  • SCK connected to Arduino UNO D3
  • A+ connected to Load Cell - Red/white/black/green A+
  • A- connected to Load Cell - Red/white/black/green A-
  • AVDD connected to Load Cell - Red/white/black/green E+

SG90 Servo Motor

  • PWM connected to Arduino UNO D6
  • 5V connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND

LCD Screen 16x2 I2C

  • SCL connected to Arduino UNO A5
  • SDA connected to Arduino UNO A4
  • VCC connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND

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.