// 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
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .