folder Project Ideas
• • 14 min read • visibility 0 readers

Build a Smart Medicine Reminder Box with Arduino – Automatic Pill Dispenser & Alert System

A
Anil Gupta
Technical Specialists & Component Engineers
Share: chat share
timer
Read Time
14 Mins
category
Category
Project Ideas
verified
Verified Guide
100% Genuine
inventory_2
Project Kit
18 Parts
Build a Smart Medicine Reminder Box with Arduino – Automatic Pill Dispenser & Alert System
Build a smart medicine reminder box with Arduino, RTC module & servo motor. Buzzer & LED alerts remind you to take pills on time. Full guide, code & BOM!

Introduction

Forgetting to take medicine on time is one of the most common — and most dangerous — health mistakes people make. Whether it's a daily vitamin, a blood pressure tablet, or a critical prescription drug, missing a dose or taking medicine at the wrong time can have serious consequences. This is especially true for elderly patients, children, and anyone managing multiple medications.

In this project, we'll build a Smart Medicine Reminder Box using an Arduino Uno, a DS3231 Real Time Clock (RTC) module, a servo motor to dispense medicine from a rotating compartment tray, a 16×2 LCD display showing current time and next dose schedule, and a buzzer with LED alert that activates at programmed medication times.

This is an outstanding project for college final year projects, healthcare IoT, elderly care systems, hospital automation demonstrations, and biomedical engineering coursework. It is a genuinely useful device that can be built for under ₹1,500 using components available at Anil Electronic Store, Ahmedabad.

What You'll Build

  • A rotating pill dispenser tray with up to 4 compartments — one per dose time
  • DS3231 RTC module keeping accurate time even during power cuts
  • Programmable alarm times for up to 4 daily doses (Morning, Afternoon, Evening, Night)
  • Buzzer alarm + Red LED alert at each programmed medication time
  • Servo motor rotates the tray to present the correct compartment at each alarm
  • 16×2 LCD showing current time, date, and next scheduled dose
  • Green LED confirmation when medicine is taken (button press)
  • Missed dose detection — escalated buzzer if medicine not taken within 5 minutes
  • Total build time: ~2 hours

How It Works

The system works in a precise time-driven cycle managed entirely by the DS3231 RTC module:

  1. Timekeeping: The DS3231 RTC module maintains accurate time independently of the Arduino — even when power is removed, its onboard CR2032 coin cell battery keeps the clock running. This guarantees the reminder system never loses time during power cuts or restarts.
  2. Alarm checking: Every 30 seconds, the Arduino reads the current hour and minute from the DS3231 via I2C. It compares this against up to 4 programmed dose times stored in the code.
  3. Dose alert: When the current time matches a programmed dose time, the system activates — buzzer beeps, red LED flashes, and the LCD displays "Time for Medicine! — Dose 1" (or whichever dose is due).
  4. Tray rotation: The SG90 servo motor rotates the pill tray to present the correct compartment opening (Dose 1 at 0°, Dose 2 at 90°, Dose 3 at 180°, Dose 4 at 270° for a 4-slot tray).
  5. Acknowledgement: The user presses the confirmation button to acknowledge the dose taken. Green LED lights up, buzzer stops, and the LCD shows "Dose Taken ✓ Next: 14:00". The system then waits for the next scheduled dose.
  6. Missed dose escalation: If the button is not pressed within 5 minutes of the alarm, the buzzer escalates to continuous beeping until acknowledged — ensuring no dose is silently missed.

Why DS3231 for Accurate Timekeeping?

The DS3231 is a precision, temperature-compensated Real Time Clock IC that maintains exceptional accuracy of ±2 minutes per year — far better than software-based timekeeping in Arduino. Key advantages for this project:

  • ✅ Keeps time during power cuts — onboard CR2032 battery backup
  • ✅ Temperature-compensated oscillator — accurate across Indian climate conditions
  • ✅ I2C interface — only 2 wires (SDA + SCL) needed alongside Arduino's existing I2C bus
  • ✅ Built-in alarm registers — can trigger interrupts at programmed times
  • ✅ Onboard AT24C32 EEPROM — can store patient name, dose history, or doctor's notes

