Introduction: 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?
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
- 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.
- 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.
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
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.
Setup:
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.

First Prize in the
Humana Health by Design Contest
204 Comments
12 years ago on Introduction
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.
Reply 5 years ago
did you finish the code yet? if so could you please tell me.
Reply 5 years ago
Hello. This is very innovative. Could you please tell the microcontroller you have used and also send the code to the email
shruthibhaskaran@gmail.com
Thank you in advance.
Reply 5 years ago
hi sir.. can you send me the code for this project? cuz i need it to make my final year project.. thanks sir
mohd.faiz2307@gmail.com
Reply 6 years ago
sir can you send the code for this project to my email idzhamyahaya97@gmail.com
Reply 6 years ago
sir im very impressed with your, can u give me the code and other materials used in project
cherukushreya96@gmail.com
Reply 6 years ago
Sir, i would also like to ask about the specific materials used in this project. thank you very much. Vincewantuten@gmail.com
Reply 6 years ago
Good day sir, could you kindly give me the code for this particular project. Vincewantuten@gmail.com
Reply 6 years ago
i liked the project very much so i need the project code. plz forward to my mail shilpa.s.rathod25@gmail.com. where can i get the components? for this project
Reply 7 years ago on Introduction
hi sir, would u please send the code? my email amboihadoi@gmail.com
Reply 7 years ago on Introduction
sir, would you please send the code for this project? this is my emails
cjdescorial@usm.edu.ph
macnilrad@gmail.com
Reply 8 years ago on Introduction
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~~
2 years ago
Hi I am from India and I have completed the project but unfortunately i am from Mechanical Branch so i am not able to write a code can someone please send me its code i ll be grateful.
My mail ID is anhadsatsangi123@gmail.com
3 years ago
i have gone through all the details of your project and its really nice one.
can i get the code please? my email-id- rahul.bose1597@gmail.com
3 years ago
Sir please send code to my email id
janrdhana994@gmail.com
3 years ago
please give me the code and full detail
4 years ago
Hi can you please send the code for this project, I found your project interesting and I want to make one for my school project
mmihrija1997@gmail.com
4 years ago
Hello,
I have a few questions about the "Automatic Medication Dispenser", as shown in this link: https://www.instructables.com/id/The-Automatic-Me...
Under the heading of "Setup", what it says is shown below:
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.
"THE OTHER VARIABLE" gives the value of WHAT in this case?
Also, under the heading of "start up", it says the following:
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.
WHAT DOES "bit 7 of register 0 (oscilloscope enable bit) to 0" mean?
Finally, what programming language did you use to program this? Can you send me step-by-step programming instructions for the "Automatic Medication Dispenser"? Can you also send me programming instructions if I were to make two of them and put them together so they can last a fortnight?
4 years ago
please! i would request the code and block diagram of this project.
12 years ago on Introduction
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.
thanks.