NOOB HELP -Arduino cat feeder -Servo & RTC



I’ve no servos handy, so can’t comment on how to power them. Hope someone else will. But yes, quite possibly need to power it differently if you insist on those cells.

Four rechargeable AAs don’t sound like enough; the Uno is a reasonably hungry board, and the voltage regulator will fade out if the input voltage is below minimum. Check the voltage of the AAs while they are running the Uno and compare against the minimum. Once the minimum is reached, the 5V or 3.3V pins on the Uno will show a decline. Starting a servo after the minimum is reached will likely reset the microcontroller, because the current surge by the servo will cause the logic voltage to collapse, and the reset will stop the microcontroller driving the servo, the voltage will recover, the sketch will run, only to repeat the cycle.

Suggest you power it from the power supply as you say, and prepare for what will happen if you have a blackout. (You’re not in SA, but the NSW grid has comparable design constraints.) If it were me, a 12V 7AH sealed lead acid battery and 350mA float charger would be my choice if a backup is really needed.

No, the DS1307 is not analog, it is pretty much entirely digital. In the Arduino world, the analog pins can be used for digital signals. Very common. Yes, those are the connections that worked for me. The assembly is still on my lab bench; and it has been going for almost 15 hours now. I forgot to mention one thing; there’s a 1k resistor that I added between SQ and 3.3V (or 5V), in lieu of using INPUT_PULLUP for D2.


To explain your battery situation a bit more; while the nominal voltage will be 1.2V per cell, the total of four in series will be a nominal 4.8V. Nickel based AA cells will start off at about 1.6V per cell when fully charged, and decline to about 1.1V per cell before they are considered to be discharged.

So that’s 6.4V to start with, dropping down slowly to 4.4V. So your cells might not have been fully discharged, but they were certainly below the minimum required to operate your project.

Also, usually one cell in a pack will have a lower voltage than the others, and this affects the total voltage.

When the current drawn increases suddenly, such as with a servo starting up, the voltage of the cells will fall suddenly as well.


I had assumed the board would consume almost no power through the night, but I guess it is functioning fully throughout the night running the timer program, I underestimated the amount of power this would use. Not a big deal for now, another lesson leant and something to be aware of for other projects. I have read about power saving features, but not just yet for me.

This is exactly what I would describe;

The reset flashes the LED in P13 and an attempt to run the servo, rinse and repeat. Good, now I know it was a power issue, it started this loop within a minute of 12 hours from being activated so I am pretty pleased with that. I could not have done this without you. once this has performed on the wedding day I will look at introducing the RTC and maybe getting it to go on a sleep cycle to conserve power. Once I get a second board I will try hooking up the RTC as you had it and see what happens.

Thank you so much, you are an excellent and knowledgeable teacher. My cats and I thank you for your support. Where is the best resource for developing my knowledge (if I’m not here), as most things seem to be extremely basic (single blink LED) or quite advanced (far beyond my ability to comprehend). Is there a recommended book, site, flow of development from my level upwards? It has been great to reach out and get this support, however I am sure you have projects of your own to be developing.

Thank you again, and I am sure I will be asking more about the RTC.




Sure, no worries, come back when you’re ready for the next steps. If I’m not active, there should be someone else.

Little Bird Electronics run Arduino classes. They’ll really get you started. There’s also a Canberra group that meets weekly. Assessing your development and comprehension over the past few days suggests to me that you won’t have any trouble learning, and so I’d rather not make specific suggestions. I’ll give you some advice though;

Yearn for that state of mind of doubt and fear when you look at something really complicated, because that’s when you’re actually learning. Approach that state with a willingness to step through the parts you do understand and search for resources that explain the parts that are in doubt. As you encounter resources, assess them for usefulness, clarity, and cost. Journal your experience and resource pointers.

Then do things with what you’ve learned. Probe your understanding by writing a sketch and assembling something. Get it working, save it somehow, and move onto the next thing. You’ll fail many times, and each time your experience will grow.

(Actually, you could almost take those two paragraphs above and apply them to relationships.)

I’ve just measured the current for the Uno with DS1307 running a timing sketch at 50mA 5V, and this is about a thousand times more than what would be acceptable in a good design for a battery operated device. A wall clock can run for months off a single alkaline AA cell. Plenty of opportunity to cut the power cost.


That is what I am going to be aiming for in the long term.

This is beautiful, and inspiring. So much so, I sat down and read it over and again. Then I researched how to set time on to a DS1307 and now I managed to do this.
10/7/16 20:25:22
10/7/16 20:25:23
10/7/16 20:25:24
10/7/16 20:25:25
10/7/16 20:25:26

Thank you,



Well done.

An RTC module has three uses;

  • a source of timing signal SQ, which is probably more accurate in the long term than a microcontroller oscillator,

  • an external timer calibrated in human language (YY/MM/DD HH:MM:SS), with battery backup,

  • a tiny memory area where data will live as long as the battery does.

On the downside, the RTC module costs running power, space, replacement batteries, and two or three digital I/O pins. Also time spent coding and testing. Having the timer use human language makes coding much harder, because of the mixed base 60 and base 24 nature of human time.

In your project, possible designs are;

  • just use the SQ signal, and count 43200 transitions between feedings; 12 hour anniversaries of when the system was last turned on,

  • use the human language timer, and wait for a particular time of day before feeding,

  • as above, but also use the tiny memory area to store the date and time of the previous feeding, so that if the power comes back on the system can do an extra feeding if the previous feeding was more than 12 hours ago.


