Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Medication Reminder**
- - Source Code NOT compiled for: ESP8266 NodeMCU V1.0
- - Source Code created on: 2025-04-14 11:04:03
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Display reminder for pill at 4:40 pm ist via rtc */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- #include <Wire.h>
- #include <RTClib.h>
- #include <LiquidCrystal_I2C.h>
- // Initialize RTC and LCD
- RTC_DS3231 rtc;
- LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address may be 0x3F on some LCDs
- // Medicine info
- String medicines[4] = {"Paracetamol", "Vitamin C", "Antibiotic", "Painkiller"};
- int reminderHours[4] = {16}; // Reminder set for 4 PM (16:00 in 24hr format)
- int reminderMinutes[4] = {40}; // Reminder set for 40 minutes past the hour
- // Other components
- const int ledPin = 14; // D5 on NodeMCU (Change pin if needed)
- const int buzzerPin = 0; // D3 on NodeMCU
- const int buttonPin = 2; // D4 on NodeMCU
- // Flag to track reminders
- bool alertTriggered[4] = {false, false, false, false};
- unsigned long lastDisplayUpdate = 0;
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Button_PushButton_PIN_D1 = 1; // This pin is not used in the USER CODE
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(9600);
- Wire.begin();
- rtc.begin();
- lcd.begin(16, 2); // Corrected begin with cols and rows
- lcd.backlight();
- // Setup output pins
- pinMode(ledPin, OUTPUT);
- digitalWrite(ledPin, LOW);
- pinMode(buzzerPin, OUTPUT);
- pinMode(buttonPin, INPUT_PULLUP);
- lcd.setCursor(0, 0);
- lcd.print(" Pill Time Boot ");
- delay(2000);
- lcd.clear();
- pinMode(Button_PushButton_PIN_D1, INPUT_PULLUP); // Keep this for compatibility with EasyButton
- }
- void loop(void)
- {
- DateTime now = rtc.now();
- // Update time display every second
- if (millis() - lastDisplayUpdate >= 1000) {
- showTime(now);
- lastDisplayUpdate = millis();
- }
- // Check reminders
- for (int i = 0; i < 4; i++) {
- if (now.hour() == reminderHours[i] && now.minute() == reminderMinutes[i] && !alertTriggered[i]) {
- triggerReminder(i);
- alertTriggered[i] = true;
- }
- // Reset trigger for next day
- if (now.hour() != reminderHours[i] || now.minute() != reminderMinutes[i]) {
- alertTriggered[i] = false;
- }
- }
- delay(100);
- }
- void showTime(DateTime now) {
- char timeBuffer[9];
- sprintf(timeBuffer, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
- lcd.setCursor(0, 0);
- lcd.print("Time: ");
- lcd.print(timeBuffer);
- lcd.print(" "); // Padding
- }
- void triggerReminder(int index) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Take: ");
- lcd.print(medicines[index].substring(0, 10)); // Fit name in LCD
- digitalWrite(ledPin, HIGH); // Turn on LED
- tone(buzzerPin, 1000);
- // Wait for pushbutton acknowledgment
- while (digitalRead(buttonPin) == HIGH) {
- delay(100);
- }
- // Acknowledged
- noTone(buzzerPin);
- digitalWrite(ledPin, LOW); // Turn off LED
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(medicines[index]);
- lcd.setCursor(0, 1);
- lcd.print("Taken ✔");
- delay(2000);
- lcd.clear();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement