Smart Pill Dispenser With Raspberry Pi and Web App
by MVermote in Circuits > Raspberry Pi
26 Views, 0 Favorites, 0 Comments
Smart Pill Dispenser With Raspberry Pi and Web App
Forgetting to take medication is a common and serious problem, especially for elderly people managing multiple prescriptions. Missed doses can lead to health complications and are one of the main reasons why elderly people can no longer live independently at home.
This project is a smart pill dispenser built around a Raspberry Pi, designed to take the stress out of medication management and help elderly people stay independent in their own home for longer. The dispenser automatically releases pills at scheduled times, shows an alarm if a dose is missed and monitors the temperature and humidity inside the device to ensure medications are stored safely.
Through a web app, caregivers or users can easily set up and adjust medication schedules and track whether pills have been taken. All data is stored in a database, giving a clear history of medication intake over time.
The housing combines a laser-cut wooden enclosure with 3D-printed internal components, resulting in a lightweight design that is easy to move and place wherever it is needed most.
Whether you are caring for an elderly relative or simply want a reliable way to manage daily medication, this project offers a complete, open-source solution you can build yourself.
Supplies
All components together cost approximately €230. Below you find a full overview per category.
Electronics
- 1x Raspberry Pi 5 Model B — €123,99 — Gotron
- 1x Raspberry Pi 40 pins GPIO Extension Kit (T-piece) — €6,50 — Tinytronics
- 1x MCP23017 I2C Port Expander — €4,00 — Tinytronics
- 1x Arduino Power Supply Module 3.3V/5V — €11,99 — Amazon
- 1x LCD 1602 Display — €6,99 — Bol.com
- 1x Button with LED indicator
Sensors
- 1x Infrared Break Beam Sensor — €3,75 — Tinytronics
- 1x IR Pyroelectric Infrared PIR Motion Sensor — €6,49 — Tinytronics
- 1x DHT11 Temperature and Humidity Module — €4,68 — Reichelt
RFID
- 1x RC522 RFID Module Kit — €6,00 — Tinytronics
- 1x RFID S50 Mifare Key Tag — €1,00 — Tinytronics
Motors
- 3x Stepper Motor 28BYJ-48 5V — €2,95/piece — Otronic
- 3x ULN2003A Stepper Motor Driver — €1,60/piece — Otronic
Housing (~€40)
- Laser-cut wooden enclosure
- 3D-printed internal components
3D Printed Components
The internal components of the pill dispenser are 3D printed in PLA. The STL files are available as a downloadable file at the bottom of this step.
Parts to print
- 1x Funnel
- 3x Rotating cylinder with 7 pill compartments
- 3x Lid for each cylinder
Print orientation
All parts must be printed upside down. This ensures a cleaner print and better accuracy for the pill compartments. Make sure to enable supports in your slicer software, as they are required.
Laser Cut Wooden Housing
The housing of the pill dispenser is made from 4mm multiplex, cut using a laser cutter. The design files are available as downloadable files at the bottom of this step.
Cutting the parts
The housing consists of 7 panels, each cut from a 450x600mm sheet of 4mm multiplex. Load the DXF files into your laser cutter software and cut all parts. Make sure to check the settings of your laser cutter for 4mm multiplex before cutting.
Important: cable hole position
In the current design files, the cable hole on the right side panel is too small. I recommend making the hole higher in the design file before cutting, otherwise you will need to cut it manually afterwards as I did.
(Photo of lasercut panels)
Assembly 1
Now that all parts are printed and cut, we can assemble the pill dispenser. Follow the steps below in order.
1. Attach the 3D-printed cylinders to the top panel
Screw the 3 cylinder supports onto the small top panel from below using 2mm screws. Holes are provided in the 3D-printed supports for this purpose.
2. Assemble the wooden housing
Glue the small panels together first, making sure the teeth fit neatly into each other. Once these are dry, glue them onto the base plate.
3. Attach the stepper motors and motor drivers
Glue the stepper motors to the bottom of each cylinder. Make sure the motors are firmly attached to the cylinders, as they need to withstand the rotational force during dispensing. Glue the motor drivers onto the base plate.
4. Attach the Raspberry Pi and breadboard
Glue the Raspberry Pi and breadboard onto the base plate. Make sure to position them correctly so that the power supply cable can reach through the holes provided in the housing.
5. Attach the sensors
Glue the IR break beam sensor into the holes provided in the 3D-printed housing. The sensor fits perfectly into these holes. Glue the PIR motion sensor into the hole provided in the housing. Glue the DHT11 temperature and humidity sensor onto the small top panel. The exact position of the DHT11 does not matter much.
6. Attach the LCD screen and button
Place the LCD screen and the button into the holes provided in the front panel and glue them in place.
7. Attach the RFID scanner
Glue the RFID scanner to the inside of the right panel, aligned with the RFID logo that is engraved on the outside of the panel.
(photo(s) of assembly first part)
Electronics and Soldering
In this step we will solder all the wires and connect the components according to the Fritzing schematic. The Fritzing file is available as a downloadable file at the bottom of this step.
Breadboard
The following components are placed on the breadboard:
- MCP23017 I2C Port Expander
- Potentiometer for LCD contrast adjustment
- Transistor to control the LED button
- Resistors for the transistor circuit
Soldering
Solder all wires to their respective components. Make sure all connections are solid and secure. Make sure all wires are long enough to connect their component to the breadboard.
Connecting the components
Once all wires are soldered, connect everything according to the Fritzing schematic. Double-check all connections before powering on the device.
(Photo electronics + fritzing)
Final Assembly
Now that all electronics are connected, we can close the housing. Follow the steps below in order.
1. Attach the front panel
Glue the front panel onto the base plate and against the small inner panels at the same time. Make sure the button and lcd screen are on the outside of the device.
2. Attach the side panels
Glue the side panels onto the base plate and against the front panel. Make sure the teeth fit neatly into each other. For the right panel make sure the RFID logo is on the outside as well, with the scanner on the inside.
3. Attach the back panel
Glue the back panel onto the base plate and against the side panels.
4. Assemble the lid
Glue the small top panel onto the center of the large lid panel. This forms the removable lid of the dispenser. The lid can be placed on top of the housing and removed whenever you need to refill the pill compartments. Do not glue the lid to the housing itself.
(Photo final assembly)
Set Up Raspberry Pi
Operating System
This project uses a custom Raspberry Pi image provided by Howest MCT. If you are building this project yourself, install Raspberry Pi OS on an SD card of at least 16GB using Raspberry Pi Imager.
Enable I2C, SPI and SSH
Before running the project, make sure to enable I2C, SPI and SSH on your Raspberry Pi. You can do this via:
Navigate to Interface Options and enable I2C, SPI and SSH one by one and reboot your pi using the command:
Clone the repository from my github: https://github.com/howest-mct/2025-2026-projectone-mct-MilanVermote
Create a virtual environment:
Install all required libraries using the requirements.txt file:
Additionally, install the following two libraries manually as they are not yet included in requirements.txt:
Database Setup
This project uses a MariaDB database. The database structure is shown in the ERD below.
Database structure
The database consists of the following tables:
- profiel — stores user information and their RFID tag
- pil — stores medication information
- pilSchema — stores the medication schedule per user
- pilInname — registers when a user has taken their pills
- sensor — stores the sensor types used in the device
- sensorData — stores readings of all sensors
- motor — links each motor to a specific pill
- motorActivatie — logs each time a motor has been activated
Creating the database
Open MySQLWorkbench and connect to your Raspberry Pi via SSH tunnel:
- SSH Hostname: 192.168.168.169
- MySQL Username: root
- MySQL Password: S3crET
Create a new database and import the SQL dump file (See Github: https://github.com/howest-mct/2025-2026-projectone-mct-MilanVermote/data)
Configure the database connection
Make a copy of config_example.py and rename it to config.py. Fill in your database password
Web App
The web interface is built with a FastAPI backend and served via Apache2 on the Raspberry Pi.
Setting up Apache2
First, configure Apache2 to serve the front-end files from your repository:
Find the line with DocumentRoot /var/www/html and change it to:
Save with Ctrl + X, then Y and Enter.
Next, open the Apache2 configuration file:
Find the following block:
And change it to:
Save with Ctrl + X, then Y and Enter.
Set the correct permissions:
Restart Apache2 and verify it is running:
You should see active (running) in the output.
Using the web app
Make sure your PC is connected to the same WiFi network as the Raspberry Pi. The IP address of the Raspberry Pi is always shown on the LCD screen of the device. Open a browser on your PC and navigate to:
The web app offers the following features:
- Temperature & Humidity — live readings and history from the DHT11 sensor
- Pill Schedules — view, edit or delete medication schedules per user
- Pill Intake — view when a user has taken or missed their pills
- Motor Testing — manually test each stepper motor
Auto-start on boot
To make the backend start automatically when the Raspberry Pi boots, create a service file:
Add the following content:
Copy the file to the systemd folder:
Test the service:
If everything works correctly, enable auto-start on boot:
Check the status of your service at any time via:
Result
The smart pill dispenser is a complete, standalone device that helps elderly people manage their medication independently at home.
How it works
Medication schedules are set up and managed through the web app. When it is time for a user to take their medication, the LED on the device starts blinking and the name of the person who needs to take their pills appears on the LCD screen.
The user then scans their RFID badge on the side of the device to identify themselves. Once identified, they hold their hand below the dispenser and the stepper motor automatically rotates the cylinder to release the correct pills through the funnel.
After collecting the pills, the user confirms the intake by pressing the button on the front of the device. This is logged in the database and can be viewed in the web app, where caregivers can also check whether pills have been taken or missed.
The DHT11 sensor continuously monitors the temperature and humidity inside the device to ensure medications are stored under safe conditions. These readings are also visible in real time on the web app, along with a history of previous measurements.
(Photo of result)