Introduction: Create an Internet Connected Pill Dispenser
Studies show the consequences of patients not taking medications according to doctor's orders can be serious, especially in older patients.With today's low cost micro-controllers and sensors (and the incentive of the Radio Shack / Instructables Micro Controller Contest) I thought there must be a better way to ensure my elderly relatives are taking their medications on schedule. This Instructable describes how you can use a Parallax Propeller micro-controller to create the Propeller based Internet Logging Pill Dispenser...or the P.I.L Box for short.
What is the P.I.L. Box?
The P.I.L. Box is a modification to a standard pill dispenser, it uses a Parallax Propeller micro-controller to keep track of when a patient should take their medications. It displays a count down timer one hour before dosage time and then when the time arrives, it generates audible messages, LED 7 Segment messages and lights an LED under the correct compartment to be opened. When the patient opens a compartment, a sensor detects this and records the event to an internet accessible log file (thereby allowing relatives or health care providers to verify meds are being taken on time). More importantly the P.I.L Box logs the fact that a patient has missed their serving time and even sends a Twitter message to alert relatives and health care providers.
- 1 Microcontroller - For this project I used a Parallax Propeller microcontroller (Board of Education model), but an Arduino would work as well.
- 1 Pill Dispenser - an Ezy Dose XL 7 Day Pill Reminder with Push Button Pop-up Covers
- 1 Project Box - I used a wooden ex-toolbox from a salvage store
- 8 Micro-switches - one for each day of the week and one to detect the pill box is missing
- 1 Momentary switch - used to answer prompts from the microcontroller
- 1 4-digit seven-segment display - displays messages
- 2 Shift registers or for easier wiring, I used a Shift-me! card from tymkrs.com
- 1 breadboard
- 1 speaker - the Propeller BOE has a 3.5mm headphone jack and voice synthesized messages are played through the speakers
- 1 PC - a serial connection over USB is used to log events to the web server.
- (optional) XBee modules - instead of a USB connection as shown in the attached video, you could optionally use XBee modules to send messages wirelessly from the PIL Box to the PC
Step 1: Design Features of the P.I.L. Box Internet Connected Pill Dispenser
- Dosage Time Reminders - Automated, clear, reminders to the patient, informing of the proper time to take their medications.
- "Next Dosage” Time Display – by pressing the red Enter button on the front panel, a user can switch from viewing the current time of day, to viewing the next scheduled medication time
- LED backlighting - LEDs mounted beneath the dispenser highlight the proper compartment to be opened for the current dosage time.
- Audible English language reminders are provided by way of the Parallax Voice Synthesizer object and Propeller speaker jack.
- Local and Remote Logging - The device logs the date and time a patient accesses the dispenser compartments, as well as many non-compliance error situations (such as a missed dosage time). Logs are written to both a web-server accessible file and locally on the Propeller microSD card. I log the file locally to handle the case of a PC server failure or a power-outage (assuming the P.I.L. Box is using the optional 9V battery supply feature).
- Internet Accessible Logs - Remote logging allows a family member or other care provider to check on a patient remotely and verify that they are taking meds on schedule. A patient may even use the log themselves. Consider the case where a patient arrives at work and can't remember if they took their morning medications, with the P.I.L. Box an up to date record of meds taken is available on your smart phone or networked computer.
- Twitter enabled - the P.I.L. Box is a registered Twitter application and by use of REST APIs, the python-based remote logging server sends Twitter messages to notify care providers about missed dosage events.
- Low Cost Standard Pill Containers - P.I.L. Box uses inexpensive standard 7 Day Pill Reminders made by Ezy Dose. The prototype design allows the container to easily be removed, enabling a care provider to visit weekly dropping off a new pre-filled med container and collecting the empty container for restocking. Being able to remove the box will help users actually get to their meds as well.
- Non-compliance Error Messages - If a patient misses a dosage time, forgets to replace the pill container or accesses meds early, visual and audible error messages are generated, and such issues are logged to the local and remote log-files.
- Extendable Design - The current prototype supports only seven compartments, one for each day of the week, but obviously many patients would require three or even four servings a day. The Propeller has 20 totally free I/O pins and I needed 12 simply to drive the LED display, so I used shift registers to provide additional pins. Because I used the Tymkrs Shift Me V1 shift register board, not only could I control 8 switches and 8 LEDs while only allocating 6 pins, I knew I could also chain together many such boards, thus easily supporting as many containers as desired. For example, with little design change, we could simply add 3 additional shift register boards, allowing us to handle 32 LEDs and 32 Switches and thus support the Ezy Dose 4X/Day Weekly Pill Organizer, which features 28 separate pill compartments.
If a picture is worth a thousand words, then a video must be even better…please see my video demo on YouTube
Step 2: The Internals, How Does It Work?
The Propeller Based Internet Logging Pill Dispenser (P.I.L. Box) has the Parallax Propeller Board of Education at its heart.
- When started, the P.I.L. Box is aware of the current time and the patient dosage time.
- The next dosage time is displayed until we are less than one hour away.
- Once we are one hour away, a countdown timer is shown on the 4 digit LED display. This timer runs in a separate Propeller cog, allowing the main program to continue checking for buttons, error conditions and log events.
- When the countdown timer reaches zero, the appropriate LED is turned on indicating which compartment the patient is to access. A voice synthesized reminder is played as well.
- If the patient opens the proper compartment, a log entry is added to the local and remote log-files.
- If the patient opens the wrong compartment or does not access the compartment, an error message is played and an error event is logged.
- The Next Dosage time is calculated and we start again.
Step 3: Complete the Wiring
Build the Box
While there are many types of Pill Dispensers on the market, I found the Ezy Dose XL 7 Day Pill Reminder works great for this project because it's the only model I've seen that has buttons which can easily be detected by microswitches. The dimensions are not as particular but I've made the dimensions available in a 3D drawing in Tinkercad here:
Connect the wires
I used an online schematic drawing tool called Schemeit for the P.I.L. Box schematic and wiring diagram. It’s very easy to see what goes where when you use the online version so I've shared the design here
Step 4: Code for the Propeller Based Pill Dispenser and It's Server
- Coding the Parallax Propeller Micro-Controller is done in the Propeller Tool Developer Environment (as seen in the image here).
- Code for the Parallax Propeller Micro-Controller does not have to be done from scratch. For my project I used several "objects" from the Propeller Object Exchange site http://obex.parallax.com
- I've attached my code to this Instructable as attachment code.zip. Hopefully the code and the comments there in will give everyone a better understanding of how the project works.
This is the structure of the code that makes up the PIL Box:
The main function of the PIL Box is implemented in the file PILDispenserMainDriver.spin
2013 P.I.L Dispenser Project
Author: Tim Massaro
Project : "microMedicPIL"
├──Parallax Serial Terminal Plus.spin
├──Propeller Board of Education.spin
│ └── SD-MMC_FATEngine.spin
Code for the Python Based Server
The python based server, PIL_Logger_Final.py runs on a PC. It was tested with python 2.7.3 on Windows 7. The server waits for messages from the Propeller micro-controller. The server logs events to a file on the PC which can be accessed from a webserver. Optionally the server can send a Twitter message or text message to notify care providers about missed dosage events.
Thanks for checking out my micro-controller based project.
Good luck on all your projects!
We have a be nice policy.
Please be positive and constructive.