Things used in this project

Hardware components:
Photon new
Particle Photon
×2
Servo (generic)
×2
11026 02
Jumper wires (generic)
×1
12002 04
Breadboard (generic)
×2
Software apps and online services:
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service

Schematics

Bell Circuit
This diagram shows the circuit that was used to control the bell
Bell fi7xnf7wfo
Light Switch Circuit Diagram
This diagram shows the circuit that was used to control the light switch
Light dqwyesca0b

Code

Bell Servo Motor ControlC/C++
This code will be used along with IFTTT to be able to ring the bell at a certain time
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

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

void setup()
{
    Particle.function("bell", bell);  // create a function called "bell" that
                                      // can be called from the cloud
                                      // connect it to the bell function below

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

int bell(String command)   // when "bell" is called from the cloud, it will
{                          // be accompanied by a string.
    
    if(command == "alarm")     // if the string is "alarm",
    {                               
        for (int i = 0; i < 30; i++) // ring the bell 3 times.
        {
            myservo.write(0);       // move servo to 0° - ding!
            digitalWrite(D7, HIGH); // flash the LED
            delay(100);             // wait 100 ms
            myservo.write(25);      // move servo to 25°
            digitalWrite(D7, LOW);  // turn off LED
            delay(200);            // wait 1 second between bells
            
            Particle.publish("Motor", "Lights on", PUBLIC);
        }
        return 2;                   // return a status of "2"
    }
    
}


void loop()
{
  // empty because we call the gong function via the cloud
}
Light Switch Subscription CodeC/C++
This code subscribes to the Bell Servo Motor Control Code from the cloud and activates a servo motor that turns the lights on
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

void setup()
{
  myservo.attach(D1);  // attaches the servo on the D1 pin to the servo object
  // Only supported on pins that have PWM
myservo.write(35); // starts motor at 35 degrees
}

void loop()
{
Particle.subscribe("Motor", LightsOn, "46002b000851363136363935");
  // Subscribe will listen for the event Motor and, when it finds it, will run the function LightsOn
  delay(1000); // delays the motion 1 sec after subscribing to "Motor" event
}

void LightsOn(const char *event, const char *data)
{
  /* Particle.subscribe handlers are void functions, which means they don't return anything.
  They take two variables-- the name of your event, and any data that goes along with your event. */
  
  
   if (strcmp(data,"Lights on")==0) { // if the data from "Motor" reads "Lights on" than the servo will rotate
    myservo.write(180);              // the servo arm will rotate 180 degrees
    delay(1000);                     // this makes a 1 second delay before the arm returns.
    myservo.write(35);              // arm returns to 35 degrees (starting point)
  }
 
}

Credits

12642673 181423152218261 3287017994064420217 n
Jack Crooks
1 project • 1 follower
Contact
Face 3 tlhe6zdhvn
Jacob Warner
1 project • 1 follower
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login