Arduino-Based Automatic Pill Dispenser Machine with LCD Display, Servo Motor and Buzzer Reminder

Automatic Pill Dispenser Machine – Arduino UNO + RTC + Servo | MakeMindz
💊 Healthcare Automation Project

Automatic Pill Dispenser
Machine with Arduino

Smart medication management system using Arduino UNO, DS3231 RTC, servo motor and I2C LCD. Dispenses pills at scheduled times with buzzer reminders — designed for elderly care, clinics and home health monitoring.

⏰ DS3231 RTC ⚙️ Servo Motor 📟 I2C LCD 16×2 🔔 Buzzer Alert 🔘 Push Buttons 🏥 Healthcare IoT
01 — Overview

Project Overview

The Automatic Pill Dispenser Machine is a smart medication management system that dispenses tablets at user-programmed times with audio-visual alerts. Built on Arduino UNO with a DS3231 Real-Time Clock for accurate scheduling, the system uses a servo motor to physically release pills from a compartment while an I2C LCD and buzzer notify the user.

This project is practical for elderly patients, individuals with chronic conditions, and healthcare facilities. It can be further extended with GSM alerts, mobile app integration and cloud-based health tracking.

🏆

What makes it special: The DS3231 RTC maintains accurate time even during power interruptions, ensuring the dispenser never misses a dose schedule — critical for real-world medical applications.


02 — Features

Key Features

RTC Scheduling

DS3231 RTC maintains time through power cuts for reliable dose scheduling.

⚙️

Servo Dispensing

PWM-controlled servo rotates to release pills from the compartment automatically.

📟

I2C LCD Status

16×2 display shows current time, set dose time and dispensing messages.

🔔

Buzzer Alert

1 kHz tone reminds the user when medication is dispensed.

🔘

Button Interface

3 push buttons set hour, minute and confirm dose schedule without a screen keyboard.

🔒

Repeat Protection

alarmSet flag prevents re-triggering within the same scheduled minute.

📡

IoT Expandable

Designed for upgrade with GSM, Wi-Fi or cloud health monitoring modules.

🏥

Healthcare Ready

Reliable for elderly care, hospitals, home monitoring and chronic condition management.


03 – Hardware

Components Required

Arduino UNO – ATmega328P main controller
DS3231 RTC Module – Accurate real-time clock with battery backup
Servo Motor (SG90) – Controls pill dispensing mechanism
I2C 16×2 LCD Display – Status and time display (address 0x27)
Active Buzzer – Medication reminder alert
Push Button × 3 – Set Hour, Set Minute, Confirm
10kΩ Resistors × 3 – Button pull-up resistors (or use INPUT_PULLUP)
Breadboard & Jumper Wires – Circuit connections
5V Power Supply – USB or external adapter
Pill Storage Compartment – Physical container attached to servo
⚠️

RTC Battery: The DS3231 requires a CR2032 coin cell to maintain time during power cuts. Without it, the scheduled dose time resets on every power cycle. Always install the backup battery before deployment.


04 — Wiring

Circuit Connections

ComponentPin / SignalArduino UNO PinNotes
LCD SDAI2C DataA4 (SDA)I2C shared bus
LCD SCLI2C ClockA5 (SCL)I2C shared bus
LCD VCCPower5V
LCD GNDGroundGND
RTC SDAI2C DataA4 (SDA)Shares I2C bus with LCD
RTC SCLI2C ClockA5 (SCL)Shares I2C bus with LCD
RTC VCCPower3.3V or 5V
RTC GNDGroundGND
Servo SignalPWMD9PWM-capable pin
Servo VCCPower5VUse external 5V for real servo
Servo GNDGroundGND
Buzzer +Digital OUTD6Uses tone()
Buzzer −GroundGND
Button SET HOURINPUT_PULLUPD2Press = LOW
Button SET MININPUT_PULLUPD3Press = LOW
Button CONFIRMINPUT_PULLUPD4Press = LOW
💡

I2C shared bus: Both the LCD (0x27) and RTC DS3231 (0x68) share the same A4/A5 I2C lines. This is normal — each device has a unique address. No additional wiring is needed.


06 — Logic

How It Works

Boot

LCD shows splash, components initialise

⏱️

Time Check

RTC polled every loop — current time shown on LCD row 1

🔘

Set Schedule

Buttons increment hour/minute; CONFIRM displays set time

🎯

Match!

RTC hour & minute match schedule → dispensePill() called

💊

Dispense

Buzzer sounds, servo rotates 90°, waits 1s, returns to 0°

Variable / ConstantValuePurpose
setHour8 (default)Scheduled dose hour (0–23)
setMinute0 (default)Scheduled dose minute (0–59)
alarmSetboolPrevents re-trigger within same minute
buttonSetHour (D2)INPUT_PULLUPIncrements setHour (+1 mod 24)
buttonSetMinute (D3)INPUT_PULLUPIncrements setMinute (+1 mod 60)
buttonConfirmTime (D4)INPUT_PULLUPDisplays current schedule on LCD row 2
Servo open position90°Rotates to release pill
Servo closed positionReturns to rest after 1 000 ms
Buzzer frequency1 000 HzAlert tone during dispensing
Button debounce200 ms delayPrevents multiple increments per press

