Don't Miss Downton!
Made by Ian Lee
Made by Ian Lee
My wife and her friends love Downton Abbey and while not physically together, they watch it at the same time each week. This app reminds the group to tune in and alerts the group to those who have not tuned in within 5 minutes of start time.
Created: January 29th, 2016
I wanted to build an app that would remind the group to tune in and check to see who had tuned in upon show time and alert the group if someone was missing. This would work by building an IFTTT connection to send an SMS to the group 15 minutes before each episode and then using a photosensor, 5 minutes after showtime check to see if the TV was on. If it was not on, then the device would post a tweet and funny photo to twitter alerting the group that someone had not joined.
Locally, LEDs would signify to the local user if the program was running, if Downton Abbey was on, and if the TV was on.
Having missed her social showing on Sunday, on Wednesday my wife and I caught up on the latest episode of Downton Abbey and I got the idea for this device. Having worked with photosensors during the workshop, I thought this would be an easy project to assemble. While I quickly was able to augment the workshop code to achieve the desired functionality locally (getting photosensor readings, blinking LEDs, and turning on LED when low photo readings) getting the code logic around the time syntax was far more challenging then I expected. After googling and attempting numerous efforts myself, Dr. Bryne was able to help find the errors in my code and get the logic working properly to drive actionable response on the Photon only during the time periods at and right before the show. The key it turns out was in the Time.weekday numbering which I can erroneously being using so my code thought it was the wrong day of the week...thus was not working.
Altering clearing this hurdle, I was able to take time to implement the time logic for the photosensor and twitter integrations as well as clean up the code a bit through indentation and added comments. Please note that when posting the code into the window below, this seems to have causes more of a mess than benefit but I promise the code looks much cleaner in my ATOM terminal.
Images & Code Below
- Image1: Reminder Text Sent from Photon to Phone via IFTTT
- Final Code
- Image 2: Log returns via Particle Cloud showing Publishing results used to trigger IFTTT
- Image 3: Twitter Post Sent from Photon to Twitter via IFTT when sensor responded to low photo activity from TV.
// Creative Project 1: Ian Lee
// 1/29/16, CMU-Designing for IOT
// Project: Downton Abby Viewing Party Bot
// Goal: Create an IOT Device that signals when and if Downton Abby is on notifies my wife and her friends via SMS 15 minutes prior to watch.
// At start time, photosensor then signals and alerts if TV is not turned on. TV State is logged to Google Drive.
// Project Components
// 1. Particle Photon
// 2. 3 Single Color LEDs
// 3. 1 Photosensor
// 4. 4 Resisters
// variables
// Signal Elements
// LED Pins
int ledPinRed = D0; // RED (TV IS OFF AND SHOULD BE ON)
int ledPinBlue = D1; // BLUE (DOWNTON ABBY IS ON NOW)
int ledPinYellow = D2; //YELLOW (PROGRAM RUNNING)
// Photo Resistor
int photoCellPin = A0;
// Store the sensor reading
int photoCellReading = 0;
// threshold for being on
int threshold = 350;
// hold a state to say if TV is on or not
bool isOn = false;
// store how bright the LED should be
int ledBrightness = 0;
int ledBrightness2 =0;
// store the time value since it was first covered
long timeSinceFirstThreshold = 0 ;
// Time Store For When to Send Reminder SMS Messages
int dayOfInterest1 = 6;
int hourOfInterest1 = 23;
int minuteOfInterest1 = 0;
// Time Store for When Downton Abbey is On
int dayOfInterest2 = 6;
int hourOfInterest2 = 23;
int minuteOfInterest2 = 0;
// Time Store for When to Check TV Status
int dayOfInterest3 = 6;
int hourOfInterest3 = 23;
int minuteOfInterest3 = 0;
// setup
void setup()
{ // define the LED as output
pinMode( ledPinRed , OUTPUT );
pinMode (ledPinBlue, OUTPUT);
pinMode (ledPinYellow, OUTPUT);
// connect the photo cell reading to the cloud
Particle.variable( "light", &photoCellReading, INT );
Time.zone( -5 );
Serial.begin( 9600 );
}
// loop
void loop()
{
// STATUS LED
digitalWrite( ledPinYellow, HIGH);
delay(1000);
digitalWrite( ledPinYellow, LOW);
delay (1000);
// reading from the sensor
photoCellReading = analogRead( photoCellPin );
Particle.variable( "light", &photoCellReading, INT );
// TV STATUS AT SHOWTIME
if (Time.weekday() == dayOfInterest2 && Time.hour() == hourOfInterest2 && Time.minute() >= minuteOfInterest2 ){
// see if TV is on
if( photoCellReading < threshold ){
isOn = false;
ledBrightness = 255;
Particle.publish("Missing_Downton", "Yes"); //If covered, write to cloud to kick of IFTTT
delay (10000);
}
if( photoCellReading > threshold){ //If not covered, turn of LED indicator
isOn = true;
ledBrightness = 0;
}
}
digitalWrite( ledPinRed , ledBrightness);
// SERIAL READINGS FOR DEBUGGING
Serial.print( "Sensor reading is: " );
Serial.println( photoCellReading );
delay( 50 );
// SEND SMS REMINDER ALERT
if (Time.weekday()==dayOfInterest1 && Time.hour() == hourOfInterest1 && Time.minute() >= minuteOfInterest1 ){
Particle.publish("Downton_Alert", "Yes");
delay (10000);
}
// INDICATE IF DOWNTON IS ON
if( (Time.weekday() == dayOfInterest2 && Time.hour() == hourOfInterest2 && Time.minute() >= minuteOfInterest2 )){
digitalWrite( ledPinBlue, HIGH);
}}
Click to Expand
@eswiftlee is missing DOWNTON ABBEY! OH MY pic.twitter.com/bOp9Ey63Xp
— Downton Abbey (@Downton_IOT) January 30, 2016
This course charts the emergence of the now "connected world" to explore the possibilities for future products and connected spaces.
My wife and her friends love Downton Abbey and while not physically together, they watch it at the same time each week. This app reminds the group to tune in and alerts the group to those who have not tuned in within 5 minutes of start time.