Introduction: The Automatic Medication Dispencer

Picture of The Automatic Medication Dispencer

I wanted to make something for the health contest, but I had no clue where to start until my girlfriend got ill. I noticed how easily she forgot to take her prescripted medication and that made me think. A lot of people, especially elderly people, take a lot medication on a daily basis to stay as healthy as possible. Some of that medication needs to be taken on a exact time, or they don't function as well.
So I decided to make a machine that automatically gives the right pills at the right moment and also sounds an alarm so that the person who needs those pills knows it's time for his or her medication.

It is my first 'big' project that combines a clock/calender, memory and movement.

If you like it, then please vote for it in the Health contest.

Step 1: What Does It Do?

Picture of What Does It Do?

The 'machine' has seven drums (one for each day of the week) with 4 compartments that you can fill with your medication. When filled, you put them back in the machine and connect them to it.

On the front of the machine is a lcd-screen and 2 buttons. There you can set the time and date and program when you need the medication.

When it is time for your medication, the machine drops the correct pills and sounds an alarm until you take the pills and push a button. After that it goes back to "sleep" until the next alarm.

Step 2: Making Plans

Picture of Making Plans
What are the requirements of a machine if we think about a machine that gives you your pills?
  • It should be the right pills: We need a system that drops the right pills when needed and that is easy to fill up when empty. So after quite a long time of hard thinking (and several headackes later) I came up with a drum that has 5 compartments with a stepper motor that turns the right compartment to a hole, so the pills can drop out.
I decided to have 7 drums with 5 compartments so that you can use a drum for each day and every drum contains a maximum of 4 doses (5th compartment always has to be empty).

  • They should come at the right time: We have to be sure that the pills are delivered at the rigth time so a clock is added to the electronics circuit. I've used the very populare DS1307 Clock IC. Main reason is that is a very easy clock to use and that is only uses 2 wires (I2C)for communication with the microcontroller. It also has its own battery backup system so it can run up to 10 years without main power.
  • It should be reliable: Your device should not lose its data in case of a power outage and it would be nice if it also keeps working during a blackout. So a 9V backup battery was added and all data is stored on a EEPROM IC so that it won't be lost. The EEPROM IC is a 24LC16B that uses the same two wires as the clock to communicate with the microcontroller.
  • It should be easy to use: So it has only 2 buttons and an lcd screen to acces the needed information. It also has a buzzer so that it can give a soundalarm when the pills are delivered.


Step 3: Building the Drums.

Picture of Building the Drums.

To construct the drums, I used 3mm acrylate which I had CNC-milled into all the different bits and pieces.

A clear acrylic tube makes for the housing.

In the back panel a hole of 5.5mm was drilled, in which the motor can be fitted. In the inside disk a hole of 1mm was drilled so that it could be stuck on the 1.5mm shaft of the motor.

I removed a section from the tube to create an opening through which the pills can drop out.

After that everything was glued together with cyano-acrylic glue.

Step 4: The Electronics

Picture of The Electronics

I have spend a lot of time drawing this circuit and I hope that it is clear to understand.

The electronics basically consist of two boards.
  • Mainboard: the mainboard contains the powersupply, Microcontroller, clock, memory, and motordrivers.
  • Interface board: This board contains the LCD-screen and 2 buttons.
Both boards are connected to each other with a 10wire flatcable.

Main board:

The powersupply should be pretty forward: it is a standard 5V supply used on many projects. The only thing I added are a 'power-on led' and a connection for a 9V battery. The 2 diodes should prevent the 9V battery to 'charge' when the 12V is on and vice versa.

When we look at the microcontroller, you can see that Port D is entirely used for the lcd and the 2 buttons (INT0 and INT1).
Port B is used for ISP programming (PB3 to PB5 + PC6 for reset) and to sent the pulses for the steppermotors to the drivers (PB0 to PB2).
The communication with the clock and EEPROM goes via an I2C protocol and uses PC4 and PC5.
PC0 is used for the buzzer and PC1 to PC3 go to the 74HCT238. The 74HCT238 is a  3 to 8 decoder/converter and decodes a 3 pin binary input to a decimal output. I use it to save pins on my microcontroller. The output of this IC turns the logic voltage of the drivers on and sets the enable pins to 1. One driver for each day of the week.

As said before the clock and the EEPROM use the same 2 wires to communicate with the microcontroller via an I2C protocol. It is a pretty easy and straightforward way to communicate (especially if you use bascomAVR like I do) and it allows you to communicate with 127slave devices via 2 wires. Just don't forget to add the 2 pull-up resistors (in this case 4,7K).

Interface board:

Port D on the main board, is connected to a 10 pin female header so that it can be connected directly to the interface board by a flatcable. The power for the interface board also comes via the cable from the main board.
The 10K resistor and the 10K potentiometer are used to set the brightness of the lcd. The power and datalines are directly connected from the header.

The two buttons connect to ground. Note that the pull-up resistors (1.5K) are on the mainboard.

Keep in mind that other lcd's can have a different pinning so check your datasheet for the correct pinning.

I added a 47Ohm resistor to the backgroundlight just to make it a bit less bright. It is however not a necessary component to make the machine work.

Step 5: Programming

Picture of Programming
I won't go to deeply into explaining the programming of the device itself, as everybody has his or her own way of programming and may use a prefered language. What I will do is explain the idea behind it and how it works in my case.

Start up:

When power is switched on the microcontroller reads the clock and makes sure that the clock is running by setting bit 7 of register 0 (oscilloscope enable bit) to 0. As the datasheet suggests, this is needed because the initial power-on state of the registers is not defined.

Then the first needed alarmtime is read from the memory and stored into the appropriate variables.

Main loop and alarm sub:

After this the program goes into its main loop. Every second the microcontroller reads the clock and compares it with the data from the memory. When there is a match the program goes to the alarm subroutine.

In the alarm subroutine the program decides what drum should rotate depending on the day of the week and after that it makes it move 3 steps.When the movement is done a alarm sounds and it only stops when there is an interrupt by one of the 2 buttons.
After the alarm is stopped, the system reads the next alarmtime from the memory and returns to its main loop.


In setup mode, 2 buttons are used to set the entire machine. Both buttons are interrupts and each time they are pressed the value of their variable increases by 1. 
The variable of one of the buttons tells the system what data should be set and the other variable gives the value. This way we can setup everything with just 2 buttons.

After all the variables are set, the microcontroller writes everything to the clock and/or memory and goes back to the main loop.


janw (author)2010-12-30

Note to everybody who are interessed in the code: I am rewriting the Bascom code for this project and will publish it as soon as I have finished it. But a newborn baby around, they work doesn't go very quickly.

Shruti Bhaskaran (author)janw2017-09-17

Hello. This is very innovative. Could you please tell the microcontroller you have used and also send the code to the email

Thank you in advance.

FarEast97 (author)janw2017-04-04

hi sir.. can you send me the code for this project? cuz i need it to make my final year project.. thanks sir

muhammad idzham (author)janw2017-03-19

sir can you send the code for this project to my email

cherukus (author)janw2017-02-06

sir im very impressed with your, can u give me the code and other materials used in project

VinceR21 (author)janw2016-09-16

Sir, i would also like to ask about the specific materials used in this project. thank you very much.

VinceR21 (author)janw2016-09-15

Good day sir, could you kindly give me the code for this particular project.

shilpap9 (author)janw2016-09-13

i liked the project very much so i need the project code. plz forward to my mail where can i get the components? for this project

sapiks (author)janw2015-09-12

hi sir, would u please send the code? my email

macnilrad (author)janw2015-08-04

sir, would you please send the code for this project? this is my emails

myl123 (author)janw2014-07-07

hello there sir. do you have the code of this already? the one that you rewrote? i hope i can get a copy of it. i'll be using this for my project. please send me your code. pretty please! thanks in advanceeeeeee~~

Nazerikson97 (author)2017-06-04

Hi sir, I have a similar idea for an upcoming school project, I would really appreciate your help in this as i feel your designs are excellent. I would like to know the cost of the components and the code you use for it. Any other information on how you manufacture this device will be thoroughly appreciated.

majidrayan (author)2017-05-19

