MediCal

Made by nsridhar

Everyone in my immediate family has pills and vitamins that must be taken at regular intervals, but sometimes they miss a day or take them on the wrong days due to forgetfulness. This smart pill tracking system will send reminders to the user when they should take their meds and also keep track of when they last took them, removing any guesswork. It will also track the amount of medicine left in the bottle and let the user know when to refill.

Created: January 25th, 2018

0

----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------


Problem Statement:

Everyone in my immediate family has pills and vitamins that must be taken at regular intervals, but sometimes they miss a day, run out of pills unexpectedly, or take them on the wrong days due to forgetfulness. While calendars and reminders are helpful they are easily ignored and do not help you find your medicines either if you have multiple bottles.


Goal:

My smart pill tracking system will send reminders to the user when they should take their medicine and also flash to help users keep track of their pills. It should also track the amount of medicine left in the bottle and let the user know when to refill.

Process:

The first step in developing this prototype was to narrow down the sensor to use to measure the amount of pills in the bottle. I was originally going to keep a running measurement of the number of pills remaining based off of weight from a load cell/FSR or by using some sensor to help count the pills, but both of these methods were too imprecise to give meaningful data.

Instead I decided to do a more binary measurement based off of the approximate height level of all the pills left in the bottle.

I used a distance sensor to measure the height level of the pills, and have the LED signal an alert if the height level is lower than some set number. This is measured as distance from the cap using an IR distance sensor.


I also attached a switch underneath the cap so it gets pushed down when the bottle is closed. 


Finally I added an LED to the bottle to signal different alerts and reminders to take the pills.


Outcome:

The LED attached to the cap of the bottle functions as an alert indicator to tell the user when to take their pills and when they are running low on pills. It breathes quickly if it is time to take medicine, flashes in sets of 3's if the bottle is running low, and turns off if there is no alert.


The user can turn off the alert by opening the bottle, taking a pill, and closing it again, or through the use of email commands. If the user sends an email to trigger@applet.ifttt.com from a registered email address, they can turn the LED off, or to the Reminder or Low on pills alert modes for manual overriding.


Code:

0
int ledPin = D0;
int switchPin = D1;
int distPin = A1;
int switchState = 0;
int prevState = 0;
int alarmState = 2;
int prevAlarmState = 0;
int dist = 0;

void setup() {
  Particle.function("led", ledControl);

  pinMode(ledPin, OUTPUT);
  pinMode(switchPin, INPUT);
  pinMode(distPin, INPUT);
	Serial.begin(9600);


  digitalWrite(ledPin, LOW);
}

void loop()
{

  switchState = digitalRead(switchPin);
  dist = analogRead(distPin);


  if(switchState == 0 && prevState == 1){
    alarmState = 0;
  }

  else if(switchState == 1 && prevState == 0){
    alarmState = 0;
  }

  if(dist > 1600 && alarmState == 1){
    alarmState = 2;
  }
  else if(dist < 1600 && alarmState == 2){
    alarmState = 1;
  }

  alarm(alarmState);

  prevState = switchState;

}

void alarm(int alarmState){
  if (alarmState == 0){
      digitalWrite(ledPin, LOW);
  }

  else if(alarmState == 1){
      for (int i = 0; i<255; i++){
        analogWrite(ledPin, i);
        delay(2);
      }
      for (int i = 255; i>0; i--){
        analogWrite(ledPin, i);
        delay(2);
      }
  }

  else if(alarmState == 2){
        digitalWrite(ledPin, HIGH);
        delay(100);
        digitalWrite(ledPin, LOW);
        delay(100);
        digitalWrite(ledPin, HIGH);
        delay(100);
        digitalWrite(ledPin, LOW);
        delay(100);
        digitalWrite(ledPin, HIGH);
        delay(100);
        digitalWrite(ledPin, LOW);
        delay(100);
        digitalWrite(ledPin, HIGH);
        delay(300);
    }
}

int ledControl(String cmd){


//find state of led
  if(cmd == "Reminder"){
      alarmState = 1;
  }
  else if (cmd == "Off"){
      alarmState = 0;
  }
  else if (cmd == "Low"){
      alarmState = 2;
  }

  else{
    return -1;
  }

  return alarmState;
}
Click to Expand
0

Circuit Diagram:



Parts:

- Pill Bottle

- Single Color LED

- Micro Switch

- Particle Photon

- IR Analog Distance Sensor

Reflection:

The greatest learning phase for me in regards to this prototype was learning how to use IFTTT with Particle to schedule schedule time based events and also to set up email commands to the Photon. Utilizing the Particle functions through IFTTT was worlds easier than using a special API or anything and getting used to that workflow was fun. Additionally I wrote my own functions to set up the different alert patterns for my LED, which helped me get more familiar with Particle code.

0
MediCal Smart Pill Bottle Prototype - DIoT
Nitesh Sridhar - https://vimeo.com/254615010
x
Share this Project

Courses

49313 Designing for the Internet of Things (Undergrad)

· 22 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Everyone in my immediate family has pills and vitamins that must be taken at regular intervals, but sometimes they miss a day or take them on the wrong days due to forgetfulness. This smart pill tracking system will send reminders to the user when they should take their meds and also keep track of when they last took them, removing any guesswork. It will also track the amount of medicine left in the bottle and let the user know when to refill.