Skip to main content
Version: ACS CC

Automated Pill Dispenser

A sensor-verified automatic medication dispenser with dual stepper motor carousel and shutter mechanism.

info Author: Dinu Alexandra
GitHub Project Link: GitHub Repository

Description

The device dispenses pills from a 7-day rotating carousel according to a preset schedule. A stepper motor rotates the pill box to the correct day, while a second stepper motor controls a shutter disc that opens to release pills by gravity. An IR sensor confirms dispensing, a Hall sensor verifies carousel position, an ultrasonic sensor detects user proximity, and a temperature/humidity sensor monitors storage conditions. The user sets schedules via 3 buttons and an OLED display. A servo motor locks the lid to prevent unauthorized access. All dispensing events are logged to a MicroSD card.

Motivation

Elderly people and patients with complex treatments frequently forget to take their medication on time. Commercial automated dispensers are expensive and often lack verification mechanisms. This project provides an affordable solution that verifies every step of the dispensing process through multiple sensors, monitors storage conditions, and alerts the user through audio and visual feedback — all without requiring internet connectivity.

Architecture

Architecture Diagram The system has three main subsystems connected to the STM32 Nucleo-U545RE-Q:

  • Sensor subsystem — 4 sensors provide feedback: Hall effect (KY-035, ADC) for carousel homing, IR obstacle sensor (GPIO) for pill detection, HTU21D (I2C) for temperature and humidity, HC-SR04P (GPIO) for user proximity detection.
  • Actuator subsystem — 3 actuators control dispensing: Stepper motor 1 + ULN2003 (GPIO×4) rotates the carousel, Stepper motor 2 + ULN2003 (GPIO×4) controls the shutter disc, Servo SG90 (PWM) locks/unlocks the lid.
  • Interface subsystem — OLED SSD1306 display (I2C), DS3231 RTC (I2C) for scheduling, MicroSD card module (SPI) for event logging, active buzzer (PWM) for alarms, 3 push buttons (GPIO) for menu navigation.

All I2C devices (OLED, DS3231, HTU21D) share the same bus on PB6/PB7 with 4.7kΩ pull-up resistors. Communication protocols used: I2C, SPI, GPIO, PWM, ADC.

Log

Week 5 - 11 May

Week 12 - 18 May

Week 19 - 25 May

Hardware

The mechanical assembly uses a commercially available 7-day round pill box mounted upside-down on the first stepper motor's shaft. The compartments face downward onto a fixed base plate. A second stepper motor drives a shutter disc beneath the base — when the shutter hole aligns with the active compartment, pills fall through by gravity into a collection tray. A neodymium magnet glued to the carousel triggers the Hall sensor once per revolution for position calibration. The IR sensor at the dispensing window confirms that pills actually fell through. The entire assembly sits inside a box enclosure containing the breadboard, STM32 Nucleo, battery holder, and all electronics.

Schematics

KiCad Schematic

Bill of Materials

DeviceUsagePrice
STM32 Nucleo-U545RE-QThe microcontrollerProvided by university
OLED Display 0.96" SSD1306 I2CDisplays schedule, status, alerts16.96 RON
DS3231 RTC ModuleReal-time clock for dose scheduling17.98 RON
HTU21D Temp & Humidity SensorMonitors medication storage conditions17.22 RON
Hall Sensor KY-035Carousel homing and position verification4.15 RON
IR Obstacle SensorDetects pills falling through dispensing window3.12 RON
HC-SR04P Ultrasonic SensorDetects user proximity for display wake-up10.14 RON
28BYJ-48 Stepper Motor ×2Rotates carousel and shutter disc20.58 RON
ULN2003 Driver Module ×2Drives the stepper motors9.94 RON
SG90 Servo Motor 180°Locks/unlocks the lid9.49 RON
Active Buzzer 5V ×2Audible alarm for dose reminders2.22 RON
Mini Button 6×6×5mm ×4Menu / Up / Down navigation1.44 RON
MicroSD Card Module SPILogs dispensing events in CSV format~7.00 RON
Breadboard MB102 830ptsPrototyping platform16.66 RON
Breadboard Power SupplyRegulates power to 3.3V and 5V rails6.69 RON
4×AA Battery HolderPower source (6V)6.34 RON
Varta AA Batteries ×8Powers the system13.18 RON
TP4056 Charging ModuleOptional LiPo charging4.72 RON
Resistor Kit 600pcsPull-up resistors for I2C, button pull-downs15.16 RON
Dupont Wires MM 30cm ×40Breadboard connections8.39 RON
Dupont Wires FM 10cm ×40Module-to-breadboard connections7.73 RON
Dupont Wires FF 30cm ×40Module-to-module connections7.59 RON
Neodymium Magnets 5×2mm ×20Position marker on carousel for Hall sensor24.16 RON
7-Day Round Pill BoxCarousel body (7 wedge compartments)3.81 RON

Software

LibraryDescriptionUsage
embassy-stm32HAL and async runtime for STM32GPIO, I2C, SPI, PWM, ADC peripheral access
embassy-executorAsync task executorRuns 6 concurrent tasks: scheduler, motor control, sensors, display, proximity, logging
embassy-timeAsync timers and delaysNon-blocking delays for stepper stepping, sensor polling, alarm timeouts
ssd1306OLED display driverRenders schedule, status pages, and alerts on the 0.96" I2C display
ds323xDS3231 RTC driverReads current time, sets alarm times for dose scheduling
embedded-sdmmcSD card FAT32 filesystem driverWrites timestamped dispensing events to CSV files via SPI
embedded-halHardware abstraction layerStandardized interfaces for GPIO, I2C, SPI, ADC peripherals
defmt + defmt-rttLogging frameworkStructured debug logging via RTT during development
panic-probePanic handlerPrints panic info and backtraces via RTT probe
  1. Embassy-rs — Async framework for embedded Rust
  2. SSD1306 OLED driver crate
  3. DS323x RTC driver crate
  4. Embedded SDMMC crate
  5. PM Rust Course — Lab 01
  6. PM Rust Course — Lab 02
  7. PM Rust Course — Lab 03
  8. 28BYJ-48 Stepper Motor Datasheet
  9. HTU21D Sensor Datasheet