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
CartYou'll need
Arduino Uno Rev 3Board Only$32.24
Male-Male Jumper Wires (Set of 65-assorted sized and colors)$6.99
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.
- Use a food storage container with a narrow opening.
- Attach servo to the container lid or side.
- Create a rotating paddle or gate that releases food when servo moves.
- 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.
- Connect RTC VCC to Arduino 5V.
- Connect RTC GND to Arduino GND.
- Connect RTC SDA to Arduino A4.
- Connect RTC SCL to Arduino A5.
- 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.
- Connect servo signal wire to Arduino Pin 9.
- Connect servo VCC to Arduino 5V.
- Connect servo GND to Arduino GND.
You should see
Servo is wired.
Upload feeding schedule code
About 30 minutes
Program automatic feeding times.
- Install RTClib library in Arduino IDE.
- Upload the pet feeder sketch.
- Set current time in the code.
- Set feeding times (e.g., 8 AM and 6 PM).
#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.
- Set a feeding time to 1 minute in the future.
- Watch Serial Monitor to see when feeding triggers.
- Verify food dispenses at the correct time.
- 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.