Skip to content

Automatic Pet Feeder with Arduino

Build an automated pet feeder using Arduino with a servo motor and real-time clock to dispense food on a schedule.

  • Arduino
  • Intermediate
  • 90 minutes
  • 5 steps

Shop this project

Cart

Prices from vilros.com. Tax and shipping at checkout.

Before you start, you'll need

  • Arduino Uno
  • Servo motor (standard size)
  • Real-time clock module (DS3231)
  • Food storage container
  • Jumper wires
  • Power supply (9V or USB)

Create the food dispenser

About 20 minutes

Build a mechanical dispenser.

  1. Use a food storage container with a narrow opening.
  2. Attach servo to the container lid or side.
  3. Create a rotating paddle or gate that releases food when servo moves.
  4. Test manually: servo rotates, food dispenses, servo returns.

You should see

Servo can dispense a portion of food when rotated.

Connect real-time clock

About 15 minutes

Wire RTC module to Arduino.

  1. Connect RTC VCC to Arduino 5V.
  2. Connect RTC GND to Arduino GND.
  3. Connect RTC SDA to Arduino A4.
  4. Connect RTC SCL to Arduino A5.
  5. Install coin battery in RTC to keep time.

You should see

RTC is wired and powered.

Connect servo motor

About 10 minutes

Wire servo for food dispensing.

  1. Connect servo signal wire to Arduino Pin 9.
  2. Connect servo VCC to Arduino 5V.
  3. Connect servo GND to Arduino GND.

You should see

Servo is wired.

Upload feeding schedule code

About 30 minutes

Program automatic feeding times.

  1. Install RTClib library in Arduino IDE.
  2. Upload the pet feeder sketch.
  3. Set current time in the code.
  4. Set feeding times (e.g., 8 AM and 6 PM).
cpp
#include <Wire.h>
#include <RTClib.h>
#include <Servo.h>

RTC_DS3231 rtc;
Servo feeder;

// Feeding times (24-hour format)
int feedingHours[] = {8, 18};
int feedingMinute = 0;

bool fedToday[2] = {false, false};

void setup() {
  Serial.begin(9600);
  
  if (!rtc.begin()) {
    Serial.println("RTC not found!");
    while (1);
  }
  
  // Set time if RTC lost power
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  
  feeder.attach(9);
  feeder.write(0);
  
  Serial.println("Pet Feeder Ready");
}

void loop() {
  DateTime now = rtc.now();
  
  Serial.print("Time: ");
  Serial.print(now.hour());
  Serial.print(":");
  Serial.println(now.minute());
  
  // Check each feeding time
  for (int i = 0; i < 2; i++) {
    if (now.hour() == feedingHours[i] && 
        now.minute() == feedingMinute && 
        !fedToday[i]) {
      
      Serial.println("Feeding time!");
      dispenseFood();
      fedToday[i] = true;
    }
    
    // Reset fed status at midnight
    if (now.hour() == 0 && now.minute() == 0) {
      fedToday[i] = false;
    }
  }
  
  delay(30000);
}

void dispenseFood() {
  Serial.println("Dispensing food...");
  
  feeder.write(90);
  delay(1000);
  
  feeder.write(0);
  delay(1000);
  
  Serial.println("Food dispensed!");
}

Adjust feeding times in feedingHours array. Default: 8 AM and 6 PM.

You should see

Code uploads and RTC shows correct time.

Test the feeding cycle

About 15 minutes

Verify automatic feeding works.

  1. Set a feeding time to 1 minute in the future.
  2. Watch Serial Monitor to see when feeding triggers.
  3. Verify food dispenses at the correct time.
  4. Check that feeding only happens once per scheduled time.

You should see

Feeder dispenses food automatically at scheduled times.

It didn't work
  • RTC time is wrong.

    Uncomment the rtc.adjust line in setup to set current time. Upload once, then comment it out again and re-upload.

What to do next

Stuck? Contact Vilros Support with your board model and what you see on screen.