Smart Medicine Box

Our ECE 4760 final project is to build a microcontroller based smart medicine box. Our medicine box is targeted on users who regularly take drugs or vitamin supplements, or nurses who take care of the older or patients. Our medicine box is programmable that allows nurses or users to specify the pill quantity and day to take pills, and the serve times for each day. Our smart medicine box contains seven separate sub-boxes. Therefore, nurses or users can set information for seven different pills. When the pill quantity and time have been set, the medicine box will remind users or patients to take pills using sound and light. The specific number of pills needs to be taken will be displayed by a seven segment led display placed on the corresponding sub-box. Compared with the traditional pill box that requires users or nurses to load the box every day or every week. Our smart medicine box would significantly release nurses or users’ burden on frequently preloading pills for patients or users.

High Level Design

Rationale and Inspiration

I am an international student, and during holidays I always bring some USA made medicines to my grandparents back in China. I found they always have trouble remember the number of pills they need to take from each of the medicine bottle because they couldn’t read English. They also complained to me that they sometimes forget to take to pills, and some medicines were expired due to this reason. Therefore, the idea to make a smart pillbox that would help people like my grandparents came to my mind. After I talked with my partner Jie, we broadened the targeted users of our pillbox from just the older to people who regularly take pills. We also thought nurses who take care of patients could also benefit from, since they also regularly prepare pills for patients. After the targeted user being defined, we then defined the specifications of our device based on the user needs. The device should be able to generate loud sound so that even people with impaired hearing were able to hear it. The device should demonstrate ease of use. Therefore, we decided to use a LCD and a keypad as the user interface. In order to help user remember the number of pills they need to take, we also used several seven segment LED displays to indicate the number of pills the user need to take. Based on theses specifications, we designed a high-level block diagram (figure below) to demonstrate the overall design of our device.

There are five major components for our device, including a pill box containing seven separate small boxes; a speaker module; a 3×4 keypad; an Atmel 1284p microcontroller; seven segment LED display (7 units); and a 2×16 characters LCD screen.
Functionality of each component:
Keypad: Keypad is used for the user or nurse to enter the information of time when the smart box would send “reminder” (displaying numbers and playing sythsized voice). It is also used for the user to enter a number to command a specific pill box to open on a specific day. (say, open No.1 pill box on Monday), and user can also enter the freuency infromation to take pills for each day. The keypad is also used for stopping the music and led display when the user has taken the pill.  LCD: The 2 line, 16 characters LCD screen is used to display the instruction information, the number of pills need to be taken, and the current time and date.Speaker Module: The speaker module is used to play the sythesized sound to remind the user to take pill.
Pill boxes: We used a pillbox system containing 7 separate small pillboxes. Each box has a seven segment led dispaly placed on the box. For our pill system, the user can store up to seven different types of pills, which can be stored in those seven small separate boxes. He or she can also specify the different combinations of pill boxes to be open for each day.
Microcontroller: One Atmel 1284p is used to execute all the commands mentioned above.

Logical Structure

Our device uses the state machine and real time clock (RTC) to provide real-time functionality. This state machine determines which key has been pressed and provides keypad debounce functionality. We use the 16MHz external oscillator to build a real time clock for the device. Since the accuracy for the external crystal oscillator has a very high accuracy, and based on our calculation, our RTC should only delay about several minutes in a week. Such error is tolerable, since we not particularly used the RTC as an alarm clock.

The device’s logic structure contains three major stages: 1. User initialization stage. 2. Comparison stage. 3. Reminder stage. In the user initialization stage, the user enters the current time, date and pill information (including amount and serve time for each type of pill). After the user finishing entering all the information, the device will enter the comparison stage unless the initialization button is pressed. During the comparison stage, the system compares the pill information for each of the sub-box with the time counted by RTC. Once the information entered by the user matches the RTC time, the system will jump out of comparison stage and enter the reminder stage. In the reminder stage, the device will continuously play synthesized voice, and the seven segments LED display will show the number of pills needs to be taken on each of the sub-box.

Hardware Tradeoffs

Initially, we planned to use electrical magnetic solenoids to control the open and close of the lids for each of the sub- boxes. However, the size of the solenoids available is not desirable to be attached to the box, and shipping time for the solenoids is also too long. Therefore, we decided to replace the solenoids with the seven segment led displays to achieve the same functionality, which is to improve ease of use of the device.

