First time trying to use arduino nano to make automatic cat feeder

I'm making automatic cat feeder.
I have arduino nano and the servo to open and close the valve for food the come out.
But when I search online for more, I need to buy RTC to control the time and day?
Is it possible to just program time delay between activation to activation of the servo with only arduino nano or Do I need the RTC chip to control the time of activation.
I want to servo activate 4 times in a day and everyday.
This is to code that I'm trying to use, is it correct?
Thanks!

#include <Servo.h>
#define SERVO_PIN 9
Servo demoServo;
#define NUM_DISPENSE_PER_DAY 4 // number of times to dispense food per day
#define DISPENSE_SECS 5 // amount of time to keep dispenser servo open

void setup()
{
demoServo.attach(SERVO_PIN);
}

void loop()
{
demoServo.write(180); // activate feeder
delay( DISPENSE_SECS * 1000 );
demoServo.write(0); // reset feeder
delay( 1000606024/NUM_DISPENSE_PER_DAY - DISPENSE_SECS1000 );
}

this will be too large for an int1000*60*60*24/NUM_DISPENSE_PER_DAY - DISPENSE_SECS*1000 ;you'll overflow ==> use unsigned long

first time posters need to read the forum guidelines on how to post code... if you correct the previous post, you'll get more hints :slight_smile:

The timers built into the average Arduino are not that accurate. You can build a clock based on millis() timing but expect it to drift badly (seconds or minutes per day). You could use an ESP based processor, for example the D1 Mini based on the ESP8266, if you do that then it can connect to the internet and get the time from an NTP server automatically. The problem is that I think you will have a very steep learning curve at the moment given your current level of knowledge.

I suggest you either accept inaccurate timing or use an RTC.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.