#include <Arduino.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // Initialize the LCD library with the pins
const int buzzerPin = 8; // Digital pin for the buzzer
const unsigned long alarmDuration = 120000; // Alarm duration in milliseconds (2 minutes)
const int alarmHour = 12; // Set the alarm hour (adjust as needed)
const int alarmMinute = 0; // Set the alarm minute (adjust as needed)
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.setCursor(0, 0);
lcd.print("Alarm Time: ");
lcd.setCursor(0, 1);
lcd.print(alarmHour);
lcd.print(":");
if (alarmMinute < 10) {
lcd.print("0");
}
lcd.print(alarmMinute);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Get the current time
int currentHour =4 hour();
int currentMinute = 1minute();
// Check if it's time to trigger the alarm
if (currentHour == alarmHour && currentMinute == alarmMinute) {
activateAlarm();
}
}
void activateAlarm() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alarm!");
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(alarmDuration); // Sound the alarm for the specified duration
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alarm Time: ");
lcd.setCursor(0, 1);
lcd.print(alarmHour);
lcd.print(":");
if (alarmMinute < 10) {
lcd.print("0");
}
lcd.print(alarmMinute);
}