Since we want to use one microcontroller to achieve all the functionality, tradeoffs need to be made between saving pins and complicating the circuits. The 1284p microcontroller has 4 ports, 28 pins total. The LCD module needs 8 pins and the keypad needs 7 pins. The speaker module needs a specific pin that is able to send PWM wave. Currently, we used a seven sub-boxes system. If we directly use microcontroller to control all seven segment LED displays, The rest 2 ports would just be enough. However, if we need to add more features or add more sub-boxes, this control mechanism of led displays is definitely inefficient. Therefore, we decided to use the 74LS138 3 to 8 decoder to control the switches (in this case are 2N3904 npn transistors) for those LED displays. Using 3 to 8 decoder could save us 4 additional pins for future add on features or sub-box. However, using 74LS138 would complicate the circuitry design. Current, we built the external circuitry on breadboard due to the limitation of time. In the future, customized PCB board can be used to simplify the circuitry as well as miniaturize the device size.

Software Tradeoffs

When we displayed instructions on the LCD screen during initialization process, we previously used the scheme developed in lab 2, that we showed the static texts and dynamic input at the same time. However, due to the large amount of parameters in our system, we cannot use this scheme anymore because that made the response of keypad extremely slow. Hence, we developed a new scheme for the instruction texts display that will only show the static characters once at the beginning of each status and this method achieved much better result for the response speed of keypad.

Existing Products

We found several different pillbox products available in the market. The cheapest one was the traditional pillbox, which contained seven boxes for seven different days of a week. Such pillbox normally cost below $10. However, user had to load the pills to the boxes every week. Mixing different pills in the same box would increase the risk of making mistakes. We also found another type of pillbox, which had the sound reminder, and was able to remind the user to take medicine at user specified time. However, the users still have to put different kinds of pills in the same box, and reload the boxes every week. Additionally, It could only remind the user to take pills once a day. The average costs of this type of pillbox were about $50, which was still expensive than ours. Therefore, we think it was necessary to build a cheap and functional smart pillbox that could bring more convenience for the user.

Software Design

Overall Software design

We built a medicine box with an integrated software system running in the MCU. The programming platform is AVRStudio4.0, and programming language is standard C and WINAVR/GCC compiler. Generally, our sofyware system can be divided into four parts, including real time clock, user interface, LED control and sound generation. We could get information for each medicine boxes from the user input and store the information in structure variables. The real time clock would keep running once user finishes initialization. After all the information has been entered. The system would enter comparison status. The comparison function would detect if there are medicine should be taken at that time. When it finds medicine should be taken, the audio will broadcast. After the user response to the system by pushing certain button, LEDs would indicate the amount of medicines for each box. Our system flow chart is as follow.

Data structure

The information of boxes will be stored in structs. For each box, we have a struct to store their information.  The struct contains four variables that indicate which day this medicine should be taken, how many times per day it should be taken, the amount it should be taken each time and a variable that using later by function that control the LEDs to indicate whether the LED of this box should be light up.

Real time clock

The real time clock running in our system is implemented by using MCU 16-bits timer to generate 1-second base. Firstly, we will open the compare match interrupt service routine, and set the compare value to 249. Also, we scale the running frequency of timer1 to 1/64. Then, the interval time between each interrupt routine is 0.001 second. We have a volatile variable to run the clock function every 1000 interrupt routines. Then, in the clock function, it will run like a clock. We have separated variable for two digits of seconds, minutes and one variable for hours. We also have a variable for the weekdays. We do not store the year information because we think it is unnecessary

User interface

The user interface is made up of two main components, user input and system output. User input method is keypad typing. System output methods are LCD display and LED digits display, as well as audio broadcast.

LCD Control

The LCD library lcd_lib.c and lcd_lib.h are from Scienceprog.com. The functions in the library already finish the fundamental tasks, such as showing characters on the screen, clean screen, etc. We use these functions in the library to implement our own system.

Keypad control

For the aim of obtaining the button that is pushed, we have a function for scanning the keypad. Firstly, set high-4 bits of port to input and low-4 bits to output and get the value of the high-4 bits, then, inversely do the same task and get the whole value of port. Then using this value we get to look up the button table to find out which button we pushed. The state machine will execute every 25 milliseconds. In state detect, we will judge which kind of button is pushed and do different things corresponding to the button, such as run flag setting, input string updating and changing to next parameter input. In the done state, we will update each variable in each box’s structure, and also, we will initialize some variable for the next round parameter input. Other states in the machine do not have specific function but debounce.

LED control

We use port A of microcontroller to transfer the data for seven segments LED and first three bits of port B to transfer the control signal for the multiplexer. Hence, Our function related to LED control is mainly controlling all this bits mentions above. Depends on the principle of persistence of vision, we will show the data of each LED for a short time and then switch to the next one, and doing this again and again to keep the LED lighting up. In our system, the function called led() will execute this task according to the scheme mentions above. It will run every 4 milliseconds when the system running at triggered state.

Sound generation

For the sound generation, we use the method called differential, pulse-code modulation (DPCM) that is linked in the ECE 4760 homepage. For the generation process, we have timer 0 to working at PWM mode and timer 2 working at compare match status in order to simulate the human speaking sound. We used the Matlab code to generate the sound data table of the sound we need that is ‘Time to take medicine’.

