Matthew Gardner
Published

MEGR 3171 Alarm System

You'll never miss a class again with this state of the art alarm system.

EasyFull instructions provided4 hours59
MEGR 3171 Alarm System

Things used in this project

Hardware components

Photon
Particle Photon
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
Seeed Grove-LCD RGB Backlight
×1
Resistor 47.5k ohm
Resistor 47.5k ohm
×1

Software apps and online services

fritzing
Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Clock Circuit Diagram

Clock schematic nat3qbyyxh

Lights Servo Motor Circuit Diagram

Servo schematic 0xozemtug7

"Gong" Alarm Servo Circuit Diagram

Servo schematic l2pzkopbuj

Code

Lights

Arduino
This is the code for our servo motor that turns the lights on
Servo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position

void setup()
{
    Particle.subscribe("alarm1234",servo);

    myservo.attach(D0);   // attach the servo on the D0 pin to the servo object
    myservo.write(45);    // set the servo to 45°
    pinMode(D7, OUTPUT);  // set D7 as an output so we can flash the onboard LED
    Spark.function("servo", updateServo);
}

int updateServo(String command)
{
  
  uint8_t pos = command.toInt();    // convert string to integer
}   
void servo(const char *event, const char *data) // be accompanied by a string.
{
    if(strcmp(data,"Toggle")==0)   // if the string is "Toggle", turn on the lights.
    {                            
        myservo.write(110);       // move servo to 110 to flip the switch
        digitalWrite(D7, HIGH);   // flash the LED (as an indicator)
        delay(50);                // wait 50 ms
        digitalWrite(D7, LOW);    // turn off LED
        
    }
    else if((strcmp(data,"Off")==0))
    {
         myservo.write(45);     // when the alarm sends out the "Off" signal it will reset the servo to its resting position
    }
}

Alarm

Arduino
This is the code for the servo motor that rings the bell when the clock reaches desired time
Servo myservo;  // create servo object to control a servo
                

int pos = 0;    // variable to store the servo position

void setup()
{
    Particle.subscribe("alarm1234",servo); // looks for what the alarm sends out

    myservo.attach(D0);   // attach the servo on the D0 pin to the servo object
    myservo.write(35);    // resets the servo by moving it to 35°
    pinMode(D7, OUTPUT);  // set D7 as an output so we can flash the onboard LED
    Spark.function("servo", updateServo);
}

int updateServo(String command)
{
  
  uint8_t pos = command.toInt();    // convert string to integer
}   
void servo(const char *event, const char *data) // be accompanied by a string.
{
    if(strcmp(data,"Toggle")==0)   // if the string is "Toggle", ring the bell multiple times.
    {                            
        myservo.write(0);       // move servo to 0° creating a ringing sound
        digitalWrite(D7, HIGH); // flash the LED
        delay(50);              // wait 50 ms
        myservo.write(35);      // reset the arm before ringing again
        delay(50);
        myservo.write(0);
         delay(50);
        myservo.write(35);
         delay(50);
        myservo.write(0);
         delay(50);
        myservo.write(35);
         delay(50);
        myservo.write(0);
         delay(50);
        myservo.write(35);
         delay(50);
        myservo.write(0);
        digitalWrite(D7, LOW);  // turn off LED
         
    }
    else if((strcmp(data,"Off")==0))
    {
         myservo.write(35);     // reset the servo position to resting postion of 35°
    }
}

Clock

Arduino
Allows the photon to read the current time and send a signal to the others when the desired time is met
#include <Grove_LCD_RGB_Backlight.h>


rgb_lcd lcd;

const int colorR = 200;
const int colorG = 200;
const int colorB = 200;

void setup() {
    lcd.begin(16, 2);                                                            // set up the LCD's number of columns and rows:

    lcd.setRGB(colorR, colorG, colorB);                                          // Set up background backlight color

    lcd.print("Tom's Clock");

    Time.zone(-5.00);

    delay(1000);
}

void loop() {
    lcd.setCursor(0,1);                                                          // sets the cursor where the LCD displays the time
    lcd.print(Time.format(Time.now(), "%T"));                                    // display the current time on the LCD
    if (Time.hour() == 17 && Time.minute() == 16 && Time.second() == 05){        // checks for when the alarm is set
        Particle.publish("alarm1234","Toggle",PUBLIC);                           // sends a signal to the other photons 
        delay(1000);                                                             // give a 1 second delay to allow the signal to be sent to both photons
        Particle.publish("alarm1234","Off",PUBLIC);                              // sends an off signal to the other photons
    }

}

Credits

Matthew Gardner

Matthew Gardner

1 project • 0 followers
Thanks to Tom Fisher, Justin Ratrovo, and Matthew Gardner.

Comments

Add projectSign up / Login