07 — Display

LCD Display Messages

The 16×2 I2C LCD provides real-time feedback across all system states.

Boot splash (2 s)
Smart Pill Dispenser
Normal operation
Time: 08:29:45
CONFIRM button pressed
Time: 08:29:55 Set: 8:0
Dispensing dose
Time: 08:00:01 Dispensing Pill!

08 — Arduino Code

Complete Arduino Sketch

Paste the code below into the Arduino IDE or Wokwi sketch editor. Requires LiquidCrystal_I2C, RTClib and the built-in Servo library.

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

// ── Object Initialisation ──────────────────────────────────
LiquidCrystal_I2C lcd(0x27, 16, 2);  // LCD I2C address 0x27
RTC_DS3231 rtc;
Servo dispenserServo;

// ── Pin Definitions ────────────────────────────────────────
const int buttonSetHour    = 2;   // INPUT_PULLUP – press = LOW
const int buttonSetMinute  = 3;   // INPUT_PULLUP
const int buttonConfirmTime = 4;  // INPUT_PULLUP
const int buzzerPin         = 6;
const int servoPin          = 9;

// ── Scheduling Variables ───────────────────────────────────
int  setHour   = 8;     // Default dose hour (24-h format)
int  setMinute = 0;     // Default dose minute
bool alarmSet  = false; // Prevents re-trigger in same minute

// ── Setup ──────────────────────────────────────────────────
void setup() {
  lcd.begin();
  rtc.begin();
  dispenserServo.attach(servoPin);
  dispenserServo.write(0);          // Start at closed position

  pinMode(buzzerPin,         OUTPUT);
  pinMode(buttonSetHour,     INPUT_PULLUP);
  pinMode(buttonSetMinute,   INPUT_PULLUP);
  pinMode(buttonConfirmTime, INPUT_PULLUP);

  // Splash screen
  lcd.print("Smart Pill");
  lcd.setCursor(0, 1);
  lcd.print("Dispenser");
  delay(2000);
  lcd.clear();
}

// ── Main Loop ──────────────────────────────────────────────
void loop() {
  DateTime now = rtc.now();

  // Row 0: current time
  lcd.setCursor(0, 0);
  lcd.print("Time: ");
  lcd.print(now.hour());
  lcd.print(":");
  if (now.minute() < 10) lcd.print("0");
  lcd.print(now.minute());
  lcd.print(":");
  if (now.second() < 10) lcd.print("0");
  lcd.print(now.second());

  // Check if dose time reached
  if (now.hour() == setHour && now.minute() == setMinute && !alarmSet) {
    dispensePill();
    alarmSet = true;  // Block re-trigger in this minute
  }

  // Reset flag once minute advances
  if (now.minute() != setMinute) alarmSet = false;

  // ── Button Handlers ──────────────────────────────────────
  if (digitalRead(buttonSetHour) == LOW) {
    setHour = (setHour + 1) % 24;
    delay(200);  // Debounce
  }
  if (digitalRead(buttonSetMinute) == LOW) {
    setMinute = (setMinute + 1) % 60;
    delay(200);
  }
  if (digitalRead(buttonConfirmTime) == LOW) {
    lcd.setCursor(0, 1);
    lcd.print("Set: ");
    lcd.print(setHour);
    lcd.print(":");
    if (setMinute < 10) lcd.print("0");
    lcd.print(setMinute);
    lcd.print("  ");  // Clear trailing chars
    delay(500);
  }
}

// ── Dispense Function ─────────────────────────────────────
void dispensePill() {
  lcd.setCursor(0, 1);
  lcd.print("Dispensing Pill!");

  tone(buzzerPin, 1000);         // Sound 1 kHz alert
  dispenserServo.write(90);      // Rotate servo to release pill
  delay(1000);                    // Hold open for 1 second
  dispenserServo.write(0);       // Return to closed position
  noTone(buzzerPin);

  lcd.setCursor(0, 1);
  lcd.print("Dose Completed  ");
  delay(2000);
  lcd.setCursor(0, 1);
  lcd.print("                ");  // Clear row 2
}
📦

Required libraries: Install LiquidCrystal I2C by Frank de Brabander and RTClib by Adafruit via the Arduino Library Manager (Sketch → Include Library → Manage Libraries). The Servo library is built in.


09 — Use Cases

Applications

Elderly Patient Care — Reduces missed doses for seniors living alone
Hospital Automation — Scheduled dispensing in wards and clinics
Home Healthcare — Family-monitored medication management
Chronic Conditions — Diabetes, hypertension, epilepsy dose control
Smart Medical Devices — Prototype for connected health gadgets
IoT Health Reminders — Extendable to SMS/app push notifications
Veterinary Use — Pet medication scheduling
Embedded System Education — Teaching RTC, servo and I2C integration

10 — More Projects

Related Projects

© 2026 MakeMindz · Arduino UNO · DS3231 RTC · Servo Motor · I2C LCD · Healthcare Automation

Comments

try for free