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

Arduino-Based Smart Bottle Detection and Reward System with Ultrasonic and Capacitive Sensors

View and Edit Project In Cirkit DesignerImage of Arduino-Based Smart Bottle Detection and Reward System with Ultrasonic and Capacitive Sensors

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to detect bottles using an ultrasonic sensor and a capacitive sensor, and then dispense a reward using a servo motor. The circuit is controlled by an Arduino UNO microcontroller, and it includes an LCD display for user feedback.

Component List

  1. HC-SR04 Ultrasonic Sensor

    • Description: Measures distance using ultrasonic waves.
    • Pins: VCC, TRIG, ECHO, GND
  2. SG90 Servo Motor

    • Description: A small servo motor used to dispense rewards.
    • Pins: PWM, 5V, GND
  3. Arduino UNO

    • Description: The main microcontroller used to control the circuit.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  4. Capacitive Sensor

    • Description: Detects the presence of a bottle.
    • Pins: GND, VCC, SIGNAL
  5. Power Supply

    • Description: Provides power to the circuit.
    • Pins: +, -

Wiring Details

HC-SR04 Ultrasonic Sensor

SG90 Servo Motor

Arduino UNO

Capacitive Sensor

Power Supply

Documented Code

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

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

// Infrared sensor pin
const int irSensorPin = 11;

// 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 IR sensor pin
  pinMode(irSensorPin, INPUT);

  // 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");

    // Check IR sensor for confirmation
    if (digitalRead(irSensorPin) == LOW) { // LOW indicates object detected
      Serial.println("Bottle confirmed by IR Sensor!");
      lcd.setCursor(0, 1);
      lcd.print("Bottle Confirmed");

      // 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, 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 initializes the components, reads sensor data, and controls the servo motor to dispense a reward when a bottle is detected and confirmed. The LCD provides feedback to the user, and the serial monitor is used for debugging.