My cat automatic feeder

First time using arduino. video
I used arduino nano with tiny RTC. I know little bit of C++ so it wasn't hard for me to learn.

#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 = 800; //valve open time
const int OpenPos = 100; //open degree

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();
    Serial.println(CurrentHour); 

  
  if((CurrentHour==ONHour1) && (CurrentMinute == ONMinute1)&& (CurrentSecond == ONSecond1))
  {myservo.write(OpenPos);
  delay(15);
    {
  delay(OpenValveTime); //valve open time
  }
  myservo.write(30);
  delay(15);

  Serial.println("HAPPY CAT");
  }
  else {
    myservo.write(30);
  }

  
 if((CurrentHour==ONHour2) && (CurrentMinute == ONMinute2)&& (CurrentSecond == ONSecond2))
 {myservo.write(OpenPos);
  delay(15);
    {
  delay(OpenValveTime); //valve open time
  }
  myservo.write(30);
  delay(15);

  Serial.println("HAPPY CAT");
  }
  else {
    myservo.write(30);
  }

  
   if((CurrentHour==ONHour3) && (CurrentMinute == ONMinute3)&& (CurrentSecond == ONSecond3))
 {myservo.write(OpenPos);
  delay(15);
    {
  delay(OpenValveTime); //valve open time
  }
  myservo.write(30);
  delay(15);

  Serial.println("HAPPY CAT");
  }
  else {
    myservo.write(30);
  }

  
   if((CurrentHour==ONHour4) && (CurrentMinute == ONMinute4)&& (CurrentSecond == ONSecond4))
  {myservo.write(OpenPos);
  delay(15);
    {
  delay(OpenValveTime); //valve open time
  }
  myservo.write(30);
  delay(15);

  Serial.println("HAPPY CAT");
  }
  else {
    myservo.write(30);
  }
  
}
1 Like

Post it in the project hub :+1:
Very nice work :muscle:

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