The Automatic Medication Dispencer





Introduction: The Automatic Medication Dispencer

About: I'm mainly interested in music, food and electronics but I like to read and learn about a lot more than that.

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?

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

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.

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

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

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.

Humana Health by Design Contest

First Prize in the
Humana Health by Design Contest



    • Woodworking Contest

      Woodworking Contest
    • Oil Contest

      Oil Contest
    • Planter Challenge

      Planter Challenge

    We have a be nice policy.
    Please be positive and constructive.





    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.

    11 replies

    did you finish the code yet? if so could you please tell me.

    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.

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

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

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

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

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

    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

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

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

    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~~

    please! i would request the code and block diagram of this project.

    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.

    6 replies

    Bro send the code please

    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...


    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

    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?


    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.

    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.