Arduino-Based Smart Bottle Detection and Reward System with Ultrasonic and Capacitive Sensors
View and Edit Project In Cirkit Designer
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
HC-SR04 Ultrasonic Sensor
- Description: Measures distance using ultrasonic waves.
- Pins: VCC, TRIG, ECHO, GND
SG90 Servo Motor
- Description: A small servo motor used to dispense rewards.
- Pins: PWM, 5V, GND
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
Capacitive Sensor
- Description: Detects the presence of a bottle.
- Pins: GND, VCC, SIGNAL
Power Supply
- Description: Provides power to the circuit.
- Pins: +, -
Wiring Details
HC-SR04 Ultrasonic Sensor
- VCC connected to Power Supply +
- GND connected to Power Supply -
- TRIG connected to Arduino UNO D12
- ECHO connected to Arduino UNO D11
SG90 Servo Motor
- 5V connected to Power Supply +
- GND connected to Power Supply -
- PWM connected to Arduino UNO D9
Arduino UNO
- 5V connected to Power Supply +
- GND connected to Power Supply -
- D12 connected to HC-SR04 Ultrasonic Sensor TRIG
- D11 connected to HC-SR04 Ultrasonic Sensor ECHO
- D9 connected to SG90 Servo Motor PWM
- A0 connected to Capacitive Sensor SIGNAL
Capacitive Sensor
- VCC connected to Power Supply +
- GND connected to Power Supply -
- SIGNAL connected to Arduino UNO A0
Power Supply
- + connected to Arduino UNO 5V, Capacitive Sensor VCC, SG90 Servo Motor 5V, HC-SR04 Ultrasonic Sensor VCC
- - connected to Arduino UNO GND, Capacitive Sensor GND, SG90 Servo Motor GND, HC-SR04 Ultrasonic Sensor GND
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.