Hardware Design

Microcontroller

The microcontroller used for the smart medicine box is the ATmega1284 mounted on a custom PCB. We used port A for outputting numbers on led displays; port B for controlling the switches and speaker module; port C for the LCD module; and Port D for keypad.

LCD module

The LCD module used in our project is a 16-characters, 2 lines Microtivity IM161 (with back light). Considering its small size, ease of use and its yellow back, we think it is the best candidate for our project. We found the yellow back light make it easier for the user to see the characters displayed on it, even in the dark environment. Currently, we didn’t have the back light adjustment feature in our circuit. In the future, we will add this feature to our device so that the user can dim the backlight during certain circumstances.
Pin 1 of the LCD module is connected to the ground. Pin2 is connected to the power supply of the MCU. Pin 3 connects to the wiper of the 10k trimpot. Pin 4 is the register select, which is connected to the C.0. Pin 5 is the data read/write, which is connected to C.1. Pin 6 is the enable signal, which is connected to C.2. Pin 11 to pin 14 are the data bus, which are connected to C.3-C.7. Pin15 and pin16 are the LED power and ground for the backlight. The optimal power and current for the led backlight is 4.2V and 20mA.

lcd module used in our project

LCD module link

Keypad

The key pad we used for our decvice is a 3×4 12 button keypad, which is purchased from all electronics. In the software design we will explain the kay scan algorithm in detail.

Seven segment led displays

We used Kingbright SC56-11EWA seven segment led displays for displaying the number of pills the user need to take from each of the sub-box. SC56-11EWA is a common cathode led display, which has seven pins corresponding to seven differnt segments on the display and two pins as the groud. We designed a circuits that allows us to use only 10 pins of the microcontroller to control all seven units of these led displays(See figure below). The concept behind this circuitry design is to use transostors as switches to turn the led displays on and off sequetially. Such method can be realized with the use of a 3 to 8 decoder, which uses 3 pins from the microcontroller to send 7 bits output to control the transisotors. And the rest seven pins from the microcontroller are used to send binary outputs to control the seven segment led display one at a time. In our first prototye circuits, we used pnp transistors as swtiches, since the 3 to 8 decoder can only generate one low output each time. We tested the citcuits on a breadboard with three led displays, and they all worked properly. However, after we soldered the first prototype citcuits with all seven led displays on it, we found the last three led displays were always much dimmer than the rest led displays. After we talked with Bruce about our circuit problem, he suggested us to redesign the circuits using npn transistosr and inverters instead. We then built our second prototype circuits on the breadboards due to the time limitation. The second prototype worked properly after we tested it.

Speaker Module and Audio Amplification Circuitry

We used a speaker module acquired from ECE digital lab, but the output from the microcontroller was not large enough to drive it. Therefore, we used a sound amplification circuitry based on a LM386 N-1 audio amplifier to amplify the sound from the microcontroller (see figure below). After we implemented the audio amplification circuitry, we were able to generate a much louder sound from the speaker module, and we were also able t adjust the sound amplitude.

Results

Over Performance

The overall performance of our device was satisfied. The device was packaged in a paper box, which was a little bit large for the device. However, it was able to cover all the messy wires and electrical components, so that the user would not be distracted. Moreover, the paper box also provided certain isolation ability to lower the electrical shock risks. The lcd module and keypad were mounted on the surface of the paper box. When the power is on, the lcd would display characters with the gentle yellow backlight, which allows the user to recognize the characters on the screen even in dark environment. With the implementation of statemachine, the keypad responded promptly and accurately when we pressed the buttons. The long press and backspace features went well during the initialization stage. The seven units of seven segment led displays were placed inside the box since they were embedded on the breadboard. We filled some hard sponge under the breadboard, so that the led displays were close to the surface of the paper box.The light intensity of led displays was satisfied, that the number displayed can be easily recognized even when lab’s fluorescent lamps were all on. During the test, we found that the light intensity for some led displays was a liitle different than the others, but this would not affect the users to recognize the numebers displayed. The speaker was able to produce clear and loud sythesized sound when the comparison stage was triggered. When the “#” key was pressed, the sound stopped, and we were able to see led displays show corresponding numbers without any fliker.

User Evaluation (Useability)

Since our smart pill box is intended to be used by the user who does not have any electrical engineering background or is not able to operate a complicate system. Therefore, the user evaluation is crucial for our project in terms of future improvements. We planned to do two rounds of user evaluation, first round is focused on collecting feedbacks from people who have strong learning ability and set the pill information by themselves. Second round of evelation is focused on collecting feedbacks from users who does not have strong learning ability and need others’ help to set the pill information.

