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