#include <Servo.h> // Include the Servo library
#include <NewPing.h> // Include the NewPing library
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 rtc; // declare an instance of the RTC_DS1307 class
const int pumpPin = 5; // Define the drain pump relay pin
const int pumpOnTime = 5000; // Define the time (in milliseconds) that the pump should be turned on
void setup() {
Serial.begin(9600); // Start the serial communication
if (!rtc.begin()) {
Serial.println("RTC failed");
}
// Set the time if the RTC has not been set
if (!rtc.isrunning()) {
Serial.println("RTC is not running, setting time...");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// Wait for serial monitor to open
while (!Serial) {}
// Print current time for debugging
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
pinMode(pumpPin, OUTPUT); // Set pump pin to output mode
}
void loop() {
DateTime now = rtc.now();
if (now.hour() == 18 && now.minute() == 45 && now.second() ==30 ) {
digitalWrite(pumpPin, HIGH); // Turn on the pump
Serial.println("Pump on"); // Output message for debugging purposes
delay(150000);
digitalWrite(pumpPin, LOW); // Set pump to off initially
Serial.println("Pump off"); // Output message for debugging purposes
}
delay(100);
if (now.hour() == 18 && now.minute() == 45 && now.second() ==30 ) {
digitalWrite(pumpPin, HIGH); // Turn on the pump
Serial.println("Pump on"); // Output message for debugging purposes
delay(150000);
digitalWrite(pumpPin, LOW); // Set pump to off initially
Serial.println("Pump off"); // Output message for debugging purposes
}
}