Introduction: IoT Pill Dispenser

About: Thank you, Instructables!! I have removed many of my Instructables as along with being cringy :P they lacked proper documentation (thus difficult to replicate) and some didn't even work properly. Please enjo…

Does you grandma forget taking her pills? Here's a solution.

I decided to make a smart pill dispenser that could remind about medicine and dispense it on press of a button. If in case dose is missed a notification is sent to caretaker.

Device is portable and powered by a Li-Po battery which can be charged over USB cable.

Buzzer and LED is used for alarm.

Here is demonstration video:


Unfortunately due to COVID-19 situation I left most of my electronics components and tools at my college room(Some 2000 kilometres away!), but luckily had some laying in packed boxes at home.

List of required things:

  • Wemos D1 mini ESP8266 board(Clone works just fine)
  • 3X SG90 9g servo motors
  • 0.91" 128X32 OLED Display
  • DS3231 RTC Clock Module
  • TP4056 Li-Po charging module
  • Li-Po battery(Or maybe Li-ion cell, any portable power source works)
  • LEDs,Buzzer,Push Buttons,Switches
  • PVC Conduit Pipe
  • 1/2" PVC Elbow
  • Perfboard


  • Soldering Iron
  • Solder Wire(Lead Free ;-))
  • Our trustee Hot Glue Gun + Some Glue Sticks
  • Hacksaw
  • Dremel like rotary tool

Note:- Unfortunately PVC Conduit pipe I used is not food-safe. I do not have access to 3D Printer certainly not during lockdown. Although there's no reason to worry, I uploaded CAD files for the required components!

Step 1: Design and Mechanism

Within some time(60 seconds, can be changed) after onset of alarm, press of green button on top operates two servos dispensing a pill. If button not pressed an E-mail is sent using IFTT(Webhooks).

Although pill can be dispensed at any time irrespective of alarm time, for this operation long press the green button.

Two servos operate in a sequence to push one pill down the slot and third servo opens lid just at the right time dispensing pill out.

Above 2 illustrations depict working mechanism and design of project.

Below attached is video of barebones of pill dispenser:

Step 2: 3D Printing Main Passage

Although I used PVC material but you can have a rough idea from below embedded parts. Dimensions can be adjusted according to your needs.

You can see in main tube there are 2 channels one small and the other slightly bigger. Former channel is for structural rigidity and latter for passing pills.




Step 3: Main Passage Construction

You can skip this step in case you'll be 3D printing this component!

I started out with 20mm X 12mm PVC casing because it allows a normal tablet to pass through freely.I cut reasonable length using a hacksaw and went on to making slits for servo motor attachment(Thing that acts as obstruction in path of pills).

An art and craft cutter will give more precision when cutting slits. The distance between 2 slits is equal to length of pill to be used. In my case center to center distance is 15mm.

Step 4: Rig Servos to Passage

My old trustee "Hot Glue Gun" helped me with this. Use single sided attachment.

Although, I used cello tape to temporarily hold them in place and after testing everything glued them permanently.

Step 5: Elbow Attachment

As pills would be falling vertically to make them horizontal when dispensing out, I used elbow attachment for 1/2" diameter pipe. Again used hot glue gun to secure everything in place.

Step 6: Schematics and Soldering Circuit

Above is fritzing schematics of project.

Some clarification:

  • Higher placed servo of main passage is attached to pin D3
  • Lower placed servo to D8
  • Lid servo to D5

Take a descent sized perfboard and place headers as described in photo before soldering everything.

I used lead free solder this time after realizing lead is really dangerous stuff, I suggest you too to use lead free :)

You can make connections even more secure by gluing all wires on backside but do it only after checking everything works fine there should be not short-circuits. Because after gluing its almost impossible to modify connections.

I made my own cable for connecting components to main perfboard using male-female headers and rainbow ribbon cables.

Step 7: Preparing Battery

I used old samsung phone's battery(Got it for cheap, only 100 Rupees or 1.5 USD). Identify positive terminal and negative terminals of battery and solder 2 wires.

I would suggest to check if battery still charges, old batteries are usually completely discharged. Use TP4056 to charge it up.

Step 8: Modification of TP4056

Charging status LEDs of TP4056 are SMD and won't be visible outside enclosure of project so I decided to replace them with common through hole LEDs. It turns out they are connected in common cathode configuration. Carefully remove SMDs and solder thin wires. Middle solder pad between two LEDs is the common cathode.

Step 9: Building Enclosure

I chose thin plywood for building the enclosure. Dimensions have high tolerances. You can make according to your components. It should be portable. I used thin nails and glue to join surfaces.

Construction is pretty simple, a cuboid with cutout for various things.

Charging Status LEDs, Buzzer, Display, charging port, opening etc.

Use Dremel to make cutouts in plywood. Circular opening for PVC elbow is the most challenging to do.

Instead I would suggest to 3D print the enclosure if one has access to.

Step 10: Fit Everything In

Here comes the most satisfying part of the build, gluing everything in its place and tidying everything up. I just used hot glue gun to secure components in place. Placement of buttons and switches can be seen in pictures above.

Step 11: Lid and Hinge

I also added front cap that moves aside whenever medicine is to be ejected, this is one of the main components that prevents any kind of dust or germs from creeping inside passage.

Now enclosure was almost ready, except a hinge for refilling pills. I used two thin nails to make a working hinge as shown in video.

Step 12: Setting Up IFTTT

The only part left was programming the device and setting up ifttt applets.
I used 2 events:

  1. One for indicating that pill was dispensed
  2. Other one if alarm was missed hence dose was not taken

To set up ifttt service:

  • Go to
  • Create an account
  • Go to homepage
  • Click on "Create" button on top right corner(This will take create new applet)
  • Click on Big "This" button followed by If
  • Search for Webhooks and select it
  • Enter event name and remember it
  • Now click on Big "That" button followed by then
  • Select any convenient notification system, I chose email (type it in searchbox) and connect the email id to which alert is to be sent.
  • Next compose the template for email (Simple dose missed text is enough)
  • Open Webhooks and open documentation to get you KEY.

You can refer to Taifur's instructable for better instructions except Maker in his tutorial is webhooks now and I chose E-mail instead of SMS.

You can chose any notification system. More power to you!

Make sure to remember webhooks key that is to be used in code.

Step 13: Editing and Uploading Code

Now for making these work one has to edit code provided below.

Enter you ssid name and its password as indicated in code.

Also replace the key found on documentation page of webhooks in address1 and address2 along with their event names.

Event names are different for each event but key is same.

Also enter the alarm time code(values of integers hour_1 and min_1) Now the code is good to be uploaded.

Below is the code attached after modifying the parameters. Upload it and you are good to go!

Step 14: Final Thoughts

Although I loved this machine, it works flawlessly each time.This is in no way a perfect device.

A lot can be improved in it. I am working on second version of it improving on:

  • Pocket design
  • 3D printed enclosure
  • Neat wire management inside enclosure using printed circuit boards

I will put in efforts to turn this idea into really awesome version 2.

I hope you liked my instructable! Please comment down any suggestions you have!

And don't forget to vote! ;)

Robots Contest

Participated in the
Robots Contest