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

Design_Finished.jpg

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

  1. 1x Raspberry Pi 5 Model B — €123,99 — Gotron
  2. 1x Raspberry Pi 40 pins GPIO Extension Kit (T-piece) — €6,50 — Tinytronics
  3. 1x MCP23017 I2C Port Expander — €4,00 — Tinytronics
  4. 1x Arduino Power Supply Module 3.3V/5V — €11,99 — Amazon
  5. 1x LCD 1602 Display — €6,99 — Bol.com
  6. 1x Button with LED indicator

Sensors

  1. 1x Infrared Break Beam Sensor — €3,75 — Tinytronics
  2. 1x IR Pyroelectric Infrared PIR Motion Sensor — €6,49 — Tinytronics
  3. 1x DHT11 Temperature and Humidity Module — €4,68 — Reichelt

RFID

  1. 1x RC522 RFID Module Kit — €6,00 — Tinytronics
  2. 1x RFID S50 Mifare Key Tag — €1,00 — Tinytronics

Motors

  1. 3x Stepper Motor 28BYJ-48 5V — €2,95/piece — Otronic
  2. 3x ULN2003A Stepper Motor Driver — €1,60/piece — Otronic

Housing (~€40)

  1. Laser-cut wooden enclosure
  2. 3D-printed internal components

3D Printed Components

Milan_3D.png

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

  1. 1x Funnel
  2. 3x Rotating cylinder with 7 pill compartments
  3. 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

20260612_112329.jpg

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

20260614_182922.jpg

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

20260615_003908.jpg

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:

  1. MCP23017 I2C Port Expander
  2. Potentiometer for LCD contrast adjustment
  3. Transistor to control the LED button
  4. 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

Device_Isolated.png

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:

sudo raspi-config

Navigate to Interface Options and enable I2C, SPI and SSH one by one and reboot your pi using the command:

sudo reboot

Clone the repository from my github: https://github.com/howest-mct/2025-2026-projectone-mct-MilanVermote

git clone https://github.com/howest-mct/2025-2026-projectone-mct-MilanVermote

Create a virtual environment:

python3 -m venv venv

Install all required libraries using the requirements.txt file:

pip install -r requirements.txt

Additionally, install the following two libraries manually as they are not yet included in requirements.txt:

pip install SimpleMFRC522
pip install adafruit-circuitpython-dht


Database Setup

Database_ERD.png

This project uses a MariaDB database. The database structure is shown in the ERD below.

Database structure

The database consists of the following tables:

  1. profiel — stores user information and their RFID tag
  2. pil — stores medication information
  3. pilSchema — stores the medication schedule per user
  4. pilInname — registers when a user has taken their pills
  5. sensor — stores the sensor types used in the device
  6. sensorData — stores readings of all sensors
  7. motor — links each motor to a specific pill
  8. motorActivatie — logs each time a motor has been activated

Creating the database

Open MySQLWorkbench and connect to your Raspberry Pi via SSH tunnel:

  1. SSH Hostname: 192.168.168.169
  2. MySQL Username: root
  3. 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

Schermafbeelding 2026-06-15 094944.png
Schermafbeelding 2026-06-15 094337.png
Schermafbeelding 2026-06-15 094522.png

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:

sudo -i
nano /etc/apache2/sites-available/000-default.conf

Find the line with DocumentRoot /var/www/html and change it to:

DocumentRoot /home/student/project/<your_repo>/front

Save with Ctrl + X, then Y and Enter.

Next, open the Apache2 configuration file:

nano /etc/apache2/apache2.conf

Find the following block:

<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>

And change it to:

<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>

Save with Ctrl + X, then Y and Enter.

Set the correct permissions:

sudo chown student:www-data /home/student/project/<your_repo>/front
sudo chmod 0750 /home/student/project/<your_repo>/front

Restart Apache2 and verify it is running:

service apache2 restart
service apache2 status

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:

http://<ip-address-shown-on-lcd>

The web app offers the following features:

  1. Temperature & Humidity — live readings and history from the DHT11 sensor
  2. Pill Schedules — view, edit or delete medication schedules per user
  3. Pill Intake — view when a user has taken or missed their pills
  4. 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:

nano mijnproject.service

Add the following content:

[Unit]
Description=ProjectOne Project
After=network.target

[Service]
ExecStart=/home/student/project/<your_repo>/<venv>/bin/python -u /home/student/project/<your_repo>/backend/app.py
WorkingDirectory=/home/student/project/<your_repo>/backend
StandardOutput=inherit
StandardError=inherit
Restart=always
User=student
CPUSchedulingPolicy=rr
CPUSchedulingPriority=99

[Install]
WantedBy=multi-user.target

Copy the file to the systemd folder:

sudo cp mijnproject.service /etc/systemd/system/mijnproject.service

Test the service:

sudo systemctl start mijnproject.service

If everything works correctly, enable auto-start on boot:

sudo systemctl enable mijnproject.service

Check the status of your service at any time via:

sudo service mijnproject status

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)