Automatic Medicine Dispenser using IoT

There are several challenges that old people face, and of them is taking their medicines on time. Old people usually forget to take their medication on time and also have a hard time recollecting whether they had their medication, which sometimes could lead to overdose and severe medical complications. There are several expensive medicine dispensers available in the market now. However, most of the elderly people around the world don’t even know of such products and still resort to storing the medicines in a box. Several types of medicine dispensers are available commercially worldwide. However, they have several drawbacks that requires to be resolved. These drawbacks can be resolved using a Automatic Medicine Dispenser that is reliable, affordable a nd can carry up to 2-3 weeks of medicines, in such a way that, old people won’t need to depend on someone else. The product is designed to make sure that the quantity and timing of the pills to be dispensed can be controlled and monitored using an app, which makes things easier for everyone, including for children who work abroad. Also, it offers clear c ontact bet ween the consume r and par e ntal f igures as it w ill im mediately notify the guardian in case the patient has missed pill intake. Furthermore, SMD provides the customer with a touchscreen that can be accessed as an application on their cell phone, enabling them to monitor and control the timetables and use information remo tely.


I. INTRODUCTION
Studies show that many people irrespective of age become forgetful when it comes to consuming medicines. This, seen mostly in the elderly, leads to many other life risks. This is where medicine dispensers come into play. There are different types of dispensers all of which are just implemented using solid medicines. Most of them are jut simple with no reminders etc. This paper proposes a dispenser that can dispense both solid and liquid medicine, has an app integrated with it and helps to set alarms.
One of the biggest problems in the health care industry is medication adherence. Often elderly people fail to take their medication on time and for elders with more than one medication, the chances of overdosing are considerably high. This could easily lead to catastrophic events such as permanent disability or even death. Hence, it is evident that it is a widespread problem and needs a solution. It was revealed that, in a study conducted at the University of Washington, 30.7 percent of participants disliked and 18.3 percent liked at least one drug.
. . Pill makers created special bundling so as to recognize their item from those of their rivals and fabricate brand unwaveringness. Bundling configuration regularly fused a "memory help" to help ladies in following their every day pill routine, just as styled cases to enable pills to be carefully conveyed in packs and handbags. A medicine dispenser is a device which at a predetermined time dispenses the required or the already set medication to the patient. It has proved its efficiency in improving medication adherence.
The paper aims at designing a dispenser which is non-invasive in nature and which is cost effective. In the Automatic Medicine Dispenser (AMD), when it is time to take the medicine, the device can either be designed to release the premeasured dose into a small compartment which can be easily opened, or can manually be sorted into small compartment by the patient's caretaker upon which the patient is notified when it is time. The patient is notified usually through a loud alarm signal. If the patient doesn't take the medication out of the dispenser within a specified time, it would send out more loud signals to catch the attention of the patient. This is done by connecting the arduino to the network via nodeMCU. When the time for a particular medicine to be dispensed comes, the arduino sends the signal to the respective component to dispense the respective medicine.

B. Arduino technology
An Arduino board is a kit based on a one form microcontroller. The Harvard architecture is used for the software construction of the arduino where the program code and data are provided with separate memory. These are the two memories found in an Arduino. The data memory has the data stored in it and the flash memory has the code. Arduino technology has the advantage of directly uploading the program without using a hardware programmer. This is seen to be used in many controlling or communication devices. Arduino is an open source electronics platform.

C. Firebase
It is nothing but a set of tools that are used to create, develop and evolve your application. It takes care of a large portion of those processes and services that programmers would often create on their own, but wouldn't want to, because they often like to focus on the application. The cloud hosts the processes and services like databases, authentication etc. The client SDKs provided by Firebase communicate directly with these backend services, without the need for establishing any middleware between the service and your application You will only need to write code to query the information from your client's application database while using one of the Firebase database option. This is a stark change from the usually tried and tested app development methods which usually includes writing both the backend and frontend software. The frontend code invites API endpoints which the backend presents, and the job is done by the backend codes. However, with Firebase, the usual backend goes through, putting the work into the client. Firebase Authentication deals with getting your clients signed in and recognized. This product is fundamental to getting configuration done properly, particularly in the event that you have to limit access to perclient data (which is what each application would want to do). The special thing about Firebase Authentication is that it makes it simple to perform secure logins, which is amazingly hard to execute effectively all alone. Firebase Realtime Database and Cloud Firestore gives database services. Firebase brings in SDKs to use in your application to make direct data easily accessable, expelling the requirement for that annoying middleware segment.
What's extremely unique about these databases is that they give you "realtime" updates to information as it changes in the database. You utilize the customer SDK to set up a "listener" at the location of the information your application needs to utilize, and the "listener: gets summoned with that information more than once, every time a change is noticed. This lets you keep your application's presentation new and updated, without surveying the information of intrigue.

