Smart Pill Box
Remembering to take medicines can be challenging, it definitely was for me. It can also be a source of frustration for the parents when they are not sure if the child has taken their medications on time. I had done a summer project with Bluestamp Engineering where I had built a door latch. I decided to take that learnings and create a Smart Pill Box to help me and my parents solve this constant challenge of medication management.
The main features of my pillbox are:
- It has a 3D printed lock that opens with a button press.
- It sends an email to me and my parents when I have taken the medication and more importantly when I am late for medication.
- It visually shows me when I am late for my medication by glowing a RED LED light on the outside of the box (see picture).
This tutorial will go over the steps and parts so you can build one yourself.
Here is a video of the various features of this Smart Pillbox.
Future Additions/ideas:
- My version 2 which is in progress will open the lock with a fingerprint scan.
- You could also add a camera to enable facial recognition for opening the lock
- Smart speaker integration (Google home or Alexa) that will announce to a speaker that you are late for your medication
- Hydraulic motor to open the pillbox automatically on button press.
Supplies
- Chest/Small Box - I strongly recommend wood to make drilling much easier. This is a link to what I got.
- Raspberry Pi
- Arduino
- Breadboard
- Breadboard Jumper Wires
- 2 Pin LED
- Mini Servo Motor
- Lock - A 3 D printed lock that has a latch that moves back and forth using the Mini Servo Motor
Overall Circuit
The overall circuit has a few pieces in it. This step is just to get these pieces wired together. There are a lot of youtube videos on how to connect arduino, rasbperry pi, breadboard, leds etc. I wont go into too much detail on those common connections.
- Arduino to Raspberry Pi - Connect Arduino to Raspberry pi using USB Cable ports. The raspberry pi will also supply power to arduino using that cable so no separate power source is needed for Arduino to run. There are a
- Arduino + Lock - Wire up the lock to the arduino by plugging in the ground, power, and input sensor cables. As
- LED + Button - Plug in the button and LED to the breadboard using extension wires for easier fitment and more play inside the box. Connect breadboard extension wires to Raspberry Pi
- Raspberry Pi - Connect the power, monitor and keyboard cables to the raspberry Pi, so that you can do the next - Write the code.
Code
- Connect the Raspberry Pi to a monitor and keyboard and turn the power on.
- You should land on a OS home screen.
- Create a folder in one of the drives - say pillbox and copy this Python code (attached) in the folder.
- The code is pretty straightforward to understand, it basically has logic to do a few things:
- Opens the latch:
- On button press event: opens the latch on the lock for 30 seconds
- Sends an email (you can configure to whoever) saying that box was opened.
- starts a timer for 60 seconds (You might want to change this to a time that works for your scenario) - This timer is used to glow the red led. The idea is that after you have opened the box a timer starts so that a red led light can glow to visually indicate when you are due to take your next medicine.
- Sends email when you are late for your medication
- It sends an email when a configurable time expires that you are late for medication.
- Glows a red LED on the box to visually remind you that you are late for medication
- An email might not be sufficient to remind you that you are late for medication. Thats why I have also added a red led on the box that glows when you are late.
- You can test whether everything works now by running the Pillbox.py program now. It should open it in a default IDE for raspberry pi. Play with the time values etc, make sure everything works as expected.
- Once everything works, you want to make sure that this python code will automatically execute everytime you power to raspberry pi. There are many ways to do that (you can find them by doing a quick web search). I used the following method:
- Edit the rc.local file - In order to have a command or program run when the Pi boots, you can add commands to the rc.local file. On your Pi, edit the file /etc/rc.local using the editor of your choice. You must edit it with root permissions: use the command sudo nano /etc/rc.loca
- Add the command to run your pythod script here - for example sudo python /home/pi/Pillbox.py &. The & will run the process in the background as you want to have it run continously.
- reboot the Pi to see this work. You can either power cycle the Pi or run the sudo reboot command.
Downloads
Prepare the Pillbox
- Drill the following holes. I used a drill and different drill bits for it. Here is a good video on instructables on how to do this.
- On the top face - LED light
- On the top face - Button
- On the back - for power wire to exit
- On the front face - for the latch to lock into.
Put It All Together
- Glue all the pieces from Step 1 into the top inside of the box
- See the picture, this is not exactly a science but the idea is that you want to fit the pieces into the box and then do some cable management to ensure they are secure.
- One critical part here is that make sure that the hole you make for the latch aligns well to where the latch will be when the box is closed. This will require you to make some measurements before you do the drilling.
That is it. Your pillbox is ready. Have fun, modify it to make it work for yourself. See this video to see the pillbox in action.