I used an arduino nano with tiny RTC and servo.
First I only wanted to use arduino nano. But learned that without RTC if there is power outage poor cat have to wait longer to be fed. With RTC I can control the feeding time very accurate and with open valve time I can control to quantity of food per feeding.
Code probably looks like mess. But at least arduino gets it.
As I learned you never use an arduino to supply power to the servo. Can I use USB 5V adapter, and plug red wire 5V(arduino) and to the servo red. Where do I plug to black wire in arduino(GROUND?). I want use one adapter (phone charger adapter) to supply power to the Arduino and the servo without any accident.
Thanks!
#include <Wire.h>
#include <RTClib.h>
#include <Servo.h>
#include <DS1307RTC.h>
RTC_DS1307 rtc;//define a object of DS1307 class
Servo myservo; // create servo object to control a servo
const int ONHour1 = 00; // Define feeding time
const int ONMinute1 = 00;
const int ONSecond1 = 00;
const int ONHour2 = 06;
const int ONMinute2 = 00;
const int ONSecond2 = 00;
const int ONHour3 = 12;
const int ONMinute3 = 00;
const int ONSecond3 = 00;
const int ONHour4 = 18;
const int ONMinute4 = 00;
const int ONSecond4 = 00;
const int OpenValveTime = 1000; //valve open time
int CurrentHour;
int CurrentMinute;
int CurrentSecond;
void setup()
{
Serial.begin(9600);
rtc.begin();
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
DateTime now = rtc.now();
// Save check in time;
CurrentHour = now.hour();
CurrentMinute = now.minute();
CurrentSecond = now.second();
if((CurrentHour==ONHour1) && (CurrentMinute == ONMinute1)&& (CurrentSecond == ONSecond1))
{myservo.write(45);
delay(500);
{
delay(OpenValveTime); //valve open time
}
myservo.write(135);
delay(300);
Serial.println("HAPPY CAT");
}
else {
myservo.write(135);
}
if((CurrentHour==ONHour2) && (CurrentMinute == ONMinute2)&& (CurrentSecond == ONSecond2))
{myservo.write(45);
delay(500);
{
delay(OpenValveTime); //valve open time
}
myservo.write(135);
delay(300);
Serial.println("HAPPY CAT");
}
else {
myservo.write(135);
}
if((CurrentHour==ONHour3) && (CurrentMinute == ONMinute3)&& (CurrentSecond == ONSecond3))
{myservo.write(45);
delay(500);
{
delay(OpenValveTime); //valve open time
}
myservo.write(135);
delay(300);
Serial.println("HAPPY CAT");
}
else {
myservo.write(135);
}
if((CurrentHour==ONHour4) && (CurrentMinute == ONMinute4)&& (CurrentSecond == ONSecond4))
{myservo.write(45);
delay(500);
{
delay(OpenValveTime); //valve open time
}
myservo.write(135);
delay(300);
Serial.println("HAPPY CAT");
}
else {
myservo.write(135);
}
}
