To create a new Intelligent medicine box, the interaction between the doctor, box and patients is very important.
Each time the patient takes the box to the hospital to get refilled, the doctor needs to reset the box. To be more specific, the doctor needs to tell the box how long (how many days) this treatment(box) will last, how many injection syringes the patient is going to use in one day and so on. After the patient takes the box back home, the intelligent box should have the ability to detect whether the patient use the medicine according to prescription(whether overdose)
Therefore, in this tutorial, we are going to realize the interaction between doctors, smart devices, and patients through the serial monitor and the Arduino UNO.
1. Realize doctor’s input through serial Monitor
Firstly, let’s focus on how to realize the interaction between doctors and smart box. In this tutorial, we mainly use the serial monitor of Arduino to achieve this goal.
To begin with, we need to tell the doctor what he/she needs to type in through the “Serial.print” function. After the doctor types in the information, we need to use the “Serial.available ()” function to detect whether the doctor inputs, we also need to use “Serial.parseFloat ()” function saves the contents of the program input by the doctor (here we assume that we only let doctors to enter numbers). Considering that the doctor needs to enter multiple values, the input box should also be cleaned up after each input using the “Serial.read ()” function.
Below is a code example of the interaction between the doctor and the intelligence box, of how doctors input medical information to the box following the guidance from the box.
Code example – Interaction between doctors and smart box
float number_of_day = 0; float how_many_oneday = 0; void setup() { Serial.begin(9600); Serial.print("Welcome~\nIn the next few steps, you are going to reset this box following the guidance.\n\nPlease enter how long (days) this treatment(box) will last:\n"); } void loop() { if (Serial.available() > 0) { number_of_day = Serial.parseFloat(); // get the character Serial.print("This treatment will last "); Serial.print(int(number_of_day)); Serial.print(" days\n"); while(Serial.read()>=0){} //clear Serial.print("Please enter number of injection syringes to use in one day:\n"); delay(5000); if (Serial.available() > 0) { how_many_oneday = Serial.parseFloat(); Serial.print(how_many_oneday); Serial.print(" syringes to use in one day\n"); while(Serial.read()>=0){} //clear Serial.print("\nThanks! You have successfully reset the box!"); }else { Serial.print("\nTime out. Please re-enter the number of days this treatment(box) will last.\n"); } } }
2. Realize monitoring patient’s overdose situation through Intelligent Box
-Use button and RGB to demonstrate the working framework of the intelligent box
After the doctor enters the information of how long (how many days) this treatment(box) will last, and how many injection syringes the patient is going to use in one day into the intelligent medical box. The box should should have the ability to detect whether the patient overdoses (use over the input prescription).
In this tutorial, a Button and an RGB is used to show the patient’s overdose situation when the smart box is actually used.
For the button, pressing the button once means using the injection once. And the RGB light will show the situation of overdose. If the methadone has not been used on that day or the number of times of use has not reached the doctor ’s request, it will turn on the green light(tell the patient that he/she can use another one or more); if the number of uses is exactly what the doctor requested, then turn on the blue light (tell the patient that he/she can not use any more on that day); If the patient uses excessively (more than the number prescribed by the doctor), the RGB will light up red light to alert.
video
In this video, I am going to show you how doctors can type in their prescription into this DEMO box, and how this DEMO intelligent box can detect whether the patient overly use the medicine(injections), and how the RGB light on the box will show whether the patient overdosed.
parts list
- 1 Arduino UNO
- 1 Breadboard
- 1 Button
- 1 RGB Light
- 3 330 Ω Resistors
- 1 10K Ω Resistor
diagram
code
const int button1Pin = 2; const int RED_PIN = 9; const int GREEN_PIN = 10; const int BLUE_PIN = 11; unsigned long startMillis; unsigned long currentMillis; float number_of_day = 0; float how_many_oneday = 0; int input_status = 0; int overdose_status =0; int button1State; void setup() { pinMode(button1Pin, INPUT); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); Serial.begin(9600); Serial.print("Welcome~\nIn the next few steps, you are going to reset this box following the guidance.\n\nPlease enter how long (days) this treatment(box) will last:\n"); } void loop() { currentMillis = millis(); if(input_status == 0){ if (Serial.available() > 0) { number_of_day = Serial.parseFloat(); // get the character Serial.print("This treatment will last "); Serial.print(int(number_of_day)); Serial.print(" days\n"); while(Serial.read()>=0){} //clear Serial.print("Please enter number of injection syringes to use in one day:\n"); delay(5000); if (Serial.available() > 0) { how_many_oneday = Serial.parseFloat(); Serial.print(how_many_oneday); Serial.print(" syringes to use in one day\n"); while(Serial.read()>=0){} //clear input_status = 1; Serial.print("\nThanks! You have successfully reset the box!"); }else { Serial.print("\nTime out. Please re-enter the number of days this treatment(box) will last.\n"); } } } if (input_status == 1) { int i = 0; int period = 10000; int overdose_status =0; int times = 0; startMillis = millis(); for (int i =0;i= period) { overdose_status = 0; i=i+1; startMillis = millis(); times = 0; } } input_status = 2; turnRGBoff(); } } int whether_overdose(int times,float how_many_oneday) { if(times how_many_oneday) { overdose_status = 2; } return overdose_status; } void RGB_overdose(int overdose) { if(overdose_status==0) { showRGB(255); } if(overdose_status==1) { showRGB(511); } if(overdose_status==2) { showRGB(0); } } void turnRGBoff() { analogWrite(RED_PIN, 0); analogWrite(BLUE_PIN, 0); analogWrite(GREEN_PIN, 0); } void showRGB(int color) { int redIntensity; int greenIntensity; int blueIntensity; if (color <= 255) // zone 1 { redIntensity = 255 - color; // red goes from on to off greenIntensity = color; // green goes from off to on blueIntensity = 0; // blue is always off } else if (color = 512 // zone 3 { redIntensity = (color - 512); // red off to on greenIntensity = 0; // green is always off blueIntensity = 255 - (color - 512); // blue on to off } analogWrite(RED_PIN, redIntensity); analogWrite(BLUE_PIN, blueIntensity); analogWrite(GREEN_PIN, greenIntensity); }