Things used in this project

Hardware components:
Photon new
Particle Photon
×2
13285 01
PIR Motion Sensor (generic)
×1
Relay (generic)
Sainsmart model SKU: 101-70-101
×1
Extension Cord
×1
266 04
Female/Female Jumper Wires
×6
Male/Male Jumper Wires
×6
Lamp
×1
Software apps and online services:
Microsoft Excel
Hand tools and fabrication machines:
Wire cutter/stripper

Schematics

PIR Circuit Diagram
Pirsensor kalish sjac1qxkwp
Relay Circuit Diagram
Relay williams nfrpj7e2df

Code

RelayC/C++
 /*
     * Living Rooom Lights
     */
     
    int ledPin = D7;                // pin for the LED
    int inputPin = D0;               //  input pin (for PIR sensor)
    int pirState = LOW;             // assuming no motion detected
    int val = 0;                    // variable for reading the pin status
    void setup() {
      pinMode(ledPin, OUTPUT);      // declare LED as output
      pinMode(inputPin, INPUT);     // declare sensor as input
      Particle.subscribe("Kalish_Apartment", myHandler, "DeviceID");
      Serial.begin(9600);
    }

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

  if (strcmp(data,"intact")==0) {
    // if beam is intact, then turn your board LED on
    digitalWrite(ledPin,HIGH);
  }
  else if (strcmp(data,"broken")==0) {
    // if beam is broken, turn your board LED off
    digitalWrite(ledPin,LOW);
  }
  else {
    // if the data is something else, don't do anything.
  }
}
Motion Sensor C/C++
 /*
     * Living Room Lights
     */
    
    int ledPin = D7;                // pin for the LED
    int inputPin = D0;               //  input pin (for PIR sensor)
    int pirState = LOW;             // assuming no motion detected
    int val = 0;                    // variable for reading the pin status
    void setup() {
      pinMode(ledPin, OUTPUT);      // declare LED as output
      pinMode(inputPin, INPUT);     // declare sensor as input
      Particle.subscribe("Williams_Apartment", myHandler);
      Serial.begin(9600);
    }
 void loop(){
      val = digitalRead(inputPin);  // read input value
      if (val == HIGH) {            // check if the input is HIGH
        digitalWrite(ledPin, HIGH);  // turn LED ON
        if (pirState == LOW) {
          // turned on
          Serial.println("Motion detected!");
          Particle.publish("Kalish_Apartment","intact");
          //  print on the output change, not state
          pirState = HIGH;delay(100000);
        }
      } else {
        digitalWrite(ledPin, LOW); // turn LED OFF
        if (pirState == HIGH){
          // turned off
          Serial.println("Motion ended!");
          Particle.publish("Kalish_Apartment","broken");
          // We only want to print on the output change, not state
          pirState = LOW;
        }
      }
    }
    
    void myHandler(const char *event, const char *data)
{

  if (strcmp(data,"intact")==0) {
    // if beam is intact, then turn your board LED on
    digitalWrite(ledPin,HIGH);
  }
  else if (strcmp(data,"broken")==0) {
    // if beam is broken, turn your board LED off
    digitalWrite(ledPin,LOW);
  }
  else {
    // if the data is something else, don't do anything.
  }
}

Credits

Profile picture 2017 94dzdjckdp
Christopher Williams
1 project • 0 followers
Mechanical Engineering student at UNC Charlotte
Contact
Img 5398 oabvzhnuqa
Kyle Kalish
1 project • 0 followers
Mechanical Engineering Student at the University of North Carolina at Charlotte
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