A. Internet of Things (IoT) Technology
The Internet of Things (IoT) is the network of devices such as automobiles and home appliances containing electronics, software, actuators, and connectivity that enable these things to interact, communicate, and exchange information via the internet. They have unique identifiers (UIDs) and can transfer any amount of data across the network.
The IoT eosystem is composed of web-enabled smart devices, using senors and processors to collect or send data from their environments. The data is send or received by connecting to the IoT gateway and is analyzed in the cloud. All these devices does most of the work independently, without human intervention other than for setting up. The IoT includes expanding Internet connectivity to any spectrum of traditionally stupid or non-internet-enabled physical devices and everyday items beyond conventional devices, such as desktops, laptops, smartphones and tablets. These devices, integrated with technology can communicate and interact over the Internet and can be monitored and controlled remotely. An IoT ecosystem involves web-enabled smart devices that use integrated processors, sensors and communication equipment to collect, send and act on the information they obtain from their settings. These systems link to an IoT gateway that sends information to the cloud or to a local place and shares these information with other devices. The Internet of Things (IoT) is basically connecting the physical things with the internet and identifying other devices.
The fact that an object that an represent itself digitally becomes higher than the object itself makes IoT an important pathway. The object no longer relates solely to its customer but is now linked to adjacent objects and information from the database. If we had pcs that knew everything about activities-using information that they collected by itself, it would be possible to keep a tab on and count and most important decrease the wastes, losses and costs. It will easy to understand when to upgrade, fix or recall items and whether they're new or past their peak. Many people agree that there are links between computers , tablets and mobile phones. IoT portrays a world where you can communicate smartly and link just about everything. Often, these devices communicate with other similar machines and act on data from each other. The systems do much of the work without human intervention, except for setting them up, commanding them or giving them access to information for which individuals communicate with the systems. A complete IoT framework incorporates four particular segments: sensors/gadgets, connectivity, information processing, and an UI.
• First of all, sensors or gadgets gather information from its environment. This can be as subtle as measuring the temperature, or as complex as a comprehensive video feed. • Next, through a pathway this information is passed onto the cloud onto which the sensors are connected to. This connection is established through many ways including Bluetooth, cellular connectivity, satellite, low-power wide-area networks (LPWAN), WiFi, or connection via the Ethernet. All of these methods have different characteristics, ie. varying power consumption, range and bandwidth. Choosing which connection is the most viable comes down to the particular IoT application with them all having the same objective of passing the information to the cloud. • Once this data gets to the cloud, the software performs functions that processes the information received. This could be anything simple like checking if the received value is same as the one required or if it is within an acceptable range or anything complex like using video feed to capture or identify the required target. • Finally, in some way, the data is represented to the user like through a user alert (text, notification, e-mail, etc.).
The Internet of Medical Things (IoMT) is the use of IoT for research and observation purposes related to restorative and healthcare purposes, information assessment and examination. "Smart Healthcare", what IoMT was billed as, is for making healthcare services digitized interfacing accessible therapeutic assets and medicinal services administrations. IoT gadgets can be used efficiently to empower remote healthcare checking and emergency notifying systems. These healthcare gadgets can range from blood pressure and heart rate monitors to advanced systems capable of monitoring implants, such as pacemakers, hearing aids or even electronic wristbands. A few of the hospitals have started implementing "smart beds", those that are capable of detecting the presence of a patient and also when he/she wishes to get up. It can also modify itself to support the patient and to provide him pressure when medical attendants are not around. The fact that the U.S can spare more than $300 billion in human services consumptions yearly by expanding revenue and diminishing cost was shown in the Goldman Sachs report of 2015."Moreover, the utilization of cell phones to help therapeutic follow-up prompted the formation of 'm-health', utilized "to analyze, transfer and store health statistics from various assets, including sensors and biomedical acquisition frameworks".

A. Servo Motor
An electrical rotary actuator which has the ability to precisely push an object by controlling the angular position and velocity defines a servo motor. It pairs the functions of a regular motor with a senor for position feedback. The motor runs through servo mechanism. It is made up three parts namely an output sensor, a controlled device and a feedback system. The feedback system is a closed loop that can control the shaft's movement and final position using a positive feedback. PWM signals that are generated from the control wires control the servo motor. It has a maximum and minimum pulse and its length determines how much the motor will turn. From its initial position, it can rotate 90 degrees towards any of the two directions. The angle of rotation of the servo depends on the length of the pulse of the Control PIN which is a significance of pulse width modulation principle . In short, it can deduced that it is made up of a DC motor which is controlled by several gears and a potentiometer.