⚠️ Important first-time setup: When you first use a DS3231 module, you need to set the current time by running a one-time time-setting sketch before uploading the main medicine reminder code. Instructions are included in the code section below.

Components Required (BOM)

All components are in stock at anilestore.com with same-day dispatch before 2 PM. See the kit panel on this page to add everything in one click.

Circuit Connections

DS3231 RTC Module → Arduino Uno (I2C):

  • VCC → 5V
  • GND → GND
  • SDA → A4
  • SCL → A5

SG90 Servo Motor (Pill Tray Rotation) → Arduino Uno:

  • Red (VCC) → 5V
  • Brown (GND) → GND
  • Orange (Signal) → D6 (PWM)

16×2 I2C LCD Display → Arduino Uno:

  • VCC → 5V
  • GND → GND
  • SDA → A4 (shared I2C bus with DS3231)
  • SCL → A5 (shared I2C bus with DS3231)

Active Buzzer → Arduino Uno:

  • Positive → D8
  • Negative → GND

Red LED (Alarm / Reminder Alert) → Arduino Uno:

  • Anode (+) → D9 via 220Ω resistor
  • Cathode (–) → GND

Green LED (Dose Taken Confirmation) → Arduino Uno:

  • Anode (+) → D10 via 220Ω resistor
  • Cathode (–) → GND

Confirmation Button (Dose Taken) → Arduino Uno:

  • One leg → D7
  • Other leg → GND
  • Use internal pull-up: pinMode(7, INPUT_PULLUP)
  • No external resistor needed

Power:

  • Power via USB adapter or 9V battery snap to Arduino barrel jack
  • DS3231 coin cell battery (CR2032) maintains time when main power is off
  • For 24/7 operation plug into USB wall adapter — the system runs continuously

⚠️ Note on shared I2C bus: The DS3231 RTC and I2C LCD both use the same SDA (A4) and SCL (A5) lines — this is perfectly fine. I2C is a multi-device bus. Each device has a unique address (DS3231 = 0x68, LCD = 0x27) so they do not conflict. Simply connect both devices' SDA to A4 and SCL to A5 in parallel.

Required Libraries

Install via Arduino IDE → Sketch → Include Library → Manage Libraries:

  • RTClib by Adafruit — search "RTClib" — for DS3231 real time clock
  • LiquidCrystal_I2C by Frank de Brabander — search "LiquidCrystal I2C"
  • Servo — built into Arduino IDE, no installation needed
  • Wire — built into Arduino IDE, no installation needed

Step 1 — Set the RTC Time (Run Once)

Before uploading the main code, run this one-time time-setting sketch to synchronise the DS3231 with the current date and time. Upload it, wait 10 seconds, then upload the main code:


// DS3231 Time Setting Sketch — Run ONCE then upload main code
// Anil Electronic Store – anilestore.com

#include <Wire.h>
#include <RTClib.h>

RTC_DS3231 rtc;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

  // SET DATE AND TIME HERE — format: Year, Month, Day, Hour, Minute, Second
  // Use 24-hour format for hours
  rtc.adjust(DateTime(2026, 12, 1, 9, 0, 0));
  // Example above sets: 1st December 2026, 09:00:00

  Serial.println("RTC time set successfully!");
}

void loop() {
  DateTime now = rtc.now();
  Serial.print(now.day()); Serial.print("/");
  Serial.print(now.month()); Serial.print("/");
  Serial.print(now.year()); Serial.print(" ");
  Serial.print(now.hour()); Serial.print(":");
  Serial.print(now.minute()); Serial.print(":");
  Serial.println(now.second());
  delay(1000);
}

Step 2 — Main Medicine Reminder Code


