#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address as needed
const int buzzerPin = 8;
const int alarmHour = 22; // Set alarm hour (24-hour format)
const int alarmMinute = 44; // Set alarm minute
void setup() {
pinMode(buzzerPin, OUTPUT);
lcd.begin(16, 2); // Specify the number of columns and rows
lcd.backlight();
rtc.begin();
if (!rtc.isrunning()) {
lcd.print("RTC is NOT running!");
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Uncomment to set the RTC to the date & time this sketch was compiled
}
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(now.day());
lcd.print('/');
lcd.print(now.month());
lcd.print('/');
lcd.print(now.year());
if (now.hour() == alarmHour && now.minute() == alarmMinute) {
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
} else {
digitalWrite(buzzerPin, LOW); // Turn off buzzer
}
delay(1000);
}