Dillon TraphagenAndrew Lackeysamir
Published

MEGR 3171 -DSA Alarm Clock

An alarm clock that is sure to wake you up for your big day as a college student. Made for the MEGR 3171 IOT Project

IntermediateFull instructions provided4 hours784

Things used in this project

Hardware components

Photon
Particle Photon
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
Buzzer
Buzzer
×1
High Brightness LED, White
High Brightness LED, White
×3
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×3
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Maker service
IFTTT Maker service
Fritzing
Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Buzzer

Light Switch

Main Photon

Code

Main Photon

C/C++
                   +-----+
 *      +----------| USB |----------+
 *      |          +-----+          |
 *      | [ ] VIN           3V3 [ ] |
 *      | [ ] GND           RST [ ] |         
 *      | [ ] TX           VBAT [ ] |          
 *      | [ ] RX  [S]   [R] GND [ ] |
 *      | [ ] WKP            D7 [ ] |       
 *      | [ ] DAC +-------+  D6 [ ] |        
 *      | [ ] A5  |   *   |  D5 [ ] |   
 *      | [ ] A4  |Photon |  D4 [ ] |     
 *      | [ ] A3  |       |  D3 [ ] |       
 *      | [ ] A2  +-------+  D2 [ ] |       
 *      | [ ] A1             D1 [ ] |       
 *      | [ ] A0             D0 [ ] |
 *      |                           |
 *       \    []         [______]  /
 *        \_______________________/
 *
 *
 *

//  begin particle with Thingspeak library code

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

//This configues Thingspeak to our project
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;
//APIKey and Channel number was given from Thingspeak and used to connect
const String myWriteAPIKey = "AZHKS1VO66X4VKA2";

unsigned long myChannelNumber = 745551;

//This labels what fields will be used 
float field_1; 
float field_2; 
float field_3; 
//These are the names of each field and their intial values 
int alarmDetection, lightsStatus = 0, buzzerStatus = 0;
 


void setup()   {
    //ThingSpeak connection
    ThingSpeak.begin(client);
    //IFTTT Event triggered by Applet 
    Particle.subscribe("AlarmClockDSA", checkTime);
}
//AlarmClockDSA is the name of the trigger event from IFTTT
//After we subscribe we will run a loop that constanly checks the time and the IFTTT Event status

void loop() {
    Particle.publish("MEGR3171_DillonT_AlarmClock", "alarmOff", PUBLIC);
    alarmDetection = 0;
    
    String data = String(10); 
    delay(1000);
    
    //Eastern USA Time Zone
    //-4 Value is Eastern USA daylight saving time
    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("MEGR3171_DillonT_AlarmClock", "alarmOn", PUBLIC);
        alarmDetection = 1;
        delay(2000);
    }
     
    delay(1000);
    Particle.publish("alarmTime", alarmTime, PUBLIC);
    Particle.subscribe("MEGR3171_AndrewL_Motor", checkMotor);
    Particle.subscribe("MEGR3171_Samir_Buzzer", checkBuzzer);