E. NodeMCU
The name Node MCU is combination of the two words "node" and "MCU" which is short term for Microcontroller unit. The firmware and the prototyping design suites are both open source platforms. A Node MCU is a very low cost platform form for IoT. The hardware is based on the ESP 12 module. It is a single board microcontroller with an operating system of XTOS. The CPU of the microcontroller is the ESP8266. The Lua scripting language is used by the firmware. The Node MCU supports 32-bit ESP module. Node MCU has a WiFi integrated board, the ESP8266, and therefore the Node MCU finds its use widely in the IoT fields. Fig.7 shows the image of NodeMCU with integrated ESP8266.   Fig.8 shows the detailed block diagram with the components used in AMD. The main components used are a servo motor, a centrifugal pump, an arduino UNO, a nodemcu and a real time clock module (RTC). The information the user adds into the app is sent to the arduino simultaneously through the nodemcu via firebase. Instantaneous time and date is calculated by the RTC connected to the arduino. The moment they becomes equal to the ones entered by the user, the arduino commands either the servo, in the case of pills, or the centrifugal pump, in the case of liquid, to dispense the medication.

B. Hardware Integration and Working
The whole system is encased within a rigid outer structure that prevents any sort of damage that might hinder the performance of the system. The user has to install the MedCare application in their respective mobile devices. Upon installation the user is required to register first. For every user registration, a new database is created within the Firebase servers. Upon registration, the user will only be required to login from there on. The user can select the type of pill or liquid that has to be dispensed. The option of selecting the quantity of liquid medicine to be dispensed is also provided upfront.
The user can then select the time and date at which the medicine has to be dispensed. When the user clicks the 'Ok' button, a 14 digit string value is created according to the selected date, time and type of medication. For example, a selection of Paracetamol,11:30am, 20 June, 2020 will generate '20200620113001'. The corresponding string value is sent from the app to the Firebase server where it is stored in the respective user's database. This value is then send to the Arduino via the nodemcu and the values are stored in an array.
The first 12 digits of all the string values in the array are constantly compared to the output time values from the RTC module and only when any one of it is equal, the last two digits of that particular string value are checked to accurately dispense the required medicine at the exact time required. Based on the value of the last two digits, a signal from the Arduino is given to the servo motor to dispense the pill or to the centrifugal pump to pump out the required amount of liquid medicine. The servo motor is programmed such that only one pill falls at a time. Also, the pump will be activated by the Arduino only for an adequate amount of time depending on the quantity of liquid to be dispensed. Once the dispensation is completed, a buzzer is activated to alert the consumer to take the medicine on time. An ultrasonic sensor can be used to detect the presence of the pill or liquid and hence can be used to notify the caretaker that the patient has missed the medication. This notification can be sent when the sensor detects the presence of the medicine after a predetermined interval of time. A floating power supply may be used to prevent any power surges that can malfunction the Arduino or other components. The AMD app is designed on the Android studio. The app is made to connect to the arduino via firebase which allows us to send or receive data to and from the internet without human intervention. The app contains four widgets: • A spinner used as a drop down to select the medication.
• A CalenderView to select the date and year.
• A TimePicker to the select the time in a 24hr format.
• An Update button to generate the string. The result of the automatic medicine dispenser is the accurate and automatic dispensation of pills and fluid medicines according to as set by the user. For accurate dispensation of fluid medicines, the pump had to be calibrated using trial and error to find out how long the pump should work to pump out different quantities of liquid medicine. A study was done on water based and as well as with syrup based liquid medicines.
The tables below provides the collected data. For water based liquid medicines: For syrup based liquid medicines: The tabular data shows that the centrifugal pump will pump out exactly 2ml of a syrup based liquid medicine in 7.25 seconds and so on. This data is crucial in determining how long the pump must be switched on using the Arduino.
Furthermore, the main objective of the project is to ensure that the device knows what to dispense and when to do it, in accurate amounts. Proper communication of data is needed to fulfil this requirement. Figure 5.2 shows the string value generated whenever the user selects a medicine to be dispensed at whatever date and time. This data needs to be stored within the Arduino to ensure proper dispensation of medicines. Figure  below shows the Firebase database being updated in real-time when a new string is generated.  The following figures shows the Arduino IDE result once the Arduino Uno program is run. The output from RTC is displayed as well as the data from the nodemcu is stored and compared to the RTC value simultaneously. When equal, the appropriate action is taken. Results for both pill dispensation and liquid medicine dispensation are show below. With the use of the SMD, the medication adherence will definitely improve, especially in elderly patients and patients with chronic and period medicine, which in turn will ensure better treatment effectiveness. Insurance companies will definitely benefit from the SMD as it will be instrumental in their customers living a healthier and better lifestyle away from the catastrophic accidents caused by missing their medicine or the right dosage. Finally, the user's interface which is the same on all operating systems and devices is clear, user-friendly, intuitive and easy to use, even for the elderly patients. The design is flexible and also gives the user, the liberty to add more containers and is also open to further enhancements in the future..