// Smart Medicine Reminder Box
// Arduino Uno + DS3231 RTC + SG90 Servo + LCD + Buzzer + LEDs + Button
// Anil Electronic Store – anilestore.com

#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo pillServo;

// ===== PIN DEFINITIONS =====
#define SERVO_PIN   6
#define BUZZER_PIN  8
#define RED_LED     9
#define GREEN_LED   10
#define BTN_PIN     7

// ===== DOSE SCHEDULE =====
// Set up to 4 dose times — Hour and Minute in 24-hour format
// Dose 1: Morning   | Dose 2: Afternoon | Dose 3: Evening | Dose 4: Night
const int doseHour[4]   = {8,  13, 18, 22};
const int doseMinute[4] = {0,  0,  0,  0};
const String doseName[4] = {"Morning", "Afternoon", "Evening", "Night"};

// Servo angles for each of 4 tray compartments
const int trayAngle[4] = {0, 90, 180, 270};

// ===== TIMING =====
const int MISSED_TIMEOUT = 300; // seconds — 5 minutes before escalation
const int SNOOZE_TIME    = 120; // seconds — snooze duration

// ===== STATE VARIABLES =====
bool alarmActive    = false;
bool doseTaken      = false;
int  currentDose    = -1;
unsigned long alarmStartTime = 0;
unsigned long lastCheck      = 0;

void buzzPattern(int times, int onMs, int offMs) {
  for (int i = 0; i < times; i++) {
    digitalWrite(BUZZER_PIN, HIGH); delay(onMs);
    digitalWrite(BUZZER_PIN, LOW);  delay(offMs);
  }
}

void showLCD(String line1, String line2) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(line1);
  lcd.setCursor(0, 1);
  lcd.print(line2);
}

String formatTime(int h, int m) {
  String s = "";
  if (h < 10) s += "0";
  s += String(h) + ":";
  if (m < 10) s += "0";
  s += String(m);
  return s;
}

int getNextDose(int currentHour, int currentMin) {
  for (int i = 0; i < 4; i++) {
    if (doseHour[i] > currentHour ||
       (doseHour[i] == currentHour && doseMinute[i] > currentMin)) {
      return i;
    }
  }
  return 0; // Wrap around to first dose next day
}

void triggerAlarm(int doseIndex) {
  currentDose   = doseIndex;
  alarmActive   = true;
  doseTaken     = false;
  alarmStartTime = millis();

  Serial.println("ALARM! Time for " + doseName[doseIndex] + " dose!");

  // Rotate tray to correct compartment
  pillServo.write(trayAngle[doseIndex]);
  delay(800);

  // Alert
  digitalWrite(RED_LED, HIGH);
  buzzPattern(3, 300, 150);

  showLCD("Take Medicine!",
          doseName[doseIndex] + " Dose");
}

void acknowledgeDose() {
  alarmActive = false;
  doseTaken   = true;

  digitalWrite(RED_LED,   LOW);
  digitalWrite(GREEN_LED, HIGH);
  buzzPattern(2, 100, 80);

  int nextDose = getNextDose(doseHour[currentDose], doseMinute[currentDose] + 1);
  showLCD("Dose Taken!",
          "Next: " + formatTime(doseHour[nextDose], doseMinute[nextDose]));

  Serial.println("Dose acknowledged. Next dose at " +
                  formatTime(doseHour[nextDose], doseMinute[nextDose]));

  delay(3000);
  digitalWrite(GREEN_LED, LOW);
}

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!rtc.begin()) {
    Serial.println("DS3231 RTC not found! Check wiring.");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power — please set time using the time-setting sketch.");
  }

  pillServo.attach(SERVO_PIN);
  pillServo.write(0); // Start at Dose 1 position

  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RED_LED,    OUTPUT);
  pinMode(GREEN_LED,  OUTPUT);
  pinMode(BTN_PIN,    INPUT_PULLUP);

  lcd.init();
  lcd.backlight();
  showLCD("Medicine Box", "Starting...");
  delay(2000);

  // Boot confirmation
  buzzPattern(1, 200, 0);
  digitalWrite(GREEN_LED, HIGH);
  delay(500);
  digitalWrite(GREEN_LED, LOW);

  Serial.println("Smart Medicine Reminder Box Ready.");
}

