Smart Multi-Dose Medication Adherence Dispenser with Missed-Dose Alerting for Chronic Care

1. Introduction

Medication adherence is an important part of managing chronic health conditions. Patients who take long-term medications may sometimes forget scheduled doses, take medication at the wrong time or experience difficulties managing multiple medicines throughout the day.

These challenges can affect treatment routines and increase the burden on caregivers.

The Smart Multi-Dose Medication Adherence Dispenser with Missed-Dose Alerting for Chronic Care is an innovative electronics and Internet of Things (IoT) project designed to improve medication organization and reminder management.

The system uses an ESP32 microcontroller, a Real-Time Clock (RTC), a dispensing mechanism, sensors and a notification system to manage scheduled medication reminders.

At programmed reminder times, the device alerts the user and makes the designated compartment accessible. It then monitors whether the medication has apparently been collected and sends an alert to a caregiver if the scheduled interaction is not confirmed within a configured period.

The project demonstrates how embedded systems, automation and wireless communication can support people managing long-term medication routine.

    2. Objectives of the Project

    The main objectives are:

    • To design an automated multi-dose medication reminder and dispensing prototype.
    • To use an ESP32 microcontroller to control medication scheduling.
    • To integrate an RTC module for accurate timekeeping.
    • To provide audible and visual medication reminders.
    • To monitor whether a medication compartment has been accessed.
    • To detect and report unconfirmed scheduled medication interactions.
    • To send missed-dose notifications to caregivers through Wi-Fi.
    • To improve medication organization for people managing chronic care routines.

    3. Components and Materials Required

    No.ComponentQuantityPurpose
    1ESP32 DevKit1Main microcontroller
    2DS3231 RTC module1Accurate timekeeping
    3SG90 servo motor1Controls compartment access
    416×2 LCD with I2C1Displays reminders
    5Push buttons3–4User interaction
    6Buzzer1Audible reminders
    7LEDs3Visual status indication
    8IR sensor1Detects collection activity
    9Medication storage compartments1 setStores scheduled doses
    10ResistorsAs requiredCircuit protection
    11Jumper wiresAs requiredElectrical connections
    12Power supply1Powers the system
    13Enclosure1Houses the electronics

    Optional components include a backup battery, load cell, Wi-Fi dashboard and additional caregiver notification interface.

    4. How the Smart Medication Dispenser Works

    The system operates through a programmed medication schedule stored in the ESP32.

    The DS3231 RTC module maintains the current time, even when the main power supply is disconnected, provided its backup battery is functional.

    The ESP32 continuously compares the current time with the programmed reminder schedule.

    When a scheduled reminder is reached, the system activates the buzzer and displays a message on the LCD.

    The servo motor controls access to the designated compartment. An IR sensor can detect whether the user has interacted with the dispensing area.

    If the interaction is not confirmed within the configured reminder window, the system records an unconfirmed dose event and sends a notification to the caregiver.

    System operation sequence:

    • The user or caregiver configures the medication schedule.
    • The RTC module provides the current time.
    • The ESP32 checks the programmed schedule.
    • A reminder is activated when a scheduled time arrives.
    • The appropriate compartment is made accessible.
    • The sensor monitors collection activity.
    • The system records the interaction status.
    • If no interaction is detected within the reminder window, a missed-dose alert is generated.
    • The caregiver receives a notification through the connected platform.
    DoseRight: ESP32 Smart Automatic Medicine Dispenser

    5. System Block Diagram

    The project can be represented using the following functional architecture:

    
                 MEDICATION SCHEDULE
                         |
                         v
                  ESP32 CONTROLLER
                         |
              +----------+----------+
              |          |          |
              v          v          v
           DS3231      LCD        BUZZER
            RTC       DISPLAY      ALERT
              |
              v
        Schedule Checking
              |
              v
        SERVO DISPENSING
          MECHANISM
              |
              v
       MEDICATION ACCESS
              |
              v
         IR COLLECTION
            SENSOR
              |
              v
        ESP32 PROCESSING
              |
              v
           Wi-Fi MODULE
              |
              v
       CAREGIVER NOTIFICATION

    6. Circuit Connections

    The ESP32 serves as the central processing unit. The RTC and LCD communicate through the I2C interface, while the servo, buzzer, buttons and sensors use digital GPIO connections.

    How to Use HiLetGo ESP-32: Pinouts, Specs, and Examples | Cirkit Designer

    Pin connection table

    ComponentESP32 connection
    DS3231 SDAGPIO 21
    DS3231 SCLGPIO 22
    DS3231 VCC3.3V
    DS3231 GNDGND
    LCD SDAGPIO 21
    LCD SCLGPIO 22
    Servo signalGPIO 18
    IR sensor OUTGPIO 19
    Buzzer positiveGPIO 23
    Green LEDGPIO 25
    Red LEDGPIO 26
    Confirmation buttonGPIO 27

    Important electrical precautions:

    • Power the servo using a suitable external regulated 5V supply rather than the ESP32 3.3V output.
    • Connect the external supply ground to ESP32 GND.
    • Use an appropriate transistor driver for a buzzer that exceeds the GPIO current rating.
    • Ensure the LCD and RTC voltage levels are compatible with the ESP32.
    • Do not connect 5V signals directly to ESP32 GPIO pins.

    7. Mathematical and Programming Logic

    The system uses time comparison to determine when a medication reminder should be activated.

    The basic time-matching condition is:

    T_{\text{current}}=T_{\text{scheduled}}

    The reminder system also uses a defined response window.

    For example, if a reminder is activated at 8:00 AM and the configured response window is 15 minutes, the system checks for a collection interaction before 8:15 AM.

    The missed-dose detection condition is:

    T_{\text{current}}-T_{\text{reminder}}>T_{\text{window}}

    And:

    \text{Collection Status}=\text{Not Confirmed}

    When both conditions are satisfied, the system generates a missed-dose alert.

    This is an electronic reminder and collection-monitoring function. It cannot establish whether medication was swallowed or whether a prescribed dose was taken correctly.

    8. ESP32 Programming Code

    The following example provides the foundation for the project.

    It uses:

    • ESP32 for system control.
    • DS3231 for timekeeping.
    • SG90 servo for compartment access.
    • IR sensor for collection detection.
    • LCD for reminders.
    • Buzzer and LEDs for alerts.
    • Wi-Fi and Blynk for caregiver notifications.

    Required Arduino IDE libraries

    Install the following libraries:

    • RTClib by Adafruit.
    • ESP32Servo.
    • LiquidCrystal_I2C.
    • Blynk.

    Create a Blynk event named missed_dose and enable the relevant notification settings.

    
    #define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
    #define BLYNK_TEMPLATE_NAME "Smart Medicine Dispenser"
    #define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
    
    #include <WiFi.h>
    #include <BlynkSimpleEsp32.h>
    #include <Wire.h>
    #include "RTClib.h"
    #include <ESP32Servo.h>
    #include <LiquidCrystal_I2C.h>
    
    char ssid[] = "YOUR_WIFI_NAME";
    char pass[] = "YOUR_WIFI_PASSWORD";
    
    RTC_DS3231 rtc;
    Servo dispenser;
    
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    
    #define SERVO_PIN 18
    #define IR_PIN 19
    #define BUZZER 23
    #define GREEN_LED 25
    #define RED_LED 26
    #define CONFIRM_BUTTON 27
    
    // Example reminder schedule
    const int reminderHours[] = {8, 14, 20};
    const int reminderMinutes[] = {0, 0, 0};
    
    const int totalReminders = 3;
    
    // Reminder response window in milliseconds
    const unsigned long responseWindow = 15UL * 60UL * 1000UL;
    
    bool reminderActive = false;
    bool collectionDetected = false;
    bool alertSent = false;
    
    int activeReminder = -1;
    int lastReminderDay = -1;
    
    unsigned long reminderStart = 0;
    
    BlynkTimer timer;
    
    void openCompartment() {
      dispenser.write(90);
      delay(800);
      dispenser.write(0);
    }
    
    void activateReminder(int index) {
    
      activeReminder = index;
      reminderActive = true;
      collectionDetected = false;
      alertSent = false;
    
      reminderStart = millis();
    
      digitalWrite(BUZZER, HIGH);
      digitalWrite(RED_LED, HIGH);
    
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Medicine Time!");
    
      lcd.setCursor(0, 1);
      lcd.print("Check Compartment");
    
      openCompartment();
    
      Blynk.logEvent(
        "medicine_reminder",
        "Scheduled medication reminder activated."
      );
    }
    
    void checkSchedule() {
    
      DateTime now = rtc.now();
    
      if (lastReminderDay != now.day()) {
        lastReminderDay = now.day();
      }
    
      for (int i = 0; i < totalReminders; i++) {
    
        if (now.hour() == reminderHours[i] &&
            now.minute() == reminderMinutes[i] &&
            now.second() < 2 &&
            activeReminder != i) {
    
          activateReminder(i);
        }
      }
    }
    
    void checkCollection() {
    
      if (!reminderActive) return;
    
      // IR sensor assumed active LOW
      if (digitalRead(IR_PIN) == LOW) {
    
        collectionDetected = true;
        reminderActive = false;
    
        digitalWrite(BUZZER, LOW);
        digitalWrite(RED_LED, LOW);
        digitalWrite(GREEN_LED, HIGH);
    
        lcd.clear();
        lcd.print("Collection");
        lcd.setCursor(0, 1);
        lcd.print("Interaction Seen");
    
        Blynk.logEvent(
          "medicine_collected",
          "Medication compartment interaction detected."
        );
    
        delay(2000);
        digitalWrite(GREEN_LED, LOW);
      }
    
      else if (millis() - reminderStart >
               responseWindow) {
    
        reminderActive = false;
    
        digitalWrite(BUZZER, LOW);
        digitalWrite(RED_LED, HIGH);
    
        lcd.clear();
        lcd.print("Missed Reminder");
        lcd.setCursor(0, 1);
        lcd.print("Caregiver Alert");
    
        if (!alertSent) {
    
          Blynk.logEvent(
            "missed_dose",
            "No collection interaction detected "
            "within the reminder window."
          );
    
          alertSent = true;
        }
      }
    }
    
    void setup() {
    
      Serial.begin(115200);
    
      Wire.begin(21, 22);
    
      pinMode(IR_PIN, INPUT);
      pinMode(BUZZER, OUTPUT);
      pinMode(GREEN_LED, OUTPUT);
      pinMode(RED_LED, OUTPUT);
      pinMode(CONFIRM_BUTTON, INPUT_PULLUP);
    
      lcd.init();
      lcd.backlight();
    
      dispenser.attach(SERVO_PIN);
      dispenser.write(0);
    
      if (!rtc.begin()) {
        lcd.print("RTC Error!");
        while (true) delay(100);
      }
    
      // Set the clock manually when first configuring.
      // Uncomment once, upload, then comment it again.
      // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    
      lcd.print("Medicine System");
      lcd.setCursor(0, 1);
      lcd.print("Connecting WiFi");
    
      Blynk.begin(
        BLYNK_AUTH_TOKEN,
        ssid,
        pass
      );
    
      lcd.clear();
      lcd.print("System Ready");
    
      timer.setInterval(1000L, checkSchedule);
      timer.setInterval(200L, checkCollection);
    }
    
    void loop() {
    
      Blynk.run();
      timer.run();
    
      // Manual confirmation button
      if (reminderActive &&
          digitalRead(CONFIRM_BUTTON) == LOW) {
    
        reminderActive = false;
        digitalWrite(BUZZER, LOW);
        digitalWrite(RED_LED, LOW);
    
        lcd.clear();
        lcd.print("User Confirmed");
        lcd.setCursor(0, 1);
        lcd.print("Reminder Closed");
    
        delay(500);
      }
    }

    Programming note: This is an educational prototype rather than a clinically validated dispenser. The example uses illustrative reminder times, a single active reminder state and a basic sensor interaction. A complete multi-compartment implementation needs persistent event logging, per-dose state tracking, schedule configuration, power-failure recovery, duplicate-alert prevention and mechanical interlocks. Sensor detection or button confirmation must never be interpreted as proof that medication was swallowed.

    9. Designing the Multi-Compartment Dispensing Mechanism

    The mechanical section is one of the most important parts of the project.

    A rotating compartment system can be constructed using a circular medication storage container divided into several sections.

    Automatic pill dispenser by Shaztech.info MakerWorld: Download Free 3D Models
    Automatic Medication Dispenser : 5 Steps - Instructables
    DoseRight: ESP32 Smart Automatic Medicine Dispenser
    Final Project: Indispensable Pill Case - Griffin van Horne - Fab Academy
    Pill Dispenser : 8 Steps - Instructables
    Automatic Pill or Medication Dispenser : 7 Steps (with Pictures) - Instructables
    Automatic Pill or Medication Dispenser : 7 Steps (with Pictures) - Instructables
    One Click weekly pill dispenser V2.0 by Rober7Crow MakerWorld: Download Free 3D Models
    Automatic pill dispenser by Shaztech.info MakerWorld: Download Free 3D Models
    Sound Dose | صوت الجرعة - SD-100 Smart Medication Dispenser
    Final Project: Indispensable Pill Case - Griffin van Horne - Fab Academy
    Automated Pill Dispenser 756x630
    Smart Pill Dispenser | DeepSea
    Supplement Dispenser / Pill Dispenser by Konrad MakerWorld: Download Free 3D Models
    PILLBOX 7 day   - Pilulier 7 jour by mat64680 MakerWorld: Download Free 3D Models
    基于AIR32单片机的智能药盒 - 立创开源硬件平台
    Pill Organizer Adhd - Etsy
    Pill Dispenser for elder :: Behance

    Construction procedure

    • Obtain a circular plastic container.
    • Divide the container into separate medication compartments.
    • Label each compartment according to its programmed schedule.
    • Attach a rotating platform to the servo mechanism.
    • Design an outlet through which the selected compartment can be accessed.
    • Mount the servo securely beneath the rotating platform.
    • Position the IR sensor near the collection outlet.
    • Connect the mechanism to the ESP32 controller.

    For a more advanced design, a stepper motor can replace the servo to provide more precise compartment positioning.

    The physical design should prevent access to other compartments and prevent accidental release of multiple compartments.

    10. IoT Dashboard and Caregiver Notification System

    One of the major advantages of this project is its ability to communicate with caregivers remotely.

    The ESP32 connects to Wi-Fi and sends event notifications through Blynk.

    How to Improve Medication Adherence: A Patient's Guide | Patient Talker Blog

    The dashboard can be designed to display:

    Dashboard featureFunction
    Next reminderDisplays upcoming scheduled reminder
    Reminder statusShows whether a reminder is active
    Collection statusShows detected or unconfirmed interaction
    Missed reminder alertNotifies caregiver
    Device statusIndicates whether the ESP32 is connected
    Event historyRecords reminder and interaction events

    The caregiver can receive notifications when the device detects an unconfirmed medication collection event.

    The system should distinguish between a missed reminder, an unconfirmed collection and a confirmed user interaction.

    11. Possible Project Improvements

    Mainlogix Canada | IoT and Automation Solutions

    The project can be upgraded in several ways.

    A. Voice Reminder Integration

    Add a speaker module to provide spoken medication reminders.

    B. GSM Notification System

    Integrate a GSM module to send SMS notifications when Wi-Fi connectivity is unavailable.

    C. Fingerprint Authentication

    Add a fingerprint sensor to restrict access to authorized users.

    D. Load Cell Integration

    Use a load cell and HX711 amplifier to detect changes in compartment weight. This can provide additional evidence of medication removal, although it cannot confirm ingestion.

    E. Battery Backup

    Add a rechargeable battery and charging circuit to maintain operation during power interruptions.

    F. Cloud-Based Medication History

    Store reminder events and collection interactions in a cloud database for authorized caregiver access.

    12. Applications of the Project

    The Smart Multi-Dose Medication Adherence Dispenser can be applied in several healthcare and home-care environments.

    • Chronic Care Management: Supports medication routines for people requiring long-term treatment.
    • Elderly Care: Helps older adults organize scheduled medication reminders.
    • Home Healthcare: Allows family members to monitor reminder and collection events.
    • Assisted Living Facilities: Supports organized medication reminder routines.
    • Rehabilitation Centres: Helps manage scheduled medication reminders.
    • Remote Healthcare: Enables caregivers to receive device notifications remotely.

    13. Advantages of the System

    • Automates medication reminders.
    • Organizes multiple medication compartments.
    • Reduces dependence on manual reminders.
    • Provides audible and visual alerts.
    • Supports caregiver notifications.
    • Maintains scheduled time using an RTC module.
    • Provides an opportunity for remote monitoring.
    • Can be expanded using artificial intelligence and cloud computing.

    14. Limitations and Safety Considerations

    Despite its potential, the project has some limitations.

    ChallengePossible solution
    Power failureInstall battery backup
    Wi-Fi disconnectionAdd GSM notification
    Servo malfunctionIntroduce position feedback
    Incorrect sensor detectionUse multiple confirmation methods
    Incorrect schedule configurationProvide caregiver-controlled settings
    Medication compartment mix-upUse clearly labelled and secured compartments

    Important healthcare safety consideration: This project is intended for educational prototyping and medication-reminder support. It must not independently determine medication dosages, change prescriptions, recommend taking missed doses or release extra medication following a missed reminder. Actual medication dispensing requires professional validation, secure mechanical design, appropriate supervision and safeguards against medication errors. Collection detection does not prove ingestion.

    15. Conclusion

    The Smart Multi-Dose Medication Adherence Dispenser with Missed-Dose Alerting for Chronic Care demonstrates how electronics, automation and IoT technology can contribute to improved medication management.

    By integrating an ESP32 microcontroller, RTC module, servo motor, sensors and wireless communication, the project provides an intelligent platform for scheduled reminders, compartment access monitoring and caregiver notifications.

    Its ability to distinguish between scheduled reminders and unconfirmed collection interactions makes it a promising concept for supporting chronic care routines.

    The project also provides an excellent opportunity for students, innovators and STEM researchers to explore the application of embedded systems in healthcare technology.

    mbeva

    Dominic Mbeva is a science teacher, experienced researcher, innovator, and creative technologist with expertise in STEM education, digital media, and scientific research. As a Kenya Science and Engineering Fair (KSEF) advisor and projects manager, he mentors young scientists, guiding them in developing award-winning innovations. He is also an IC Technorat, leading advancements in science and technology. Beyond education, Dominic is a skilled photographer and video editor, using visual storytelling to make science more engaging. His philosophy, “If you take care of minutes, hours will take care of themselves,” reflects his belief in consistent effort, strategic thinking, and innovation to drive success in both research and creativity.

    Related Posts

    KSEF Nationals 2026 Food Technology Results: Top 10 Projects, Winning Schools and Best Innovation Ideas for 2027

    Introduction The Kenya Science and Engineering Fair (KSEF) Nationals 2026 showcased impressive creativity and scientific innovation among Senior School learners participating in the Food Technology category. The final ranking report…

    Read more

    KSEF Nationals 2026 Biology Results: Top 10 Senior School Projects, Winners and Best Ideas for 2027

    The 2026 Kenya Science and Engineering Fair (KSEF) Nationals Biology Senior School competition has showcased outstanding scientific creativity, with students presenting innovative projects addressing agriculture, healthcare, environmental conservation, biotechnology and…

    Read more

    Leave a Reply

    Your email address will not be published. Required fields are marked *