Create a smart pills reminder for my wife, and make me look responsible!!
Problem Statement:
I got recently married and am feeling excited about this new phase of life. As soon as this home hack assignment was described, I wanted to use this opportunity to make something useful for my wife. My wife regularly takes vitamin supplement and I usually remind her every day during lunch. Some days I get too busy with work and forget to remind her, and once I realize it, I feel very bad. To avoid this situation and also impress my wife, I took up this project to make me and my wife a smart pills reminder system.Goal:
The goal of this project is to detect if my wife has already taken the pills and either thank her for taking the pill or notify me to remind her if she has forgotten to take them. Another sub-need recognized from discussing the project with her was to remind me to get pills refill from the pharmacy when they are nearing empty. She (being smart) wanted the smart device to help her and not just me :PProcess:
First I started off with creating the bill of materials needed based on a conceptual idea. The idea was to use a pressure sensor data recorded over a period to understand the state of the pills bottle. I also wanted visual feedback to show if the pressure sensor is working and used an led to provide that feedback.
Bill of materials;
Photon microcontroller
Breadboard
Connectors
Resistors
Pressure sensor
Led
Click this link to view the full assembly of the circuit
https://drive.google.com/open?id=0Bw44yovidQDHNG52VzVPU0FKclU
// Stage 1 code
int ledPin = D0; // Light pin digital output
int pressureSensorPin = A0; // connected to analog pin 0
int pressureReading; // define a variable to store our sensor reading
int ledBrightness = 0; // assigning ledBrightness to 0
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Particle.variable("pressure", &pressureReading, INT);
}
void loop(){
pressureReading = analogRead(pressureSensorPin);
Serial.println( pressureReading );
ledBrightness = map(pressureReading, 0, 4095, 50, 255);
analogWrite(ledPin, ledBrightness); // control the ledPin output
delay(1000); // take reading every second
}
Click to Expand
// Stage 2 code
int ledPin = D0; // Light pin digital output
int pressureSensorPin = A0; // connected to analog pin 0
int pressureReading; // define a variable to store our sensor reading
int ledBrightness = 0; // assigning ledBrightness to 0
int removeCounter = 0; //assign removeCounter to 0
int tarePressure = 100; // assigning tarePressure to 100
int notificationThreshold = 1000; // assigning notificationThreshold to 1000
void setup() {
Serial.begin(9600);
Time.zone(-5); // Setting time zone to EST
pinMode(ledPin, OUTPUT);
Particle.variable("pressure", &pressureReading, INT);
}
void loop(){
pressureReading = analogRead(pressureSensorPin);
Serial.println( pressureReading );
ledBrightness = map(pressureReading, 0, 4095, 50, 255);
// detecting the number of times the bottle was removed
if (pressureReading < 100){
removeCounter++;
}
// detecting if the time is 1 PM
if (Time.hour() == 13){
// If the pill bottle was not removed, remind to take pill
if (removeCounter == 0){
Particle.publish( "pill-update", "Take pill");
}
// Else publish thanks for taking the pills
else{
Particle.publish( "pill-update", "Thanks for taking the pill");
}
// Detect the low level of pills and send notification
if (tarePressure<=pressureReading && pressureReading<=notificationThreshold){
Particle.publish( "pill-update", "Consider reordering");
}
}
analogWrite(ledPin, ledBrightness); // control the ledPin output
delay(1000); // take reading every second
}
Click to Expand
// Stage 3 final code
int ledPin = D0; // Light pin digital output
int pressureSensorPin = A0; // connected to analog pin 0
int pressureReading; // define a variable to store our sensor reading
int ledBrightness = 0; // assigning ledBrightness to 0
int removeCounter = 0; //assign removeCounter to 0
int tarePressure = 100; // assigning tarePressure to 100
int notificationThreshold = 1000; // assigning notificationThreshold to 1000
unsigned long oneHour = 60*60*1000; // declaring oneHour in milli-seconds
unsigned long lastPublishTime = 0; // assigning lastPublishTime to 0
void setup() {
Serial.begin(9600);
Time.zone(-5); // Setting time zone to EST
pinMode(ledPin, OUTPUT);
Particle.variable("pressure", &pressureReading, INT);
}
void loop(){
pressureReading = analogRead(pressureSensorPin);
Serial.println( pressureReading );
ledBrightness = map(pressureReading, 0, 4095, 50, 255);
// detecting the number of times the bottle was removed
if (pressureReading < 100){
removeCounter++;
}
// detecting if the time is 1 PM
if (Time.hour() == 13){
// detecting if the last published time is more than an hour
if(millis()-lastPublishTime > oneHour){
// If the pill bottle was not removed, remind to take pill
if (removeCounter == 0){
Particle.publish( "pill-update", "Take pill");
lastPublishTime = millis(); // record the latest run time to lastPublishTime
}
// Else publish thanks for taking the pills
else{
Particle.publish( "pill-update", "Thanks for taking the pill");
lastPublishTime = millis(); // record the latest run time to lastPublishTime
}
// Detect the low level of pills and send notification
if (tarePressure<=pressureReading && pressureReading<=notificationThreshold){
Particle.publish( "pill-update", "Consider reordering");
lastPublishTime = millis(); // record the latest run time to lastPublishTime
}
}
}
analogWrite(ledPin, ledBrightness); // control the ledPin output
delay(1000); // take reading every second
}
Click to Expand
Outcome:
Final outcome of this effort was to create a prototype that records sensor data and publish events based on some conditions. The context of usage was to make me look responsible and encourage better behavior of regularly taking pills for my wife and prevent us from running out of pills. Doing the above project I learnt how to research and understand code shared by others, apply them to solve my problem effectively. I also understood some common pitfalls using particle, like over publishing events, setting time zone if using time function, etc. and learn how to avoid them. I think the outcome of this project was success from practical learning point of view. This also made my wife very happy, which is always a good outcome :PNext steps:
Midway of the project I realized that the pressure sensor might not be able to measure bottle weight and the way to overcome this is by using a load cell in combination with HX711 ADC instead of the pressure sensor. Since the phy comp lab does not have these components, I had no way to get them except order in Amazon. I have just received the HX711 ADC, but still waiting on the load cell. Once I receive them, will complete the final version of the actual working pill reminder.Reflection:
I think this was a very useful design of IoT device exercise where we defined a problem and solved it using the power of Particle + IFTTT and cloud. This is my first IoT project and I had a lot of fun and learning doing it. It could have been better if I had planned in advance the components needed so I could have completed the final version. I did hit some roadblocks, but the professor and TA were very helpful in teaching me how to resolve them. Overall I think it was a good learning experience and I am excited for my next project.A hands-on introductory course exploring the Internet of Things and connected product experiences.
Create a smart pills reminder for my wife, and make me look responsible!!
January 26th, 2017