//The AlarmDetection above sets the value on the Thingspeak channel    
// The above code subscribes to the other Photons and Publishs an event for the Photons to read 
//The Photon also subscribes to the events put out by the other two photons
    delay(1000);
    writetothingspeak();

    delay(30000); 
}
//Writes data collected to Thingspeak fields
void writetothingspeak(void) {
  field_1 = alarmDetection;
  field_2 = lightsStatus;
  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);

}
//Uses void function to check event and records data
//Data is changed from intial value of 0 to 1 
//This will show on Thingspeak and you will be able to tell when the alarm went off
//This happens to both the Buzzer and the lights status
void checkMotor(const char *event, const char *data) {

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

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

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

Servo/Lights

C/C++
                   +-----+
 *      +----------| USB |----------+
 *      |          +-----+          |
 *      | [*] VIN           3V3 [ ] |
 *      | [*] GND           RST [ ] |         
 *      | [ ] TX           VBAT [ ] |          
 *      | [ ] RX  [S]   [R] GND [ ] |
 *      | [ ] WKP            D7 [ ] |       
 *      | [ ] DAC +-------+  D6 [ ] |        
 *      | [ ] A5  |   *   |  D5 [ ] |   
 *      | [ ] A4  |Photon |  D4 [ ] |     
 *      | [ ] A3  |       |  D3 [ ] |       
 *      | [ ] A2  +-------+  D2 [ ] |       
 *      | [ ] A1             D1 [ ] |       
 *      | [ ] A0             D0 [*] |
 *      |                           |
 *       \    []         [______]  /
 *        \_______________________/
 *
 *
 *



Servo myservo;  // Creates servo object.
int pos = 0;
int led = D7;
int Servo = D0;
void setup()

{
    pinMode(led, OUTPUT);
    digitalWrite(led, LOW);
    
    pinMode(Servo, OUTPUT);
    digitalWrite(Servo, LOW);
    
    Particle.subscribe("MEGR3171_DillonT_AlarmClock", DillonT, "360029000447363339343638");  // This subscribes the photon to the event AlarmClock initiated by DillonT
    Particle.subscribe("MEGR3171_Samir_Buzzer", SamirM, "2f0041000547373336323230"); // This subscribes the photon to the event Buzzer initiated by SamirM
}


void DillonT(const char *event, const char *data)
{}
void SamirM(const char *event, const char *data)

{
    
    if (strcmp(data,"alarmOn")==0) {
        myservo.write(110);       // move servo to 110 to flip the switch
        digitalWrite(led, HIGH);   // flash the LED (as an indicator)
        delay(50);                // wait 50 ms
        digitalWrite(led, LOW);  
        String Servo=String("1");
        Particle.publish("MEGR3171_AndrewL_Motor","LightsOn",PUBLIC);
    }
    else if(strcmp(data,"alarmOff")==0) { 
        digitalWrite(led, LOW);
        myservo.attach(D0);     // Pin D0 is connected to the servo motor.    // Pin D0 is connected to the servo mtor.
        myservo.write(0);      // Move servo to initial position 
        myservo.detach();
        String Servo=String("1");
        Particle.publish("MEGR3171_AndrewL_Motor","LightsOFF",PUBLIC);
}
}

Buzzer

C/C++
                   +-----+
 *      +----------| USB |----------+
 *      |          +-----+          |
 *      | [ ] VIN           3V3 [ ] |
 *      | [ ] GND           RST [ ] |         
 *      | [ ] TX           VBAT [ ] |          
 *      | [ ] RX  [S]   [R] GND [ ] |
 *      | [ ] WKP            D7 [*] | --------//LED Lights      
 *      | [ ] DAC +-------+  D6 [ ] |        
 *      | [ ] A5  |   *   |  D5 [ ] |   
 *      | [ ] A4  |Photon |  D4 [ ] |     
 *      | [ ] A3  |       |  D3 [ ] |       
 *      | [ ] A2  +-------+  D2 [ ] |       
 *      | [ ] A1             D1 [ ] |       
 *      | [ ] A0             D0 [*] |-------- //Buzzer
 *      |                           |
 *       \    []         [______]  /
 *        \_______________________/
 *
 *
 *


int led = D7;
int Buzzer = D0;

int state = 0;



void setup() 
{
pinMode(led, OUTPUT);
digitalWrite(led, LOW);

pinMode(Buzzer,OUTPUT);
digitalWrite(Buzzer, LOW);



Particle.subscribe("MEGR3171_DillonT_AlarmClock", DillonT, "360029000447363339343638");
Particle.subscribe("MEGR3171_AndrewL_Motor", AndrewL, "44002d000547363339343638" );

}

void AndrewL(const char *event, const char *data)
{}
void DillonT(const char *event, const char *data)
{
    

if (strcmp(data,"alarmOn")==0) {
digitalWrite(led, HIGH);
  delay(2000);
  digitalWrite(led, LOW);
  delay(2000);
  
  digitalWrite(Buzzer,HIGH);
      delay(1000);
  digitalWrite(Buzzer,LOW);
  
  digitalWrite(led, HIGH);
  delay(1200);
  digitalWrite(led, LOW);
  delay(1200);
  
  digitalWrite(Buzzer,HIGH);
      delay(1100);
      digitalWrite(Buzzer,LOW);
 String Buzzer = String("1");     
 Particle.publish("MEGR3171_Samir_Buzzer","buzzON", PUBLIC); 
}

    else {
        digitalWrite(Buzzer, LOW);
        digitalWrite(led, LOW);
        digitalWrite(Buzzer, LOW);
        String MEGR3171_Samir_Buzzer = String("0");
        Particle.publish("MEGR3171_Samir_Buzzer","buzzOFF", PUBLIC);
    }
}    

Credits

Dillon Traphagen

Dillon Traphagen

1 project • 1 follower
Andrew Lackey

Andrew Lackey

1 project • 1 follower
samir

samir

0 projects • 1 follower
Thanks to Janessa Schwallie, Lindsey Ward, and Alex Caviness.

Comments

Add projectSign up / Login