#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
const int relayPin = 2; // Digital pin connected to the relay module
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(relayPin, OUTPUT);
}
void loop() {
DateTime now = rtc.now();
// Check if it's time to ring the bell
if ((now.hour() == 9 && (now.minute() == 0 || now.minute() == 10)) ||
(now.hour() == 10 && (now.minute() == 0 || now.minute() == 50)) ||
(now.hour() == 11 && (now.minute() == 0 || now.minute() == 50)) ||
(now.hour() == 12 && now.minute() == 40) ||
(now.hour() == 13 && now.minute() == 20)) {
ringBell();
delay(1000); // Add a delay to prevent multiple bell rings at the same time
}
delay(1000); // Wait for 1 second before checking again
}
void ringBell() {
digitalWrite(relayPin, HIGH); // Turn on the relay, powering the buzzer
delay(500); // Adjust the duration of the bell sound (in milliseconds) as needed
digitalWrite(relayPin, LOW); // Turn off the relay
}