Janessa SchwallieLindsey WardAlex Caviness
Created October 18, 2018

MEGR 3171 - Morning from Hell Alarm System

This system will assure that you'll never be late for your 8am again, with two methods to get you ready for the day -- alarms and sunshine!

IntermediateFull instructions provided78
MEGR 3171 - Morning from Hell Alarm System

Things used in this project

Hardware components

Photon
Particle Photon
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
Buzzer
Buzzer
×2
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×3
Slide Switch
Slide Switch
×1
DC motor (generic)
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
SmartThings service
IFTTT SmartThings service

Story

Read more

Schematics

Buzzer circuit

Servo/Blinds Circuit

Main Photon Schematic

Very interesting.

Code

Servo Motor Photon for Blinds

C/C++
This code controls the degree of rotation of the servo motor to open and close the blinds when an "On" or "Off" event is published from the main photon. In either case, this photon will publish a numerical value corresponding to the event.
Servo myservo;  // Creates servo object.
int pos = 0;
void setup()

{
    Particle.subscribe("MEGR3171MasterOfHell", hoosier_narwhal);  // This subscribes the photon to the event "MEGR3171MasterOfHell" initiated by hoosier_narwhal.
    Particle.subscribe("HellBuzzer", lward32); // This subscribes the photon to the event "HellBuzzer" initiated by lward32.
    myservo.attach(D0);
}


void lward32(const char *event, const char *data)
{}
void hoosier_narwhal(const char *event, const char *data)

{
    
    if (strcmp(data,"alarmOn")==0) {   
        String HellBlinds=String("1");
        Particle.publish("HellBlinds","blindsOn",PUBLIC);
        myservo.attach(D0);     // Pin D0 is connected to the servo mtor.
        myservo.write(60);      // Move servo clockwise.
        delay(8000);   // Servo rotation for 8 seconds.
        myservo.detach();
        delay(10000); 
        myservo.attach(D0);
        myservo.write(120);       // Move servo counterclockwise.
        delay(8000);
        myservo.detach();
    }
    
    
    else if(strcmp(data,"alarmOff")==0) { 
        String HellBlinds=String("0");
        Particle.publish("HellBlinds","blindsOff",PUBLIC);
        myservo.attach(D0);     // Pin D0 is connected to the servo motor.

}
    
}

Buzzer Code

C/C++
This code sends a high signal to both of the buzzers and communicates to the main code by telling it if the buzzer is on or off.
 pinMode(Buzzer1, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(Buzzer2, OUTPUT);
  Particle.subscribe("MEGR3171MasterOfHell", hoosier_narwhal);
  Particle.subscribe("HellBilinds", morphing_power);
}
void morphing_power(const char *event, const char *data)
{}
void hoosier_narwhal(const char *event, const char *data)
{
    
    if (strcmp(data, "alarmOn")==0) { 
        digitalWrite(Buzzer1, HIGH);
        digitalWrite(led, HIGH);
        digitalWrite(Buzzer2, HIGH);
        delay(1000);
        digitalWrite(Buzzer2, LOW); /// this series of delays bliks the led and pulses the buzzer
        digitalWrite(led, LOW);
        delay(1000);
        digitalWrite(Buzzer2, HIGH);
        digitalWrite(led, HIGH);
        delay(1000);
        digitalWrite(Buzzer2, LOW);
        digitalWrite(led, LOW);
        delay(1000);
        digitalWrite(Buzzer2, HIGH);
        digitalWrite(led, HIGH);
        delay(1000);
        String HellBuzzer = String("1");
        Particle.publish("HellBuzzer","buzzON", PUBLIC); //publishes the code buzz on to the main code
    }
    else {
        digitalWrite(Buzzer1, LOW);
        digitalWrite(led, LOW);
        digitalWrite(Buzzer2, LOW);
        String HellBuzzer = String("0");
        Particle.publish("HellBuzzer","buzzOFF", PUBLIC);
    }
}

Main Photon

C/C++
This code extracts the alarm time set in IFTTT to determine when to trigger the alarm. It then pushes that data to the other photons and records their data.
// Libraries Used
#include <ThingSpeak.h>

TCPClient client;

String hightemp, lowtemp, month, day, year, hour, minute, period, date, date_time, current_time, midday;
int changed_hour, current_hour, current_minute;
String alarmTime;

const String myWriteAPIKey = "XO3WY3JHC91WM089";

unsigned long myChannelNumber = 575085;

float field_1; //alarm status
float field_2; //blinds status
float field_3; //buzzer status

int alarmStatus, blindsStatus = 0, buzzerStatus = 0;
 
//int boardLed = D7;

void setup()   {
    //ThingSpeak integration
    ThingSpeak.begin(client);
    //IFTTT integration
    Particle.subscribe("TheAlarmPerDiem", checkTime);
}

void loop() {
    Particle.publish("MEGR3171MasterOfHell", "alarmOff", PUBLIC);
    alarmStatus = 0;
    
    String data = String(10); //gives the value a buffer to work properly
    delay(1000);
    
    //calibrated for Eastern USA Time Zone
    if(Time.month()==3 && Time.day()>10){
            Time.zone(-4);
    }
    else if(Time.month()>3 && Time.month()<11) {
        Time.zone(-4);
    }
    else if(Time.month()==11 && Time.day()<4) {
        Time.zone(-4);
    }
    else {
        Time.zone(-5);
    }
    current_time = Time.format(Time.now(), "%I:%M%p");
    Particle.publish("checkCurrentTime", current_time, PUBLIC);
     
    if(strcmp(current_time, alarmTime) == 0)
    {
        Particle.publish("MEGR3171MasterOfHell", "alarmOn", PUBLIC);
        alarmStatus = 1;
        delay(2000);
    }
     
    delay(1000);
    Particle.publish("alarmTime", alarmTime, PUBLIC);
    Particle.subscribe("HellBlinds", checkBlinds);
    Particle.subscribe("HellBuzzer", checkBuzzer);
    
    delay(1000);
    writetothingspeak();

    delay(30000); //0.5 min
}

void writetothingspeak(void) {
  field_1 = alarmStatus;
  field_2 = blindsStatus;
  field_3 = buzzerStatus;
    
  ThingSpeak.writeField(myChannelNumber, 1, field_1, myWriteAPIKey);
  delay(1000);
  ThingSpeak.writeField(myChannelNumber, 2, field_2, myWriteAPIKey);
  delay(1000);
  ThingSpeak.writeField(myChannelNumber, 3, field_3, myWriteAPIKey);
  delay(1000);
}

void checkTime(const char *event, const char *data) {

  String str = String(data);
  char strBuffer[64] = "";
  str.toCharArray(strBuffer, 64);
  String temp;
  
  temp = strtok (strBuffer, " ,.-");
  while (temp != NULL)
  {
    alarmTime = temp;
    temp = strtok (NULL, " ,.-");
  }

  delay(1000);

}

void checkBlinds(const char *event, const char *data) {

  String str = String(data);
  if(strcmp(str, "blindsOn") == 0) {
      blindsStatus = 1;
  }
  else {
      blindsStatus = 0;
  }
}

void checkBuzzer(const char *event, const char *data) {

  String str = String(data);
  if(strcmp(str, "buzzON") == 0) {
      buzzerStatus = 1;
  }
  else {
      buzzerStatus = 0;
  }
}

Credits

Janessa Schwallie

Janessa Schwallie

1 project • 2 followers
Lindsey Ward

Lindsey Ward

1 project • 2 followers
Alex Caviness

Alex Caviness

1 project • 2 followers

Comments