i am trying to turn my 12v dc motor on at a certain time (i.e. 10am) spin for a set amount of time (i.e. 10 seconds) and then turn off until the next time (i.e. 6pm) and do the same function. This is going to be for a pet feeder. I have set the RTC which is a DS1307 type, i have the code for that set up with the date and time synced to real time, however i cannot get the motor to turn at a specific time.
this is the code i have so far.
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int motorPin = 9;
int time = 20500;
void setup () {
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
lcd.println("RTC is NOT running!");
RTC.adjust(DateTime((DATE), (TIME)));
}
}
void loop () {
DateTime now = RTC.now();
lcd.setCursor(0,1);
lcd.print("TIME: ");
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
if (time == "20500"){
digitalWrite(motorPin, HIGH);
}
else (time != "20500"){
digitalWrite(motorPin, LOW);
}
lcd.setCursor(0,0);
lcd.print("DATE: ");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
}