Okay,…maybe I played a little more, I was multitasking on wedding things as well. I have nearly finished the prototype with the current and tested iteration of the sketch on it, still waiting to test the servo operation values.
I have also been fiddling around with the time libraries guide, and time.alarm. I think this (see below) is close to the DS1307 program that I would need to use. I think this will also write the time to the serial monitor. I don’t have a board to test this on at the moment as mine is currently in service, I have more on the way though.

Hopefully this will use option two;

However not store the feed data, so if it’s interrupted it could cause an issue with the written time. If I removed the time write line on this sketch, as the DS1307 has time stamped onto it already, would it just use the alarm time to go off? Something I can test and play around with once I have another board.

I have also added some more possible development ideas at the bottom of the code, so I can move them up as I add code and complication.


 * This is a code structure for my Cat feeder. 
 * It needs to get a servo motor to move every 12 hours, or at 0700 and 1900 using a DS1307
 * with a long term reasonable degree of accuracy. 
 * Compiled from online resources and learning. For Cat feeder
 * P Hoskins, Canberra, ACT, 04.10.16
 * with help from littlebird forum - 
 * Secondary addition of an RTC controlled timer to the system 
 // will require batteries-  FUTURE  solar and rechargeable system-
 //these are the time library inclusions
#include <TimeLib.h>
#include <TimeAlarms.h>
AlarmId id;
// servo library inclusions
#include <Servo.h> //Adds servo library to system
Servo myservo; // names the servo, could also be a number??
const int servoPin = 11; //identifies servo pin

void setup() {
 //Time and alarm codes
  while (!Serial) ; // wait for Arduino Serial Monitor

// Is this needed if I use the pre stamped time on the DS1307??
  setTime(8,29,0,1,1,11); // set time at time of upload, use H,M,S DD,MM,YY 

 // create the alarms, to trigger at specific times
  Alarm.alarmRepeat(7,00,0, MorningAlarm);  // 7:00am every day
  Alarm.alarmRepeat(19,00,0,EveningAlarm);  // 7:00pm every day

// servo setup
 pinMode(13, OUTPUT);
    digitalWrite(13, 1);
    digitalWrite(13, 0);


void loop() {
  Alarm.delay(1000); // wait one second between clock display

// functions to be called when an alarm triggers:
void MorningAlarm() {
  Serial.println("Alarm: - Feedimng time"); //writes to LCD screem??
    delay(1000); //open speed of the servo
    myservo.write(180); //angle is changeable depending on the amount of food delivered
    delay(1000); //close speed of the servo

void EveningAlarm() {
  Serial.println("Alarm: - Feedimng time"); //writes to LCD screem??
    delay(1000); //open speed of the servo
    myservo.write(180); //angle is changeable depending on the amount of food delivered
    delay(1000); //close speed of the servo

void digitalClockDisplay() {
  // digital clock display of the time in serial monitor- FUTURE send to 2x16 LCD and scroll next feed //time

void printDigits(int digits) {
  if (digits < 10)
 * Further developments
 * print time to a 2x16 lcd screen scrolling with not feed time and current time and count down??
 * save last feed time incase of interuptions
 * add solar charger to battery pack
 * IoT extension for remote feeding
 * camera, or a system to check cats are happy and eating.
 * Low level food light, ambient light sensor in food hopper


Thanks for the update. I’m presuming you’re using PJRC’s updated Time, TimeAlarm, and DS1307RTC libraries which are referenced in the start of

PJRC’s libraries are at;

Caveat: I’ve not used these libraries yet. I’ve tended to use ARM, or ESP8266 cores instead of Arduino Uno when I want something with a sense of human time.

Using TimeLib.h or TimeAlarms.h like you do is using the internal timing of the microcontroller on the Uno. About as accurate as delay(). To add the DS1307, you may need to add code to enable the DS1307RTC library as the timing source for the Time library. Then accuracy will change to that of the DS1307.

When using without DS1307, if you remove the setTime call, the Time library will use whatever time source it has, which if it is none will likely be that timeStatus will return timeNotSet and alarms might not work. I don’t know. You can easily test without waiting 12 hours though.

As there’s no difference between your morning and evening functions, these could be the same function. I guess you may plan to make them different.

You might also add buttons for setting the time. That will be fun!


I wasn’t using the RTC library, as I assumed it was a given source of time. I can put that in though when I start looking into it more. Buttons to adjust the time would be great, Making it easier to re set to daylight savings etc. I will add that to the developments list in the bottom comment in the code.

At this point I am having issues with the food dropping down, it seems the food has a round plane and two flat planes, making it three sided. This means that when the initial drop goes through the opening, a cave is formed in the food hopper, easy fix, put in an agitator. I have again managed to fudge the code to get a second servo to run after the first servo opens up the chute, in the code and I am pretty sure I can get the two to run almost simultaneously, I will play around with that tonight.

My current pressing question is servo or stepper motor for the agitator? It only needs to move a small amount of food around to get more food to collapse the cave that appears. A 4.2kg 6v servo would be plenty of grunt and they are easily accessible through Jaycar, (the same as the one opening the chute). If they can run simultaneously I will be able to get more food through opening. However a servo needs to sweep action right (forward and back), when a stepper would be able to rotate(full circle), pushing food around in a circular motion. In my mind this puts less stress on the whole set up, but I don’t really know enough about how the two different systems work to make that call.
Any advice on this?


Thanks. That’s an interesting new problem. What springs to mind;

  • a stepper will require a driver module, but a servo has the driver module built in,

  • watch the total current from power supply if both are activated at once,

  • a hopper with two different slopes may change cave formation.


Long term, you might make your own hopper with a 3D printer; there are some organisations that will print your design for you. A hopper that works the material in one dimension at a time as it falls looks interesting. Google image search for the “diamondback hopper”. Other interesting keywords are rathole, bridge and hangup, to describe the cave formation.