#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 rtc;
const int alarmHour = 8; // Set the hour for the alarm
const int alarmMinute = 0; // Set the minute for the alarm
// LCD pin connections
const int lcdCols = 16;
const int lcdRows = 2;
const int lcdAddress = 0x27; // I2C address of your LCD module
LiquidCrystal_I2C lcd(lcdAddress, lcdCols, lcdRows);
const int alarmIntervalHours = 4;
void setup() {
Serial.begin(9600);
rtc.begin();
lcd.begin(lcdCols, lcdRows);
lcd.backlight();
lcd.print("Medicine Alarm");
delay(2000);
lcd.clear();
}
void loop() {
DateTime now = rtc.now();
// Calculate the minutes since midnight
int minutesSinceMidnight = now.hour() * 60 + now.minute();
// Check if the current time matches the conditions for the alarm
if (minutesSinceMidnight % (alarmIntervalHours * 60) == 0) {
lcd.setCursor(0, 0);
lcd.print("Time to take");
lcd.setCursor(0, 1);
lcd.print("your medicine!");
digitalWrite(12, HIGH);
delay(60000); // Wait for a minute to avoid repetitive alarms
digitalWrite(12, LOW);
lcd.clear();
}
// Optional: You can add more functionality or sensors to extend the program
}