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

Arduino-Controlled Automatic Food Dispenser with RTC Scheduling and Sound Activation

Image of Arduino-Controlled Automatic Food Dispenser with RTC Scheduling and Sound Activation

Circuit Documentation

Summary

This circuit is designed to perform various functions including sound detection, timekeeping, servo control, and Bluetooth communication. It features an Arduino UNO microcontroller at its core, interfaced with a KY-037 microphone sensor, a DS1307 real-time clock module, two MG996R servos, a Bluetooth HC-06 module, a 4-channel relay, LEDs, pushbuttons, resistors, diodes, and capacitors. The circuit is powered by a 9V battery and a 12V power supply. The Arduino UNO controls the components based on sensor inputs, time, and Bluetooth commands to perform actions such as dispensing food at scheduled times or upon receiving a command.

Component List

LEDs

  • LED: Two Pin (red): Red LEDs used as indicators in the circuit.

Microphone

  • KY-037 Microphone: A sound detection sensor module with both analog and digital outputs.

Bluetooth Module

  • Bluetooth HC-06: A Bluetooth module for wireless communication.

Power Supplies

  • 9V Battery: Provides power to the circuit.
  • 12V Power Supply: Provides power to the circuit.

Timer IC

  • 555 Timer IC: A versatile timer IC for generating precise time delays and oscillations.

Real Time Clock Module

  • Real Time Clock Module - DS1307 RTC Breakout Board: A real-time clock module for keeping track of the current time and date.

Servos

  • MG996R: High-torque digital servos for controlling mechanical components.

Relay Module

  • Relay 4 Channel 5v: A 4-channel relay module for controlling high power loads.

Capacitors

  • Electrolytic Capacitor: Used for filtering and stabilizing the power supply.

Diodes

  • Diode: Used for directing current flow and protecting the circuit from reverse voltage.

Resistors

  • Resistor: Used to limit current and divide voltages in the circuit.

Pushbuttons

  • Pushbutton: A momentary switch used for user input.

Microcontroller

  • Arduino UNO: The main controller of the circuit, programmed to manage the components and execute the logic.

Wiring Details

KY-037 Microphone

  • Analog output to Arduino UNO A1
  • Ground to common ground net
  • VCC to 5V net

Bluetooth HC-06

  • VCC to 5V net
  • GND to common ground net
  • TXD to Arduino UNO D0
  • RXD to Arduino UNO D1

9V Battery

  • Positive to 5V net
  • Negative to common ground net

12V Power Supply

  • Positive to 12V net
  • Negative to common ground net

555 Timer IC

  • VCC+ to 5V net
  • Dis to 5V net
  • Th to resistor (1k Ohm) and electrolytic capacitor (0.00047 Farads) net
  • CV to common ground net
  • Rst to 5V net
  • Out to Arduino UNO D8
  • Trig to pushbutton net
  • GND to common ground net

DS1307 RTC Breakout Board

  • 5V to 5V net
  • GND to common ground net
  • SQW to Arduino UNO A2
  • SCL to Arduino UNO A5
  • SDA to Arduino UNO A4

MG996R Servos

  • GND to common ground net
  • VCC to 12V net
  • SIG to Arduino UNO D9 and D10

Relay 4 Channel 5v

  • GND to common ground net
  • IN1 to Arduino UNO D11
  • IN2 to Arduino UNO D12
  • IN3 to Arduino UNO D13
  • IN4 to Arduino UNO A0
  • VCC to 5V net

LEDs

  • Cathode to resistor (220 Ohms) net
  • Anode to Arduino UNO D2, D3, D4, D5

Pushbuttons

  • Pin 1 (in) to 5V net
  • Pin 2 (in) to pushbutton net
  • Pin 3 (out) to Arduino UNO D6 and D7
  • Pin 4 (out) to Arduino UNO A3

Resistors

  • 220 Ohms between LED cathodes and ground net
  • 1k Ohm between 555 Timer IC Th pin and ground net

Electrolytic Capacitors

  • Positive to 5V net or 12V net
  • Negative to common ground net

Documented Code

#include <Wire.h>         // For I2C communication (RTC and other I2C devices)
#include <RTClib.h>       // RTC library for DS1307
#include <Servo.h>        // Servo library

// Pin Definitions
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int led4 = 5;
const int button1 = 6;
const int button2 = 7;
const int relay1 = 11;
const int relay2 = 12;
const int relay3 = 13;
const int relay4 = A0;
const int soundSensorPin = A1;
const int servo1Pin = 9;
const int servo2Pin = 10;

// Components
Servo servo1;
Servo servo2;
RTC_DS1307 rtc;

void setup() {
  // Serial Communication for Bluetooth
  Serial.begin(9600);

  // Pin Modes
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(soundSensorPin, INPUT);

  // Attach Servos
  servo1.attach(servo1Pin);
  servo2.attach(servo2Pin);

  // Initialize RTC
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set the RTC to the date & time this sketch was compiled
  }

  // Initial states
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay4, LOW);
  servo1.write(0);  // Initial position for Servo 1
  servo2.write(0);  // Initial position for Servo 2
}

void loop() {
  // Get current time from RTC
  DateTime now = rtc.now();
  
  // Feeding schedule (e.g., feed at 8:00 AM and 6:00 PM)
  if ((now.hour() == 8 && now.minute() == 0) || (now.hour() == 18 && now.minute() == 0)) {
    dispenseFood();
  }

  // LED Control (optional for indicator)
  digitalWrite(led1, HIGH);  // Turn on LED 1 to indicate system is active
  delay(500);                // Wait for 500ms
  digitalWrite(led1, LOW);   // Turn off LED 1
  delay(500);                // Wait for 500ms

  // Check Button 1 for manual food dispensing
  if (digitalRead(button1) == LOW) {
    delay(50); // Debounce delay
    while (digitalRead(button1) == LOW);  // Wait for button release
    dispenseFood();  // Manually dispense food when button is pressed
  }

  // Sound Sensor Detection for automatic dispensing (optional feature)
  int soundLevel = analogRead(soundSensorPin);
  if (soundLevel > 500) {  // Example threshold for sound detection
    Serial.println("Sound Detected!");
    dispenseFood();
  }

  // Bluetooth Command (Send 'F' to feed or 'T' to get current time)
  if (Serial.available()) {
    char command = Serial.read();
    if (command == 'F') {
      dispenseFood();  // Bluetooth command to dispense food
    } else if (command == 'T') {
      sendCurrentTime();
    }
  }
}

// Function to dispense food using servos
void dispenseFood() {
  Serial.println("Dispensing food...");
  
  // Rotate Servo 1 to release food
  servo1.write(90);   // Move Servo 1 to 90 degrees
  delay(1000);        // Wait for food to dispense
  servo1.write(0);    // Move Servo 1 back to 0 degrees
  delay(1000);        // Wait

  // Rotate Servo 2 to reset dispenser or perform additional task
  servo2.write(90);   // Move Servo 2 to 90 degrees
  delay(1000);
  servo2.write(0);    // Reset Servo 2
  delay(1000);

  // Indicate that food has been dispensed
  digitalWrite(led2, HIGH); // Turn