#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h>
#define MOTOR_PIN 9
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
RTC_DS3231 rtc;
DateTime now;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
rtc.begin();
pinMode(MOTOR_PIN, OUTPUT);
lcd.print("Automatic");
lcd.setCursor(0, 1);
lcd.print("Chicken Feeder");
delay(2000);
lcd.clear();
}
void loop() {
now = rtc.now();
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.setCursor(0, 1);
if (now.hour() == 10 && now.minute() == 3 && now.second() == 0) {
lcd.print("Feeding Time!"); // Display feeding message
Serial.println("ON");
analogWrite(MOTOR_PIN, 255); // Turn on motor at full speed
delay(5000); // Motor runs for 2 seconds
analogWrite(MOTOR_PIN, 0); // Turn off motor
lcd.clear(); // Clear LCD display
}
else if (now.hour() == 10 && now.minute() == 4 && now.second() == 0) {
lcd.print("Feeding Time!"); // Display feeding message
Serial.println("ON");
analogWrite(MOTOR_PIN, 255); // Turn on motor at full speed
delay(5000); // Motor runs for 2 seconds
analogWrite(MOTOR_PIN, 0); // Turn off motor
lcd.clear(); // Clear LCD display
}
else {
lcd.print("Waiting..."); // Display waiting message
Serial.println("OFF");
}
delay(1000);
}