We invited some of our friends as our fisrt round users to try our device and give us some feedbacks. Due to the limitation space for displaying characters on LCD, we were not able to display the instructions on the lcd screen. Therefore, users needed to have some quick learning on how to use the device. After around five minutes of learning, tester were able to set the real time clock, and pill information for each of the medicine box with out any difficulty. In the future, we would improve the user interface so that it can be more self-explainatory for the user to use. It would also be helpful to create a user manual to help the user to use the device. Besides that, our testers also thought the size of the paper box was a little big when compared with the actual pill boxes mounted on the top. Our testers also concerned that the boxes were hard to open and close. They also suggested that we should replace the pill boxes with larger ones. They also thought it would be better to place theseven segment led displays on the surface of the paper box, so that they could read the numbers displayed more easily. They also suggested that the switch of the microcontroller should also be placed outside the box and marked, since the real users might be have any knowledge about the circuitry. We created a table (see below ) inorder to list all the suggestions and comments from our testers.

Problem
Solution
Priority
words displayed on LCD are hard to understand
create a user manual and use a LCD that is able to display more words on it
high
size of the device is too big
find a smaller plastic box
medium
pill boxes are hard to open
purchase a beter one
medium
led numbers are not easy to read
place the seven segment led displays on the surface of the box
medium
the switch is hard to find
build an additional switch on the surface of the box and mark it
high
pill boxes are too small
find bigger boxes
low
Things we need to improve in the future

The priority level is rated based on how severe the problems would affect user to use the pill box.

Since our second round testers are mainly the older, we decided to conduct the evalution during the winter break.

Safety

Our device is used to contian drugs, and it is defined as a class I device based on the definition of the medical device by FDA(Link). Therefore, safety is one of the most important factor need to be considered. We should identify all the possible risks and hazards before we build the device. Validation of all the safety factors is also essential after we finish build the device. We used the analysis structure (see figure below) described in Medical Device Use-Safety: Incorporating Human Factors Engineering into Risk Managementoublished (Link) by FDA to anlyze the risks and hazards in our device.

In the identification of use-related hazard senario stage, we identified the potential hazards based on device use descripton. We found several potential hazards which would occur during the use of the device (see table below).

Hazard Description
Priority (10 is highes 1 is lowerest)
electrical shock
10
fire hazard
10
break/loose wire
6
short circuit
8

Among all the hazards, we thought electrical shock and fire hazards should have the highest priority, since these two hazards would not only cause malfunction of the device but also have high risks of causing danger to the user. In order to mitigate the risks, we decided to cover the entire circuits in an insulated box. We also planned to use high burning point material such as metal or plastic for our box in order to lower the fire risk. However, due to the time limitation, we had to choose a paper box for our current device, and we didn’t cover the entire circuitry. Therefore, we were still in the strategies implementation stage. However, for our future work, we would still stick to the analysis structure to carefully manage the risks for our device.

Conclusions

Future Work

There are several aspects we need to work on our device in the future to meet the user needs. Firstly, we should develop strategies and modify the device based on the user evalution results. This includes creating a user manual; choosing a larger lcd display; using a metal or plastic box to cover the entire circuitry; placing the swtich and led displays on the surface of the box;and using arger pill boxes.

We should also follow the risk ananlysis structure to analyze the potential risks and hazards as well as develop strategies to mitigate the risks.

Standards

There is a standard in Code of Federal Regulation (CFD) that concentrates on devices design related to food and drug (Title 21 – Food and Drugs). According to the standard, we choose the material for medicine container and other components used in the box, such as led and electromagnets. We will also design, built and code our devise based on ANSI standard and IEEE standard.

Intellectual Property Considerations

In this project, we wrote codes modified from the previous labs we did through the semester. Most of the codes were written by ourselves except the lcd_lib.c and lcd_lib.h licensed by GNU.We designed our device from scratch, and did not reverse-engineer any past designs for similar products.

Ethical Considerations

During the process of designign and building our device, we strictly adhered to the IEEE Code of Ethics. Our device does not harm one’s helth or safety, and it won’t endanger the environment. While building the device, we used all the lab equipments according to the safety requirments. While writing codes for our device, we didn’t copy anyone’s previous work. We marked the license for the lcd_lib.h and lcd_lib.c, which were provided by GNU to drive our lcd module.

In terms of the fifth item listed in the IEEE Code of Ethics, we believed we improved our understanding of designing and building medical related device. And we belived our device would help user to improve their life quality.

We also open for any critism of our device in term of its possible techical problems. We ackonledge all the helps and suggestions provided by Bruce (our instructor) and our TAs.

We are honest in collecting data from our testers, and we didn’t falsfied our verification and validation process.

Legal Considerations

We searched on the webpage of USA patent and trademark office for simillar devices. We found several petens related to the “pill box or pill dispencer”, but none of them was simillar to ours in terms of deisgn(Reference ). Therefore, we think our device does not involve any legal and patent issues.

Source: Smart Medicine Box


About The Author

Muhammad Bilal

I am a highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top