Abstract
Remembering to take medicine at the right time can be hard, especially if you need to take multiple medications at different times of day. It might not be a big deal if you forget to take your daily multivitamin, but for some people, forgetting to take medication at the right time can be dangerous. What if you had a device that could not only set off an alarm at the right time, but also automatically dispense the right pills for you? In this project, you will build an automatic medicine dispenser to do just that!
Summary
Previous experience with Arduino is required to do this project. See our How to Use an Arduino tutorial page if you are new to Arduino.
A kit is available from our partner Home Science Tools. See the Materials section for details.
The dispenser in this project is not child-proof. Do not use with real medication in households with small children. For demonstration purposes you can use candy instead.
Note: If you have never used an Arduino before, please do at least the first six tutorials on our How to Use an Arduino page before attempting this project.
Objective
Build and customize an automatic pill dispenser.
Introduction
Have you ever had to take medication at the same time each day? Maybe you take a multivitamin or an allergy pill at breakfast, or maybe you have been sick and had to take antibiotics in the morning and at night. Especially if you have to take your medication more than once a day, or even different medications at different times of day, this can be difficult to remember! You can buy a pill organizer like the one in Figure 1 to help you keep track, but you still need to remember to take the medication or set a separate alarm.
An automatic pill dispenser combines the features of a pill organizer and an alarm into one device. You pre-load the device with your medication(s), set the times, and then it will automatically dispense the right amount of medication at the right time(s) each day. This project will show you how to build an automatic pill dispenser like the one in Figure 2 using an Arduino. The dispenser uses a servo motor to turn a paddle wheel that holds pills in different compartments. The servo is programmed to rotate at certain times. A real-time clock (RTC) keeps track of the time. When a compartment slides over the hole, the pills fall down a chute into the tray at the front of the device.
Using an Arduino allows you to customize your pill dispenser and add other features. For example, you can add a liquid crystal display (LCD) to show the date, time, and important messages. You can also use a buzzer and light-emitting diodes (LEDs) for both audible and visible alarms. You can find individual tutorials for all these parts on our How to Use an Arduino page.
This project is highly customizable. You can change the device's physical features, such as:
- Physical features (appearance and number of compartments)
- Circuit (number and color of LEDs)
- Code (alarm times and on-screen messages)
The project's procedure will show you how to build the device shown in Figure 2, but what exactly you build is up to you!
Terms and Concepts
- Pill organizer
- Automatic pill dispenser
- Arduino
- Servo motor
- Real-time clock (RTC)
- Liquid crystal display (LCD)
- Buzzer
- Light-emitting diode (LED)
Questions
- What are some of the potential health risks of forgetting to take medication?
- What commercial options (things you can buy in a store or online) already exist for organizing or automatically dispensing medications?
- What features do these devices have? Are there any features that they lack?
- What features would you want to include in your own custom automatic pill dispenser?
Bibliography
- Finio, B. (n.d.). How to Use an Arduino. Science Buddies. Retrieved April 2nd, 2024
- Science Buddies Staff (n.d.). Engineering Design Process. Science Buddies. Retrieved April 2nd, 2024
- Söderby, K. (2021, November 18). Liquid Crystal Displays (LCD) with Arduino. Arduino. Retrieved April 4th, 2024
- Söderby, K. (2024, January 23). Arduino UNO R4 Minima Real-Time Clock. Arduino. Retrieved April 4th, 2024.
- Fried, F. (n.d.). Adafruit DS3231 Precision RTC Breakout. Adafruit. Retrieved April 4th, 2024.
Materials and Equipment
Recommended Project Supplies
This is an engineering design project, so your materials list may vary depending on what features you want to include with your dispenser. Parts may be available in different quantities and prices from different vendors.
- Electronics
- Science Buddies Electronics Kit for Arduino, available from our partner Home Science Tools. You will need the following parts from the kit:
- Arduino-compatible microcontroller board
- USB cable
- Breadboard
- Jumper wires
- Potentiometer
- LED
- Current-limiting resistors (220 Ω for UNO R3, 470 Ω for UNO R4)
- Pushbutton
- 10 kΩ resistor
- SG90 servo motor
- Additional jumper wires. Longer flexible wires are best for making connections from the breadboard to the Arduino, but shorter solid-core jumper wires are better for making connections on the breadboard.
- Male to male header pins
- 1602 LCD screen.The example code is written for a screen that uses parallel communication, so make sure you do not buy a screen with "I2C" in the description. If you do, you will need to use different code for I2C communication.
- Active buzzer (replace with passive buzzer if you want to play different tones)
- Real-time clock (RTC)
- If you are using an Arduino UNO R4 Minima (or equivalent), there is a built-in RTC but no battery backup, so the time will reset if your Arduino loses power. This works for a science project demonstration, but should not be used for critical medication.
- If you are using an Arduino UNO R3, or if you want a backup battery feature, then we recommend an external RTC like this one from Adafruit.
- Science Buddies Electronics Kit for Arduino, available from our partner Home Science Tools. You will need the following parts from the kit:
- Additional tools and supplies
- Cardboard
- Cardstock
- Popsicle sticks
- Scissors
- Hot glue gun
- Candy (to use for demonstration instead of real medication)
Experimental Procedure
- Build your dispenser. Figures 3 through 5 show several different views of the device. You can choose to make your dispenser using craft supplies or 3D-printed parts if you have access to a 3D printer. Your assembly procedure may vary depending on the materials you use.
- Cut a hole in a piece of cardboard so the top of the servo motor fits through.
- Glue the servo to the bottom of the cardboard, so the top sticks through the hole.
- Build legs to support the four corners of the cardboard.
- Place a circular wall on top of the cardboard, centered around the servo. A cardboard tube from the inside of a roll of duct or masking tape works well.
- Make dispenser compartments by gluing popsicle sticks together. Use a protractor if you want to measure exact angles. You will need to decide how many compartments you want, which in turn will determine how far the servo should rotate.
- Attach the servo horn to the motor (do not use a screw, just push it on) and carefully glue the popsicle sticks to the servo horn. Be careful not to use too much glue, you may need to pull the servo horn off later to make adjustments.
- Cut a pie-shaped wedge in the cardboard, the same size and shape as one of the dispenser slots.
- Build a ramp under the hole so the pills will slide down into a tray.
- Assemble the circuit as shown in Figures 6 and 7. You will need to know how to use a breadboard. Make sure your Arduino is not plugged into USB power as you build the circuit. That will give you a chance to double-check all of your wiring before powering the Arduino on. Note that this diagram assumes you are using an Arduino UNO R4 with a built-in real-time clock. If you are using an external RTC, you will either need a bigger breadboard, or you will have to remove some components (like the buzzer) from the breadboard to make room for the RTC. See our external RTC tutorial for instructions on wiring an external RTC.
- LCD connections. Note that pin labels may vary depending on where you bought your board. Pin numbers go from left to right when viewing the screen horizontally, but from bottom to top in Figure 6 since the screen is rotated.
- Pin 1 (VSS or GND) to GND
- Pin 2 (VDD or VCC) to 5V
- Pin 3 (V0) to potentiometer center pin
- Pin 4 (RS) to Arduino pin 12
- Pin 5 (RW) to GND
- Pin 6 (E) to Arduino pin 11
- Pin 7 (D0) - not used
- Pin 8 (D1) - not used
- Pin 9 (D2) - not used
- Pin 10 (D3) - not used
- Pin 11 (D4) to Arduino pin 5
- Pin 12 (D5) to Arduino pin 4
- Pin 13 (D6) to Arduino pin 3
- Pin 14 (D7) to Arduino pin 2
- Pin 15 (LED or A) to current limiting resistor to 5V
- Pin 16 (LED or K) to GND
- Potentiometer
- One outer pin to 5V
- Center pin to pin 3 (V0) on LCD screen
- Other outer pin to GND
- LED
- Positive (longer) leg to Arduino pin 7
- Negative (shorter) leg to current limiting resistor to GND
- Buzzer
- Positive pin to Arduino pin 8
- Negative pin to GND
- Pushbutton
- One side to 5V
- Other side to GND through 10 kΩ pull-down resistor and to Arduino pin 9
- LCD connections. Note that pin labels may vary depending on where you bought your board. Pin numbers go from left to right when viewing the screen horizontally, but from bottom to top in Figure 6 since the screen is rotated.
- Download the pill dispenser example code. Read through the commented code so you understand how it works.
- This code is written for the internal RTC on an Arduino UNO R4 Minima. If you are using an external RTC module, you will need to modify the code. We have example code for an external RTC here.
- This code is written for a dispenser with four compartments. It automatically rotates the servo 45° once per minute and then sounds an alarm. After the rotation, you need to press the button to confirm that you have taken the medication. After the servo has rotated 180°, it resets to its initial position.
- Upload the code to your Arduino and test it. Watch the motion of the dispenser. You may need to pop off the servo horn (this is why we said not to attach it with a screw earlier) and adjust it so the compartments align with the hole in the cardboard.
- If your device does not work as expected (the servo does not rotate, the LED does not light up, the LCD screen does not display correctly, the button does not work, etc.) you will need to troubleshoot or debug your circuit. This is a complicated circuit with a lot of parts. It is easy to misplace a wire on the breadboard, which can prevent one or more parts of the circuit from working properly. You will need to carefully double and triple-check all of your connections. It also helps to have someone else double-check your wiring, just like you might ask someone else to proofread your writing. Sometimes it can be hard to spot your own mistakes. If you get stuck or frustrated, take a break from working on your circuit and come back to it later. You might notice something that you did not notice before.
- Load some candy into your dispenser compartments and test it again. Make sure there are no issues with your ramp or tray, such as the candy getting stuck or sliding down too fast and bouncing out of the tray. Make adjustments to your ramp and tray if needed.
- Once you have the device working with the example code, it is time to customize your code. The example code dispenses medication one per minute, which works well when testing or for a demonstration at a science fair. There are many things you can change and customize in the code:
- How often it dispenses medication. The example code does this once per minute, which works well for testing and for a demonstration at a science fair, but for real-life use you will need to set different times of day. You can do this by adjusting the condition(s) in the
if
statement that detects the time (seconds == 0
in the example code). - How far the servo rotates. The example code rotates the servo 45° at a time, which works for four compartments. You will need to change the
angleIncrement
variable if you have a different number of compartments. - The messages displayed on the LCD screen.
- The behavior of the alarm, for example whether it beeps a fixed number of times or keeps beeping until you push the button.
- How often it dispenses medication. The example code does this once per minute, which works well for testing and for a demonstration at a science fair, but for real-life use you will need to set different times of day. You can do this by adjusting the condition(s) in the
- Once you have completed testing your device and customizing the code, try some real-world testing if possible. Remember that the device is not childproof and you should not use it with real medication or vitamins in a house with small children. If it is safe to do so, try using it for yourself or someone in your household over the course of a week. Do the automatic reminders make it easier to remember to take your medicine or vitamins? Are there any features you would add or change to your device? For example, what happens if the alarm goes off while you are in another room and cannot hear it? See the Variations section for some more suggestions.
Ask an Expert
Global Connections
The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.
Variations
- Build more than one device and run real-life human trials. Have volunteers keep track of how often they missed taking their medication for one week with their "normal" routine and for one week using the automatic dispenser. Does the automatic dispenser help people remember to take their medication more regularly?
- Try using your device to dispense dog or cat treats instead of medication. Can you use it to train your pet? Can you make it work with different sensors or inputs, such as a PIR sensor (motion detector) or ultrasonic distance sensor? Since the dispenser has an open top, you might want to place it in a high location your pet cannot reach (like a counter or shelf) so it can drop treats onto the floor.
- Advanced: make your device send an email or text message notification in addition to sounding an alarm. This can help if you are in a different room and do not hear the alarm. You will need to look up the different options for connecting an Arduino to the internet and sending messages.
Careers
If you like this project, you might enjoy exploring these related careers:
Contact Us
If you have purchased a kit for this project from Science Buddies, we are pleased to answer your questions.In your email, please follow these instructions:
- What is your Science Buddies kit order number?
- Please describe how you need help as thoroughly as possible:
Examples
Good Question I'm trying to do Experimental Procedure step #5, "Scrape the insulation from the wire. . ." How do I know when I've scraped enough?
Good Question I'm at Experimental Procedure step #7, "Move the magnet back and forth . . ." and the LED is not lighting up.
Bad Question I don't understand the instructions. Help!
Good Question I am purchasing my materials. Can I substitute a 1N34 diode for the 1N25 diode called for in the material list?
Bad Question Can I use a different part?
Contact Us
Related Links
- Science Fair Project Guide
- Other Ideas Like This
- Electricity & Electronics Project Ideas
- Human Biology & Health Project Ideas
- My Favorites