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.
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.
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.
Components Required
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.
Circuit Connections
| Component | Pin / Signal | Arduino UNO Pin | Notes |
|---|---|---|---|
| LCD SDA | I2C Data | A4 (SDA) | I2C shared bus |
| LCD SCL | I2C Clock | A5 (SCL) | I2C shared bus |
| LCD VCC | Power | 5V | |
| LCD GND | Ground | GND | |
| RTC SDA | I2C Data | A4 (SDA) | Shares I2C bus with LCD |
| RTC SCL | I2C Clock | A5 (SCL) | Shares I2C bus with LCD |
| RTC VCC | Power | 3.3V or 5V | |
| RTC GND | Ground | GND | |
| Servo Signal | PWM | D9 | PWM-capable pin |
| Servo VCC | Power | 5V | Use external 5V for real servo |
| Servo GND | Ground | GND | |
| Buzzer + | Digital OUT | D6 | Uses tone() |
| Buzzer − | Ground | GND | |
| Button SET HOUR | INPUT_PULLUP | D2 | Press = LOW |
| Button SET MIN | INPUT_PULLUP | D3 | Press = LOW |
| Button CONFIRM | INPUT_PULLUP | D4 | Press = LOW |
┌──────────────────────────────┐ ┌─────────────────┐ │ Arduino UNO │ │ DS3231 RTC │ │ A4 (SDA) ─────────────────────│ SDA │ │ A5 (SCL) ─────────────────────│ SCL │ │ 3.3V/5V ─────────────────────│ VCC │ │ GND ─────────────────────│ GND │ └──────────────────────────────┘ └─────────────────┘ ┌──────────────────────────────┐ ┌─────────────────┐ │ A4 (SDA) ─────────────────────│ SDA 16×2 LCD │ │ A5 (SCL) ─────────────────────│ SCL │ │ 5V ─────────────────────│ VCC │ │ GND ─────────────────────│ GND │ └──────────────────────────────┘ └─────────────────┘ D9 ────── [SERVO Signal] 5V ────── [SERVO VCC] GND ── [SERVO GND] D6 ────── [BUZZER +] GND ── [BUZZER −] D2 ────── [BTN SET HOUR] D3 ────── [BTN SET MIN] D4 ────── [BTN CONFIRM] (all buttons other side → GND, INPUT_PULLUP enabled)
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.
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 / Constant | Value | Purpose |
|---|---|---|
setHour | 8 (default) | Scheduled dose hour (0–23) |
setMinute | 0 (default) | Scheduled dose minute (0–59) |
alarmSet | bool | Prevents re-trigger within same minute |
buttonSetHour (D2) | INPUT_PULLUP | Increments setHour (+1 mod 24) |
buttonSetMinute (D3) | INPUT_PULLUP | Increments setMinute (+1 mod 60) |
buttonConfirmTime (D4) | INPUT_PULLUP | Displays current schedule on LCD row 2 |
| Servo open position | 90° | Rotates to release pill |
| Servo closed position | 0° | Returns to rest after 1 000 ms |
| Buzzer frequency | 1 000 Hz | Alert tone during dispensing |
| Button debounce | 200 ms delay | Prevents multiple increments per press |
LCD Display Messages
The 16×2 I2C LCD provides real-time feedback across all system states.
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.
#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.
Applications
Related Projects
🌐 IoT & Smart Systems
- 1.IoT Weather Monitoring System (NodeMCU ESP8266 + DHT11)
- 2.ESP8266 Smart Health & Environment Monitoring System
- 3.ESP32 Wi-Fi Weight Sensor with HX711
- 4.Smart RFID Access Control System (ESP32)
- 5.Smart Waste Management System (Arduino Nano + GSM)
- 6.Arduino UNO Smart Surveillance System with ESP8266
- 7.Arduino UNO Smart Home Automation with Flame & IR Sensors
🏭 Industrial / Automation
- 1.★ Automatic Pill Dispenser Machine (This Project)
- 2.Smart Toll Gate Automation with RFID, GSM & LCD
- 3.Smart Water Quality Monitoring (pH + Turbidity)
- 4.Automatic Tire Inflator with Pressure Sensor & LCD
- 5.Automatic Liquid Hand Sanitizer & Soap Dispenser
- 6.Smart Shopping Trolley with RFID Auto Billing
- 7.Robotic Weeding Machine with Ultrasonic Obstacle Detection
- 8.ESP32 Digital Weighing Scale (50 kg Load Cell + HX711)
Comments
Post a Comment