Smart Medication Dispenser with Arduino

Introduction

This post describes a prototype of a smart medication dispenser, created with an Arduino as the controlling unit. The hardware platform and the software to support all the functionalities were created from scratch. Some of the functionalities include the possibility to connect the dispenser to a smartphone using HC-06 Bluetooth module, or to communicate with a remote server through the internet, using ESP8266 Wi-Fi module.

Why creating a medication dispenser?

Nowadays, people take great amounts of medication, in order to have a better life quality. This is specially true amongst older people, who tend to have more complex medication regimens. With the increasing of age, people tend to have more difficulty in following those regimens, which can lead to  errors when taking medication, a problem that can cause serious health consequences.

The objective of this project was to create a prototype of a smart medication dispenser to help manage the treatments of older people. Besides that we wanted to have a solution that caregivers could easily use and that allowed them to remotely accompany the compliance to the treatment.

Some solutions in the market

Since the lack of compliance to medication regimens is a problem identified a long time ago, there are already some solutions available in the market. So, the aim of this project was not to reinvent the wheel but rather to develop an incremental solution that could mitigate some of the limitations found in those products, and also to add some innovative features.

So, we tried to develop a flexible and open solution, that could be used in multiple environments and integrated by other parties in their services.

Functionalities

  •  Possibility of defining 28 alarms for medication dispenses. For each alarm, it is possible to define the firing date and time, without limiting the number of alarms per day. Each alarm has a compartment associated in the physical structure of the dispenser, where the pills are stored for each dose.
  • Possibility of defining a maximum tolerance time for the user to retrieve the medication. After that time, if not dispensed, the dose is considered failed.
  • Possibility of configuring the alarms using a simplified mode (called daily mode) where the caregiver just needs to specify the firing time of the alarms for a day. The configured alarms will repeat every day, making it adequate for regular regimens.
  • Possibility of managing PRN medication (medication taken only when needed), by defining a minimum safety interval between doses.
  • Medication dispensing is done just by pressing a button.
  • Alarms are signaled by a flashing light and a beeping sound. The intensity and the “on/off” pattern of both visual and audio signals can be configured accordingly to the user’s preferences.
  • Recording pertinent information of operation, such as dispense time of medications or attempts of getting dispenses outside the configured time.
  • Bluetooth support, allowing communication with a smartphone, tablet or computer.
  • Wi-Fi support, allowing communication through the Internet. This allows the remote configuration of the dispenser and sending notifications to the caregiver.
  • GSM support, allowing the sending of remote notifications through SMS and the possibility to make voice calls to/from the dispenser.
  • Possibility of direct interaction with the dispenser, using its keypad and display, to configure it and to access registered information.
  • Creation of a generic API that simplifies the interaction of external devices with the dispenser, allowing its configuration and download of recorded information.

Architecture

In order to simplify the development process and to facilitate changes in the code, a modular architecture for the dispenser was developed, as shown in figure 1.

Smart medication dispenser architecture.
Figure 1 – Dispenser’s architecture.

The processing module is the entity that controls all the others modules and was implemented using an Arduino Mega 2560 board. The choice of Arduino was related to the support given by its community, which offers a vast amount of libraries and tutorials, making the development much easier.

The information recording module was implemented using Arduino’s EEPROM. The Mega Board offers 4 KB of non-volatile memory, which was enough to support all the functionalities, such as storing the time when a medication compartment is dispensed.

The alarms are signaled using a LED and a buzzer and the user just has to press a button when an alarm fires in order for the pills of that dose to be dispensed.

The keypad and the display are used as a direct interface with the dispenser, where the caregiver can configure it or access registered information. Besides that, the display can be used to show a message to the user, associated with the alarms. For example, we can write a message such as “Take the pills with water”.

The mechanical actuation was implemented using a stepper motor, which is used to move a circular structure divided in the medication compartments, as shown in figure 2. This approach is used by many of the commercial solutions available.

