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. | Component | Quantity | Purpose |
|---|---|---|---|
| 1 | ESP32 DevKit | 1 | Main microcontroller |
| 2 | DS3231 RTC module | 1 | Accurate timekeeping |
| 3 | SG90 servo motor | 1 | Controls compartment access |
| 4 | 16×2 LCD with I2C | 1 | Displays reminders |
| 5 | Push buttons | 3–4 | User interaction |
| 6 | Buzzer | 1 | Audible reminders |
| 7 | LEDs | 3 | Visual status indication |
| 8 | IR sensor | 1 | Detects collection activity |
| 9 | Medication storage compartments | 1 set | Stores scheduled doses |
| 10 | Resistors | As required | Circuit protection |
| 11 | Jumper wires | As required | Electrical connections |
| 12 | Power supply | 1 | Powers the system |
| 13 | Enclosure | 1 | Houses 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.
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.
Pin connection table
| Component | ESP32 connection |
|---|---|
| DS3231 SDA | GPIO 21 |
| DS3231 SCL | GPIO 22 |
| DS3231 VCC | 3.3V |
| DS3231 GND | GND |
| LCD SDA | GPIO 21 |
| LCD SCL | GPIO 22 |
| Servo signal | GPIO 18 |
| IR sensor OUT | GPIO 19 |
| Buzzer positive | GPIO 23 |
| Green LED | GPIO 25 |
| Red LED | GPIO 26 |
| Confirmation button | GPIO 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.
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.
The dashboard can be designed to display:
| Dashboard feature | Function |
|---|---|
| Next reminder | Displays upcoming scheduled reminder |
| Reminder status | Shows whether a reminder is active |
| Collection status | Shows detected or unconfirmed interaction |
| Missed reminder alert | Notifies caregiver |
| Device status | Indicates whether the ESP32 is connected |
| Event history | Records 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
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.
| Challenge | Possible solution |
|---|---|
| Power failure | Install battery backup |
| Wi-Fi disconnection | Add GSM notification |
| Servo malfunction | Introduce position feedback |
| Incorrect sensor detection | Use multiple confirmation methods |
| Incorrect schedule configuration | Provide caregiver-controlled settings |
| Medication compartment mix-up | Use 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.