hi sir.. can you send me the code for this project? cuz i need it to make my final year project.. thanks sir

IffaA1 (author)2017-05-01

Can you email to me this project

mm69 (author)2017-04-10

Can someone please send me the code for this. I found it very interesting and practical and would like to try it out at home; but the problem, you see, is that i'm an amateur at arduino coding and would really like to have a code to see how it works and to refer to so i can modify it according to my need. Please send the code to email ID : Thanks in advance!

FarEast97 (author)2017-04-04

hello sir. can you send me the entire code? i really need it for my final year project..

Heng Yin Qi (author)2016-08-04

Hi!! :) please send me the Arduino code for this project :)

hoping for a response! God bless u! :)

reajithk (author)2016-07-18

Sir, i am very wall impressed with your project,

can you please share details of this project,

so that i can use it for my final year project

mail ID

engrcadag13 (author)2015-08-16

Hi!! :) please send me the Arduino code for this project :)

hoping for a response :) God Bless :) :)

mahirrahman (author)engrcadag132015-11-01


Please send me the code on e-mail: along with cct and motor types.

God Bless you

anjaliwani (author)2015-09-08

zaty (author)2015-08-11

hi ! your project really amazing . if you dont mind , can you list all the component that you used for this project ? thank you very much for your help: )

macnilrad (author)2015-07-22

hi author! your project was very very amazing !! i've decided to built one of this for my granny..Its hard to build this without the ciruit and a program, can you upload them author?? please??

nageshsp (author)2015-07-04

Can you please post arduino code of this project?

PremK6 (author)2015-06-08

will you please send me the programming, component list and their approximate cost and other details of this project my email is a huge thank you to you!

vikrankrishnan (author)2015-04-08

Hi, can i get arduino code of this project...

AHMADS14 (author)2015-04-08

hye there..i really love your project..thus,my team and i have decided to use your idea for our project.can you please email me the complete coding,circuit diagram and anything that is needed to complete this project?my email is really hope u can help us.

haidangvipro (author)2015-03-05

hi, this is a very nice project...please can you send me the complete code, circuit diagram and how you designed the hardware, anything to help me do this project....this is my email:(

arahman37 (author)2015-02-03

This looks fantastic! I will be making a pill dispenser for my final year project. It will be controlled by raspberry pi instead of a microcontroller. I have found your example to be very useful. Are there any chance of you having knowledge of raspberry pi? I look forward to hearing from you soon.

janw (author)arahman372015-02-03

I have worked with raspi before. It might be a bit overkill for a project like this but maybe you are planning extra features.

arahman37 (author)janw2015-02-05

Thank you for the reply. I am planning to make a pill dispenser that will be circular in shape, with segments to hold the medications. The rotation of the box will be controlled by a stepper motor which in turn will be controlled by the raspberry pi. It would require an LED desplay and switches which will be used to set the specific times. I don't know how it would be made possible. I was wondering if I would require a clock like yours maybe? I would be very grateful if you could just give me an idea please since you have worked with raspberry pi before. I look forward to hearing from you.

janw (author)arahman372015-02-05

I personally wouldn't use a raspi for that. I would use an arduino or just a microcontroller.

bchu31 (author)2014-10-28

Hi sir I'm am very very interested in the project that you've and made and I am deciding to make one in my final year project. But I need some of the stuff from you. You could contact me at my email,
I'm lookin forward to your reply.

kotosif (author)2014-09-29

It's been a while since you posted this instructable but I was wondering if it was possible to take a look at your code? Thanks.

heebey (author)2013-05-15

Is it possible at all to get the code for this project?

Thank you.

esoolo (author)2013-04-14

The system could also have only one stepper motor, if all the dispensing drums were linked to each other via a pair of pins like the disks in a combination lock:

simjan (author)2013-03-20

Hi, just wanted to know what kind of motors are you using?
I take it you are using bipolar stepper motors? also how many phases are each of the motors?

janw (author)simjan2013-03-21

Good question. It took me a long time to figure out what motors they were (I got a batch of them very cheaply for somewhere). The motors have 3 coils with internally connected common. So 4 wires: 1 common and 1 for each coil. They have only 15 steps so they really 'jump' from step to step but that was not a problem in this machine but I wouldn't recommend them for CNC stuff.

Alapakiboy (author)2012-03-30

Im helping my friend develop something similar for her senior project and she is planning on using it for grandmother afterwards. Would it be possible if you can help us out with the parts list & how the programming was done. We are planning on adding few more features in it as well and ur help would give us more time to spend on the new features. Your help would be greatly appreciated.
I have built an RC controlled lawmower recently that I can share the instructions for if you like to build one..heeh
Here is my email:

jevans10 (author)2012-02-03

Great Job! Do yoiu mind adding me to the list please?.

rainbowangel (author)2012-01-16

please give me the codes...:( for avr...coding is very tedious..going wrong all time..anyone who did it can u give the codes?. id is
need it urgently as i am doing this as my project:)

Rahul16 (author)2011-01-22

hi, i have completed the coding and used PROTEUS Software to simulate the design. but the clock is slow compare to real time clock. can u tell me what frequency oscillator is used for both atmega and ds1307. and also specify current rating for power source for microcontroller and stepper motor driver.

rainbowangel (author)Rahul162011-12-27

if you have the code for this pill dispenser..will you please mail it to me?need it urgently for my my mail..
please sent it:) need it asap...