void loop() {
  DateTime now = rtc.now();
  int currentHour = now.hour();
  int currentMin  = now.minute();
  int currentSec  = now.second();

  // ===== CHECK FOR DOSE TIME (every 30 seconds) =====
  if (millis() - lastCheck >= 30000) {
    lastCheck = millis();

    for (int i = 0; i < 4; i++) {
      if (currentHour == doseHour[i] &&
          currentMin  == doseMinute[i] &&
          !alarmActive) {
        triggerAlarm(i);
        break;
      }
    }
  }

  // ===== ACTIVE ALARM HANDLING =====
  if (alarmActive) {
    // Check button press — dose acknowledged
    if (digitalRead(BTN_PIN) == LOW) {
      delay(50); // Debounce
      if (digitalRead(BTN_PIN) == LOW) {
        acknowledgeDose();
        delay(500);
      }
    }

    // Escalation — if not acknowledged within 5 minutes
    unsigned long elapsed = (millis() - alarmStartTime) / 1000;
    if (elapsed >= MISSED_TIMEOUT && !doseTaken) {
      // Continuous rapid beeping — MISSED DOSE
      showLCD("MISSED DOSE!", doseName[currentDose]);
      digitalWrite(RED_LED, HIGH);
      buzzPattern(5, 500, 100);
      Serial.println("MISSED DOSE ALERT! " + doseName[currentDose] + " not taken.");
    } else {
      // Repeating reminder every 60 seconds while alarm active
      if (elapsed % 60 == 0 && elapsed > 0) {
        buzzPattern(2, 300, 150);
        showLCD("Take Medicine!", doseName[currentDose] + " Dose");
        digitalWrite(RED_LED, HIGH);
      }
    }
  }

  // ===== NORMAL DISPLAY — show time and next dose =====
  if (!alarmActive) {
    int nextDose = getNextDose(currentHour, currentMin);
    String timeStr = formatTime(currentHour, currentMin);
    String nextStr = "Next:" + formatTime(doseHour[nextDose], doseMinute[nextDose]);

    lcd.setCursor(0, 0);
    lcd.print("Time: " + timeStr + "  ");
    lcd.setCursor(0, 1);
    lcd.print(nextStr + " " + doseName[nextDose].substring(0, 3));
  }

  delay(1000);
}

Customising Your Dose Schedule

Changing medication times is straightforward — just edit these four lines at the top of the main code:


const int doseHour[4]   = {8,  13, 18, 22};
const int doseMinute[4] = {0,  0,  0,  0};

This sets doses at 08:00, 13:00, 18:00, and 22:00. To change to 07:30, 12:00, 19:00, 23:30 for example:


const int doseHour[4]   = {7,  12, 19, 23};
const int doseMinute[4] = {30, 0,  0,  30};

If you only need 2 doses per day (morning and night), simply set the other two dose times to {0, 0} and they will never trigger during normal hours.

Building the Pill Tray

The rotating pill tray is the heart of this project's physical design. Here's how to build one:

  1. Base disc: Cut a circular disc of cardboard or thin acrylic approximately 12 cm in diameter. Divide it into 4 equal quadrants (each 90°) using dividers cut from cardboard strips glued vertically — these form the 4 pill compartments.
  2. Centre mount: Glue the SG90 servo horn to the exact centre bottom of the disc. The servo body sits stationary below the disc, mounted on a base plate, while the disc (tray) rotates on top.
  3. Label compartments: Label each quadrant: Dose 1 – Morning (0°), Dose 2 – Afternoon (90°), Dose 3 – Evening (180°), Dose 4 – Night (270°).
  4. Dispensing window: Cut a rectangular opening in the cover above the tray — only one compartment is visible at a time through this window. When the servo rotates, the correct compartment aligns with the window.
  5. Box enclosure: Place the entire pill tray assembly inside a box or enclosure with the dispensing window cut in the top lid. The Arduino, breadboard, LCD, and buzzer can be mounted on the front or sides.

Step-by-Step Assembly

  1. Upload the time-setting sketch first. Wire the DS3231 to the Arduino (SDA → A4, SCL → A5, VCC → 5V, GND → GND). Edit the date and time in the sketch, upload, and confirm correct time in Serial Monitor.
  2. Wire all components as per the circuit connections above. The I2C bus (A4, A5) is shared between the DS3231 and LCD — connect both in parallel to the same pins.
  3. Wire the servo to D6, red to 5V, brown to GND. Mount the servo in the base of the pill tray assembly.
  4. Wire the confirmation button between D7 and GND. The internal pull-up resistor handles the rest — no external resistor needed.
  5. Fill the pill compartments with actual tablets or dummy pills for testing.
  6. Upload the main medicine reminder code after editing dose times to your schedule.
  7. Test all dose times by temporarily setting a dose time 1–2 minutes from the current time. Verify the buzzer sounds, red LED flashes, servo rotates to the correct compartment, and the button press acknowledgement works correctly.
  8. Reset dose times to your actual medication schedule, upload again, and the system is ready for 24/7 operation.

Troubleshooting Tips

  • RTC not found / time is wrong after power cut: Ensure the CR2032 coin cell battery is properly seated in the DS3231 module's battery holder. Check SDA/SCL wiring. If rtc.lostPower() returns true, re-run the time-setting sketch.
  • Alarm triggers at wrong time: Verify the time was set correctly using the time-setting sketch. Check the Serial Monitor output at startup — it prints the current RTC time. Confirm 24-hour format is used (e.g., 18 for 6 PM, not 6).
  • Servo doesn't reach correct angle: The SG90 servo has a maximum rotation of 180°. For 4 compartments (0°, 90°, 180°, 270°), you need a servo with 270° or 360° rotation range. Alternatively use 3 compartments (0°, 90°, 180°) with a standard SG90, or use the TowerPro MG90S 360-degree continuous rotation servo with a stepper-style position control.
  • LCD shows garbled text: Run I2C scanner to find LCD address (0x27 or 0x3F). Adjust contrast potentiometer on the back of the I2C module with a small screwdriver.
  • Button press not registering: Verify pinMode(BTN_PIN, INPUT_PULLUP) is in setup(). Check the button is wired between D7 and GND — not D7 and 5V. With INPUT_PULLUP, pressing connects D7 to GND, reading LOW.
  • Alarm not triggering: The alarm check runs every 30 seconds. If the dose time passes within a 30-second window without being checked, it may be missed. Reduce the check interval to 5000 (5 seconds) for more precise triggering during testing.

Upgrades & Next Steps

  • Add a NodeMCU ESP8266 alongside the Arduino to send a WhatsApp or Telegram message to a family member's phone when a dose alarm triggers or is missed
  • Use the DS3231's built-in EEPROM (AT24C32) to log dose taken / missed history with timestamps — download weekly compliance reports via Serial Monitor
  • Add a fingerprint sensor (AS608) to ensure only the authorised patient can acknowledge the dose — prevents caregivers or children from accidentally dismissing alarms
  • Add a small load cell (HX711) under the pill tray to detect if a pill was actually removed when the compartment opened — true dose verification
  • Use an OLED display instead of LCD for a modern interface showing medication name, dose strength, doctor's instructions, and a pie chart of weekly compliance
  • Add a 4×4 keypad to allow users to input and change dose times without re-uploading code — no laptop needed after setup
  • Upgrade to Raspberry Pi for a full-featured medicine management system with touchscreen, patient profile database, and prescription photo storage

