Introduction: 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:

  1. It has a 3D printed lock that opens with a button press.
  2. It sends an email to me and my parents when I have taken the medication and more importantly when I am late for medication.
  3. 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

  1. Chest/Small Box - I strongly recommend wood to make drilling much easier. This is a link to what I got.
  2. Raspberry Pi
  3. Arduino
  4. Breadboard
  5. Breadboard Jumper Wires
  6. 2 Pin LED
  7. Mini Servo Motor
  8. Lock - A 3 D printed lock that has a latch that moves back and forth using the Mini Servo Motor

Step 1: 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.

  1. 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
  2. Arduino + Lock - Wire up the lock to the arduino by plugging in the ground, power, and input sensor cables. As
  3. 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
  4. Raspberry Pi - Connect the power, monitor and keyboard cables to the raspberry Pi, so that you can do the next - Write the code.

Step 2: Code

  1. Connect the Raspberry Pi to a monitor and keyboard and turn the power on.
  2. You should land on a OS home screen.
  3. Create a folder in one of the drives - say pillbox and copy this Python code (attached) in the folder.
  4. The code is pretty straightforward to understand, it basically has logic to do a few things:
  5. Opens the latch:
  6. On button press event: opens the latch on the lock for 30 seconds
  7. Sends an email (you can configure to whoever) saying that box was opened.
  8. 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.
  9. Sends email when you are late for your medication
  10. It sends an email when a configurable time expires that you are late for medication.
  11. Glows a red LED on the box to visually remind you that you are late for medication
  12. 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.
  13. 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.
  14. 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:
  15. 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
  16. 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.
  17. reboot the Pi to see this work. You can either power cycle the Pi or run the sudo reboot command.

Step 3: Prepare the Pillbox

  1. 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.
  2. On the top face - LED light
  3. On the top face - Button
  4. On the back - for power wire to exit
  5. On the front face - for the latch to lock into.

Step 4: Put It All Together

  1. Glue all the pieces from Step 1 into the top inside of the box
  2. 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.
  3. 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.