Making A Timer With A Servo

I have been wanting to make an automatic dog feeder for a while, and I just got a servo motor. My plan is to hook a servo up to my Arduino Uno and somehow make it so that at a chosen time it will activate the servo for a given amount of time. I am new to programming with Arduinos and I would appreciate any help I could get. Thanks, Cowen.

If you are going to have this running for more than a day or two and you don't want the times to drift several minutes a day then you should get a Real-Time Clock (RTC) module to keep the time and date.

If you want the servo to move once a day, pick an hour and minute. Make sure the clock is in 24-hour mode or you will get feedings every 12 hours instead of 24.

Then you can move the servo for one minute a day:

  if (now.day == 13 &&now.minute == 0) // 1 PM every day
    servo.write(180);
  else
    servo.write(0);

You might want to add a prox detector so the "whatever" doesn't close on the dog's head after a minute...

aarg:
You might want to add a prox detector so the "whatever" doesn't close on the dog's head after a minute...

I assumed that the servo would just be dumping a serving of food into a bowl.

I am very sorry, but I was hoping to be able to feed my dog twice a day, is there any way to do that?

programmingisfun:
I am very sorry, but I was hoping to be able to feed my dog twice a day, is there any way to do that?

What times? 9 AM and 7 PM?

  if ((now.hour == 9 && now.minute == 0) // 9 AM every day
      or
      (now.hour == 19 && now.minute == 0)) // 7 PM every day
    servo.write(180);
  else
    servo.write(0);

johnwasser:
What times? 9 AM and 7 PM?

  if ((now.hour == 9 && now.minute == 0) // 9 AM every day

or
      (now.hour == 19 && now.minute == 0)) // 7 PM every day
    servo.write(180);
  else
    servo.write(0);

I tried that, but when I go to upload it to my Arduino Uno, a message pops up saying "now was not declared in this scope.
/tmp/563348960/sketch_sep8a/sketch_sep8a.ino:15:18: error: expected ')' before ';' token

/tmp/563348960/sketch_sep8a/sketch_sep8a.ino:15:19: error: expected primary-expression before ')' token

exit status 1"

Is there any fix for this? Sorry for all of the trouble.

programmingisfun:
I tried that, but when I go to upload it to my Arduino Uno, a message pops up saying "now was not declared in this scope.
Is there any fix for this? Sorry for all of the trouble.

The fix is to connect the RTC (which you will have to buy) and use a matching library to get the current Hour and Minute. Use those values for now.hour and now.minute.