Real-World Applications

  • 👴 Elderly care at home — ensure grandparents never miss critical medications
  • 🏥 Hospital patient rooms — automated bedside pill dispensing with nurse notification
  • 👶 Children's medicine schedule — parents get reminded for fever medicine, vitamins, antibiotics
  • 💊 Chronic disease management — diabetes, hypertension, thyroid — multiple daily doses managed automatically
  • 🏠 Smart home health integration — connect to Home Assistant for complete household health monitoring
  • 🔬 Clinical trials — ensure trial participants take medication at precise times for valid research data
  • 🏫 School health rooms — manage daily medication for students with chronic conditions

Why This Project Wins at Exhibitions

  • ✅ Universally relatable — everyone understands the problem of forgetting medicine. No explanation needed.
  • ✅ Live and dramatic demo — set a dose time 1 minute away, let it trigger during the presentation. Judges love seeing the buzzer, rotating tray, and LCD all working together.
  • ✅ Healthcare theme — connects directly to digital health, elderly care, and biomedical IoT — high-impact themes at all engineering fairs
  • ✅ Missed dose alert — the escalating alarm demonstrates real safety engineering thinking
  • ✅ Clear upgrade path — IoT notifications, fingerprint verification, compliance logging — shows depth of thinking
  • ✅ Under ₹1,500 total — affordable to build a clean, well-labelled, enclosure-mounted final product

Why Buy from Anil Electronic Store?

  • ✅ Genuine DS3231 RTC modules — with AT24C32 EEPROM and CR2032 battery pre-installed, accurate to ±2 minutes/year
  • ✅ Quality SG90 servo motors — smooth, consistent rotation critical for reliable tray positioning
  • ✅ I2C LCD modules — with adjustable contrast and backlight, works out of the box with LiquidCrystal_I2C library
  • 🚚 Same-day dispatch for orders placed before 2 PM from Ahmedabad
  • 🧾 Official GST invoice — perfect for college project budget reimbursements
  • 📲 Free WhatsApp engineer support — we help with RTC time setting, servo calibration, and code debugging
  • 📦 Delivery across 19,000+ PIN codes in India

Conclusion

The Smart Medicine Reminder Box is one of the most meaningful and genuinely impactful Arduino projects you can build. Unlike many electronics projects that are purely demonstrative, this one solves a real, daily healthcare problem — and can be deployed immediately to help an elderly family member, a patient managing chronic illness, or anyone who struggles to maintain a medication schedule.

By combining precision real-time clock, automated pill dispensing, multi-level alerts, and acknowledgement confirmation, this project showcases the full potential of embedded systems in healthcare — and it's built entirely from affordable, accessible components available at Anil Electronic Store.

All parts in the BOM are 100% genuine, tested, and in stock. Order before 2 PM for same-day dispatch across 19,000+ PIN codes in India. Build the box. Set the schedule. Never miss a dose again. 💊⏰⚡

precision_manufacturing
Project BOM Bill of Materials

Build This Project Kit

Kit Total ( parts):
₹

Everything required to build this project. Uncheck any parts you already own, then click Buy Project Kit & Checkout to order everything in 1 click!

local_shipping Free Shipping over ₹2,000 · Fast Pan-India Delivery
Topics: #smart medicine reminder arduino #automatic pill dispenser arduino #DS3231 RTC arduino project #medicine alarm system arduino india #healthcare IoT project #buy DS3231 RTC module ahmedabad #medicine box arduino college project
Found this helpful? Share with fellow engineers, makers, and students.
AE
Written by Store Specialists

Anil Electronic Store Technical Team

Based in Odhav, Ahmedabad, we provide genuine electronic components, Arduino boards, robotics hardware, and industrial automation parts across India.

visibility 0 readers
home Home grid_view Shop
shopping_cart
Cart
person Login