49-713 Designing for the Internet of Things
· 26 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
My proposal is a device that helps my roommate make the perfect bath without having to stand around watching it and testing the temperature. It will alert the user when the water needs to be turned off because it has reached a certain height and when it has cooled down enough to get in or needs more hot water based on the user’s preference. To do this, I will need a thermistor, water sensor, and buzzer in case the user’s phone is on silent.
The Bath Buddy is designed for my roommate who likes to take baths, but would rather wait in the living room rather than in the bathroom while the bath is filling up. Additionally, he does not like having to constantly check the water. He will benefit from this product because it will tell him when to turn the water off and when it’s at the correct temperature while he’s in a different room. I chose this person because he lives with me so I can ask him questions and test the product with him. This problem was selected because it can easily be used and tested in my home, and it can make a relaxing activity a little more relaxing.
I want my solution to alert my user when he is away from the bath with something that is always with him (his phone or smart watch). This will make the task of drawing a bath simpler. It addresses the problem by messaging the user when the water needs to be turned off and when the temperature is cool enough to go in. In this way, the bath won’t overflow and the user won’t need to touch scalding water to test if it’s cool enough. The Bath Buddy also uses a secondary alert of a buzzer in case their phone is off or on silent.
I first tested out the codes from tutorials for the temperature sensor and piezo buzzer. The buzzer was not working at first, but then I realized that it mattered what pin I put it in. The temperature tutorial worked well. However, at some points the readings were off because the data wire kept coming out of the board so I decided to tape it in place. Next, I converged both codes together and added a water “sensor.” Because water conducts, I just have one lead attached to ground and one lead attached to a pin so that when they both touch water, the circuit is completed. When the circuit sensed water, I had it play notes on a speaker and when the temperature was correct, I had it light up an LED. I also made the temperature and water sensors publish messages to my phone using IFTTT. At first I had the water and temperature sensors in the loop section, however, this caused my code to push messages repeatedly to my phone. I instead moved them to the setup section and wrote two for loops so that it would only send one message for water level and one for temperature.
Codes used from DioT Labs and Guides:
Speaker: http://diotlabs.daraghbyrne.me/6-controlling-outputs/piezo/
Temperature Sensor: http://diotlabs.daraghbyrne.me/3-working-with-sensors/DS18B20/
// This #include statement was automatically added by the Spark IDE.
#include "OneWire.h"
// This #include statement was automatically added by the Spark IDE.
#include "spark-dallas-temperature.h"
// -----------------
// Read temperature
// -----------------
// Data wire is plugged into port 0 on the Arduino
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(D0 );
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);
// Create a variable that will store the temperature value
double temperature = 0.0;
double temperatureF = 0.0;
int waterSensor = A0;
int water;
int waterHot = 100;
int waterCold = 97;
int ledPin = D2;
void setup()
{
// Register a Particle variable here
Particle.variable("temperature", &temperature, DOUBLE);
Particle.variable("temperatureF", &temperatureF, DOUBLE);
Particle.variable("water", &water, INT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// setup the library
dallas.begin();
}
void loop()
{
// Request temperature conversion
dallas.requestTemperatures();
// get the temperature in Celcius
float tempC = dallas.getTempCByIndex(0);
// convert to double
temperature = (double)tempC;
// convert to Fahrenheit
float tempF = DallasTemperature::toFahrenheit( tempC );
// convert to double
temperatureF = (double)tempF;
water = analogRead(waterSensor);
if (water < 100){
Particle.publish("Water-Detection","Your water is ready");
if (temperatureF < waterHot){
if (temperatureF > waterCold){
Particle.publish("Water-At-Optimal-Temp");
digitalWrite(ledPin, HIGH);
}else{
Particle.publish("Water-Too-Cold");
}
}else{
Particle.publish("Water-Too-Hot");
}
delay(10000);}
delay(5000);
}
/*
The API request will look something like this:
GET /v1/devices/{DEVICE_ID}/temperature
# EXAMPLE REQUEST IN TERMINAL
# Device ID is 0123456789abcdef
# Your access token is 123412341234
curl -G https://api.particle.io/v1/devices/0123456789abcdef/temperature \
-d access_token=123412341234
*/
Click to Expand
My prototype functions correctly, but it doesn’t look like a final product. I need to make a better casing for it so that it looks more appealing, and I need to add safety measures to it. Next I would like it to turn off the water once it hit sensor and allow for someone to check the temperature of the bath at any time.
//codes for Speaker from: http://diotlabs.daraghbyrne.me/6-controlling-outputs/piezo/
//codes for Temperature Sensor from: http://diotlabs.daraghbyrne.me/3-working-with-sensors/DS18B20/
// This #include statement was automatically added by the Spark IDE.
#include "OneWire.h"
// This #include statement was automatically added by the Spark IDE.
#include "spark-dallas-temperature.h"
// -----------------
// Read temperature
// -----------------
// Data wire is plugged into port 0 on the Arduino
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(D0 );
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);
// Create a variable that will store the temperature value
double temperature = 0.0;
double temperatureF = 0.0;
int waterSensor = A0;
int water;
int waterHot = 100;
int waterCold = 97;
int ledPin = D2;
int speakerPin = D1;
// create an array for the notes in the melody:
//C4,G3,G3,A3,G3,0,B3,C4
int melody[] = {1908,2551,2551,2273,2551,0,2024,1908};
// create an array for the duration of notes.
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {4,8,8,4,4,4,4,4 };
void setup()
{
// Register a Particle variable here
Particle.variable("temperature", &temperature, DOUBLE);
Particle.variable("temperatureF", &temperatureF, DOUBLE);
Particle.variable("water", &water, INT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode( speakerPin, OUTPUT );
// setup the library
dallas.begin();
//check if water is at correct level
waterlevel();
tempCheck();
}
void loop()
{
}
void waterlevel(){
for ( int i = 0; i < 1;) {
water = analogRead(waterSensor);
if (water < 100){
Particle.publish("Turn-off-water");
playNotes();
i = 2;
}else{
i = 0;
delay(5000);
}
}
}
void tempCheck(){
for (int r = 0; r < 1;) {
// Request temperature conversion
dallas.requestTemperatures();
// get the temperature in Celcius
float tempC = dallas.getTempCByIndex(0);
// convert to double
temperature = (double)tempC;
// convert to Fahrenheit
float tempF = DallasTemperature::toFahrenheit( tempC );
// convert to double
temperatureF = (double)tempF;
if (temperatureF < waterHot){
if (temperatureF > waterCold){
Particle.publish("Water-temp-is-good");
digitalWrite(ledPin, HIGH);
r = 2;
}else{
r = 0;
}
}else{
r = 0;
}
delay(5000);
}
}
void playNotes()
{
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(speakerPin, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speakerPin);
}
}
Click to Expand
I enjoyed the process of making my Bath Buddy. It was new to me, so it was very exciting when I got things to work. Coding was time-consuming; however, I feel that in the future that this will be a faster process. I learned more about the format of this coding language and how to write for loops and publish variables to the cloud. I also learned how to use IFTTT to text me when an event has been published. If I could do this over, I would test parts separately more before putting them together. I put all the code together before testing it and it was sometimes hard to figure out what was wrong. I got to where I wanted it to be. Towards the end, I was thinking it would be helpful to have the program text me the temperature when called, but I wasn’t sure how to do this. I need to do more research in cloud variables and IFTTT. Additionally, I would have liked it to turn off the water once it hit sensor, but our faucet is stiff, and I don’t think the motor would have been strong enough to turn it.
A hands-on introductory course exploring the Internet of Things and connected product experiences.
My proposal is a device that helps my roommate make the perfect bath without having to stand around watching it and testing the temperature. It will alert the user when the water needs to be turned off because it has reached a certain height and when it has cooled down enough to get in or needs more hot water based on the user’s preference. To do this, I will need a thermistor, water sensor, and buzzer in case the user’s phone is on silent.
January 25th, 2017