The stepper motor used was a 28BYJ-48, which is a very cheap choice that operates at 5 V and has a precision of about 0.088º per step.

Smart medication dispenser circular structure
 Figure 2 – Smart medication dispenser circular structure.

We decided to implement the feedback mechanism with an extrusion in the circular structure, which marks a reference compartment. This extrusion will be detected by an optocoupler (model ITR9608 from Everlight).

Since dispensing the medication at the correct time was a crucial requirement, we decided to use a DS3231 Real Time Clock, in order to complement the time-keeping algorithm used.
The remaining modules will be described below.

Bluetooth module

The Bluetooth module was implemented using HC-06, a cheap serial-Bluetooth bridge for microcontrollers. This device allows the emulation of a serial communication over Bluetooth, which is used by the dispenser to communicate with devices such as computers, smartphones and tablets without using wires.

The goal of this interface was to allow the development of remote applications that could be used to guide the caregiver in the configuration and information retrieving processes, avoiding the need to use the keypad and the LCD display of the dispenser. Figure 3 shows a custom application that we developed for android, using an API we created over a serial protocol, which allows the configuration of the device.

Android application (menus are in Portuguese)
Figure 3 – Android application. Menus are in Portuguese.

Wi-Fi module

The possibility of connecting the dispenser to the internet was implemented using the ESP8266 module. This tiny and cheap device is a microcontroller that can connect to the internet using Wi-Fi. It can be used to develop standalone applications or as a serial to Wi-Fi bridge, which was the case.

Once connected to a router, the ESP8266 can establish or receive socket connections, allowing it to easily change data with a remote server/client. Although HTTP communication can be implement on top of the socket interface, we opted to implement a byte oriented protocol, to decrease the overhead. This communication is supported through a Python API we developed.

Through this interface, we allow the dispenser to send remote event notifications to a server, which then can be sent to the caregiver. Besides that, we allow the caregiver to remotely configure the dispenser.

Figure 4 illustrates an architecture that allows the dispenser to communicate over the internet.

Architecture that illustrates the exchange of data through the internet.
Figure 4 – Architecture that illustrates the exchange of data through the internet.

GSM module

The GSM module was implemented using the SIM900 device. It can receive AT commands though its serial port, allowing for a microcontroller to control it. Those commands include sending SMS and making/receiving phone calls.

So, the SIM900 is used by the dispenser to send textual messages to the caregiver, informing him of events that occur during the operation, such as doses taken or missed. Besides that, since the SIM900 is a relatively expensive device, we decided to allow the dispenser to receive and make phone calls. Using this interface, the caregiver can call the user to check if everything is alright, which is a pertinent functionality if the user is not able to use a phone. The user can also start a call, which is important in case of an emergency.

In order to answer or start a call, the user just needs to press a button, which is a fairly simple interface.

The result

The mechanical structure of the final prototype was impressed using a 3D printer, as shown in figure 5.

3D structure of the prototype (menus are in Portuguese)
Figure 5 – 3D structure of the prototype. Menus are in Portuguese.

The final circuit of the dispenser is shown in figure 6, and the power supply circuitry, which supports battery and power grid supply, is shown in figure 7.

Dispenser's main circuit.
Figure 6 – Dispenser’s main circuit.
Dispenser's power supply circuit.
Figure 7 – Dispenser’s power supply circuit.

This video shows the Android app controlling the circular structure that has the medication:

This video shows the process of turning on/off the LCD or just its back light, to save energy:

There are more videos on my youtube channel.

Special thanks

My coordinator, professor Renato Nunes, for helping me through the whole project;
My best friend Pedro Marques, for designing the 3D structure of the dispenser;
Glintt Engineering, for offering me the 3D printings.

29 thoughts on “Smart Medication Dispenser with Arduino”

Leave a Reply to Siva GaneshCancel reply

Discover more from techtutorialsx

Subscribe now to keep reading and get access to the full archive.

Continue reading