Try to create Servo motor with specific time for pet feeder

I'm trying to create an automatic pet feeder but it just doesn't work and it doesn't give any errors.
Can anyone help me?

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <TimeAlarms.h>
#include <Time.h>

RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int motorPin = 2;
int lastHour = 24;
int lastMinute = 60;

bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

struct FeedTime{
  int hour, minute;
};

FeedTime amFeed = {10, 0};  // i.e. 10:00am
FeedTime pmFeed = {16,20};  // i.e. 5:30pm

void setup ()
{
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
  Wire.begin();
  RTC.begin();
/*  {
    lcd.println("RTC NOT Running!");
    RTC.adjust(DateTime((__DATE__), (__TIME__)));
  }*/
}

void loop ()
{
  DateTime now = RTC.now();
  FeedTime currentTime;
  currentTime.hour = now.hour();
  currentTime.minute = now.minute();
  if((currentTime.minute != lastMinute) && (((currentTime.hour == amFeed.hour) && (currentTime.minute == amFeed.minute)) || ((currentTime.hour == pmFeed.hour) && (currentTime.minute == pmFeed.minute))))
  {
    feedTime = millis();
    feedPet = true;
  }
  lastMinute = currentTime.minute;
  if (feedPet)
  {
    turnFeeder();
  }
  if (millis() - lastPrintTime > 1000UL)
  {
    lcd.setCursor(0, 0);
    char nowDate[24] = "";
    sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
    lcd.print(nowDate);
    // display the time
    lcd.setCursor(0, 1);
    char nowTime[24] = "";
    sprintf(nowTime, "Time: %02d:%02d:%02d", now.hour(), now.minute(), now.second());
    lcd.print(nowTime);
    lastPrintTime = millis();
  }
}

void turnFeeder(void)
{
  static bool pinState = true;
  if (millis() - feedTime < 60000UL) // 60 second(s)
  {
    if (pinState)
    {
      digitalWrite(motorPin, HIGH);
      pinState = false;
    }
  }
  else
  {
    digitalWrite(motorPin, LOW);
    pinState = true;
    feedPet = false;
  }
}

Typeo or not, small errors accumulate..

You commented-out setting the RTC to system UTC time between random, non-function, hanging braces...

You meant to copy/paste this, but did not do it right...

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__));

Your "commented-out" clip will cause "now" to be "Arduino-reset-time" (0:0:0.0 ) plus a few seconds... see above.

Verify your sketch and correct it, line by line. I suspect more errors like the above.

Also, describe "just doesn't work."

p.s. Check the battery on your RTC... no battery v = no time stored.

Describe how you want your pet feeder to work, maybe draw a picture. It will help guide your sketch.

I wanted him to feed my pet him at a specific 2 hours.

"Feed pet every 2 hours." Your current sketch has many flaws, and will not track or display time, or move a motor. Here's how you should make it work:

  1. What ARDUINO do you have?
  2. What LCD do you have (SPI or I2C)?
  3. What MOTOR do you have (DC, Stepper, Servo)?
  4. What RTC do you have?

Use that information to help build some test projects.

  1. LiquidCrystalDiode (LCD) - Make a sketch that uses only your Arduino and an LCD module that places the cursor and displays some words and a changing number.
  1. Servo - Make a sketch that uses only your Arduino, a power supply, and a Servo that moves to a selected position at a given time or command.
  1. RealTimeClock (RTC) - Make a sketch that uses only your Arduino and an RTC module that sets the current time and displays the current time
  1. RealTimeClock - Modify the RTC sketch to sets an alarm, display the alarm and react to the alarm.
  1. Carefully combine projects; replace Serial Monitor with LCD, move Servo to alarm();

Hello @ruip31 - Have you more questions?

Here. Feed your cat.