#include <LiquidCrystal.h>
#include <Wire.h>
#include <RTClib.h>
#include <EEPROM.h>
RTC_DS1307 rtc; // Use DS1307 instead of DS3231
const int rs = 12, en = 11, d4 = 6, d5 = 5, d6 = 4, d7 = 3; // lcd pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int buzz = 13;
int addr = 17;
const int buttonPin1 = A0; // Button1: Increase hour
const int buttonPin2 = 9; // Button2: Decrease hour
const int buttonPin3 = 8; // Button3: Confirm
const int buttonPin4 = 7; // Extra button for other functionalities
int currentHour = 8; // Default hour for the reminder (can be adjusted by the user)
int setHour = 8; // Temporary variable for adjusting the hour
int reminderCount = 1; // Number of reminders set (1, 2, or 3 times per day)
int buzzMin = 0; // Minutes for alarm (fixed)
int buzzSec = 0; // Seconds for alarm (fixed)
int nowHr, nowMin, nowSec;
unsigned long previousMillis = 0; // Store the last time the message was updated
const long interval = 5000; // Interval at which to show motivational message (5 seconds)
void gwsMessege() { // print get well soon message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Stay Healthy <3"); // Give some cheers
lcd.setCursor(0, 1);
lcd.print("Get Well Soon^-^"); // wish
}
void helpScreen() { // function to display 1st screen on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Press Buttons");
lcd.setCursor(0, 1);
lcd.print("for Reminder...!");
}
void timeScreen() { // function to display Date and time on LCD screen
DateTime now = rtc.now(); // take rtc time and print on display
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time:");
lcd.setCursor(6, 0);
lcd.print(nowHr = now.hour(), DEC);
lcd.print(":");
lcd.print(nowMin = now.minute(), DEC);
lcd.print(":");
lcd.print(nowSec = now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
delay(1500);
}
void displayMotivationalMessage() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Don't be Sad");
lcd.setCursor(0, 1);
lcd.print("be healthy");
delay(4000); // Show first message for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("You're worth it");
delay(2000); // Show second message for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("You're Pretty");
lcd.setCursor(0, 1);
lcd.print("^-^ ^-^");
delay(2000);
}
void setup() {
Wire.begin();
if (!rtc.begin()) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set the current time
}
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome To Our"); // print a message at startup
lcd.setCursor(0, 1);
lcd.print("Medicine Reminder");
delay(1000);
gwsMessege();
delay(3000);
helpScreen();
delay(2000);
timeScreen();
delay(3000);
lcd.clear();
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buzz, OUTPUT);
Serial.begin(9600);
}
void setReminderHour() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Hour:");
lcd.setCursor(10, 0);
lcd.print(setHour);
while (true) {
int bS1 = digitalRead(buttonPin1);
int bS2 = digitalRead(buttonPin2);
int bS3 = digitalRead(buttonPin3);
// Button1: Increase the hour
if (bS1 == HIGH) {
setHour++;
if (setHour > 24) setHour = 0; // Wrap around if it goes beyond 23
lcd.setCursor(10, 0);
lcd.print(" "); // Clear the old hour
lcd.setCursor(10, 0);
lcd.print(setHour);
delay(300); // Debounce delay
}
// Button2: Decrease the hour
if (bS2 == HIGH) {
setHour--;
if (setHour < 0) setHour = 23; // Wrap around if it goes below 0
lcd.setCursor(10, 0);
lcd.print(" "); // Clear the old hour
lcd.setCursor(10, 0);
lcd.print(setHour);
delay(300); // Debounce delay
}
// Button3: Confirm the hour
if (bS3 == HIGH) {
currentHour = setHour; // Set the confirmed hour
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("In ");
lcd.print(setHour);
lcd.print(" hours, you");
lcd.setCursor(0, 1);
lcd.print("will be reminded.");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("You Should Take");
lcd.setCursor(0,1);
lcd.print("Your Med Later");
delay(2000);
lcd.clear();
break;
}
}
}
void loop() {
// Call the function to set the reminder hour when Button4 is pressed
int bS4 = digitalRead(buttonPin4);
if (bS4 == HIGH) {
setReminderHour(); // Enter setup mode to set the reminder hour
}
// Check the time and trigger the buzzer
DateTime t = rtc.now();
if (t.hour() == currentHour && t.minute() == buzzMin && (t.second() == buzzSec || t.second() < buzzSec + 10)) {
digitalWrite(buzz, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Take Medicine!");
delay(5000); // Buzzer stays on for 5 seconds
digitalWrite(buzz, LOW);
}
// Display the motivational message every 5 seconds
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
displayMotivationalMessage(); // Call the motivational message function
}
timeScreen(); // Display the time regularly
delay(1000);
}