Smart Medication Dispenser with Arduino

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.



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



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.


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.

circular.png Figure 2 – 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.

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


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.


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.


Figure 6 – Dispenser’s main 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 to:
My coordinator, professor Renato Nunes, for helping me through the whole project;
My friend Pedro Marques, for designing the 3D structure of the dispenser;
Glintt Engineering, for offering me the 3D printings.


14 Replies to “Smart Medication Dispenser with Arduino”

    1. It’s a very good idea, it would be very useful for people who are not at home the whole day or can’t take their pets when they go on vacation!
      The problem is the price of the physical structure, creating the molds would need some serious investment.


  1. You are right, turning the prototype into a product is a big step and requires appropriate funding. This does sound like a very good idea though, with a range of practical applications. I think it would be worth speaking to someone knowledgeable about the process.

    Liked by 1 person

    1. That’s true, it would need a big investment in molds and in testing, since it deals with medication.

      Nevertheless, the electronics of this project costed about 60 euros, from which 20 euros are the price of the GSM module, which is not mandatory.
      Besides that, all of the components were bought in small quantities and I couldn’t use SMD components due to the lack of proper soldering tools.
      I think it’s a reasonable price for a prototype and taking into account the cost of other products in the market.

      If someone with knowledge about the process could give his opinion, I would appreciate 🙂


  2. Prefect bro, we are doing same project right now but structure and functioning is completely different. I think iam only one doing this first but you already did it bro. So i need some suggestions from you mainly what is the feedback of project form people and any commercial product developed??? Plus cost bro. Please answer these or given any mail/mobile number bro.

    Liked by 1 person

    1. Hi!
      This was a prototype, unfortunately I never created a product due to the costs involved and the lack of investment.

      The problem with a project such as this is the scale. To put this in production, it would need some serious investment in plastic molds, to produce the output units.

      So, although the electronic for this was very cheap (and it would be even cheaper today) and each dispenser unit would be also cheap, the initial investment would be high, I guess something around 100 k (rough estimation).

      Added to that, at least here in Portugal, medical equipment needs to undergo very strict quality tests, so that would add to the price.

      It’s not easy to put a medical device such as this on the market 🙂

      Hopefully you and your team succeed on doing it. This would be very good since at least here in portugal we have a lot of elderly who would benefit from something as this.

      Unfortunately, there’s lots of people having health issues due to the fact that they cannot take the medication at the correct time or take it wrongly, and some of these issues can be very serious.

      Regarding feedback, I’ve approached some people that worked with health (doctors, nurses, caregivers) and they all told that this was indeed a very good ideia that could help solve the medication compliance problem.

      Good luck with your project,
      Nuno Santos


  3. very nice project!
    i was thinking something very similar, with other Internet Of Things implementations, but because i will do this as part of a bigger project, im curious to ask you two questions..firstly, did you have any prior technical knowledge? I know the basic concept of arduino, and good enough C programming, but no curcuits knowledge. Do you think it can be possible to learn the necessary for a proejct like this in a small amount of time? Second question is, how much time did the whole thing took you?

    thank you in advance

    Liked by 1 person

    1. Hi!

      Thank you very much 🙂

      That’s a very good area to work in today, both IoT and assistive technologies, so it is a good choice of yours

      Yes, I had some prior knowledge in programming, microcontrollers and some electronics, although I was no specialist in any of those areas (and I’m still not 🙂 ). So I’ve learned a lot trough the process.

      It took me around 7 months more or less, but I did this project as my masters thesis, so I took a considerable amount of time to analyse the state of the art and what to put in the dispenser, plus writing the whole dissertation.

      Nonetheless, it had indeed a lot of programming / electronics work, specially in controlling the mechanical part, which was by far the greatest challenge.

      Another tough challenge was working with the WiFi. At the time, the ESP8266 was being sold at eBay as a generic “WiFi to Serial Bridge” for Arduino, so it also took me a lot of time to find tools to make it work with enough reliability.

      One thing to highlight is that the end result was a prototype and not a production ready product.

      I think it is possible to learn the necessary to make a project like this (a prototype) in a small amount of time if you dedicate a fair amount of time to it 🙂

      If you already know C and Arduino, then you have a pretty good starting point. You can learn a lot about circuits around the web so that should not be a problem, just stay safe when working with electricity and ask someone if you are not sure about something. 🙂

      Even if you don’t achieve the end result you were aiming, I’m sure you will learn a lot int he process like I did, and that knowledge will be very valuable.

      In my case, I’ve originally started this blog to document much of the stuff I’ve learned during the creation of this project.

      Of course that if you are aiming to develop a product for selling, then I think it will be much harder to do it in a small amount of time.

      First, there’s the need for creating all the mechanical structure (in my case, it was designed by a friend of mine who is a mechanical engineering).

      Then, you need to take in consideration that software related with health needs to pass a lot of certifications (at least here in Portugal), so it takes a lot of time to make sure everything is accordingly to the rules and specifications.

      In either cases, my suggestion is to give it a try and enjoy the process to learn a lot, I’m sure in the end you will be happy, no matter what the outcome is 🙂

      Best regards,
      Nuno Santos


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s