janw (author)Rahul162011-01-22

Hi congrats with your simulation. I am still hoping to rewrite the code but my little newborn daughter sucks up a lot of my time so it will take time.

The clockspeed of the atmega is 8Mhz and is generated by the internal oscillator.

The DS1307 uses a 32.768Khz crystal as requested in the datasheet.

I used a 12V 2A supply for this project. I had it lying around and it was enough so I have to recalculate how much the project really needs to give you the exact current

Rahul16 (author)janw2011-01-22

thanks for info, so u mean i dont need to connect external oscillator for atmega. and one more thing the main input consist of two supplies (12 v and 9 v). so the current rating is same for both. i thought giving it a advance feature like remote control setting of alarm time using IR Remote and adding a digital thermometer . hows that?

janw (author)Rahul162011-01-23

You do not need an external oscillator indeed. You only need 1 of the 2 supplies, go for 12V, the 9V is for a backup battery.

Adding a temperature sensor is very easy. use an I2C one and just hook it up to the same lines as the DS1307. The datasheet will provide you with the correct way of adressing it.

I have not much experience with IR controles but I am sure that you can figure it out.

Rahul16 (author)janw2011-01-22

hi again, actually i m troubling with stepper motor rotation. the program i designed is just for rotating stepper motor for certain angle. and when alarm clicks again it goes back to initial position and rotates for same step angle. i need your help in this part , i want it to remember the position (angle) it had already rotated and start from same angle in place of going to back to initial position (angle). hope u understood my problem. please help me with this part of programing.

janw (author)Rahul162011-01-23

It shouldn't jump back indeed. The steppers I bought came without any information and have 4 leads. By testing them, I found out that they have 3 coils + a common GND and that they have 15 steps in a full rotation. Instead of giving pulses to a stepperdriver, I connected PB0 to PB2 to each coil via a motordriver.

The pinnumbr of the port is placed in variable i and then you can state something like (This is how it works in Bascom):

PORTB.i = 1 to activate a coil and PORTB.i = 0 to deactivate it. By placing it in the variable i, the program will always know what the last coil was and by increasing, you go forward, by decreasing you go back.

cpetrep (author)2011-10-03

Could you send me a copy of the specifications?
The sizes of the drums and the code
I am trying to complete a project for my digital II class similar to this.
Thank you

bryandhispup (author)2011-08-03

I could really use one of these but I know Diddly about circutry and microcontrollers and etc... good thing I was friends with all kinds of people in HS and I didn't burn my bridges with the "nerds". I just hope one would be willing to make this for me about cheap as free... LOL Great Job!

About This Instructable




Bio: I'm mainly interested in music, food and electronics but I like to read and learn about a lot more than that.
More by janw:Pickled ChilliesExtra hot sriracha sauce (Mme Jeanette)Build a Nest Box for Bumblebees
Add instructable to: