Stephen YoungJoseph LeNoir
Published © GPL3+

Motion Activated Christmas

A motion controlled Christmas, for your own home. And they turn off automatically after no motion is detected to save energy and money.

BeginnerFull instructions provided4 hours1,803
Motion Activated Christmas

Things used in this project

Hardware components

Photon
Particle Photon
×2
Relay (generic)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Extension Cable
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×6
Christmas Lights
×1
One Sad Christmas Tree
×1

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Hand tools and fabrication machines

Uni-T Multimeter

Story

Read more

Schematics

Motion Sensor Circuit

Motion Sensor Circuit

Relay Circuit

Relay Circuit

Code

Motion Sensor Circuit

C/C++
This is the code that is connected to the PIR sensor and will communicate to another particle if there is motion detected.
  /*
     * Christmas 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("Joseph_christmas_lights", 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("Stephen_christmas_lights","intact");
          //  print on the output change, not state
          pirState = HIGH;delay(600000);
        }
      } else {
        digitalWrite(ledPin, LOW); // turn LED OFF
        if (pirState == HIGH){
          // turned off
          Serial.println("Motion ended!");
          Particle.publish("Stephen_christmas_lights","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 your buddy's beam is intact, then turn your board LED on
    digitalWrite(ledPin,HIGH);
  }
  else if (strcmp(data,"broken")==0) {
    // if your buddy's beam is broken, turn your board LED off
    digitalWrite(ledPin,LOW);
  }
  else {
    // if the data is something else, don't do anything.
  }
}

Relay Circuit

C/C++
This is the code that the other Particle Photon uses. It is just connected to a relay switch.
  /*
     * Christmas 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("Stephen_christmas_lights", myHandler);
      Serial.begin(9600);
    }

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

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

Credits

Stephen Young

Stephen Young

1 project • 0 followers
Joseph LeNoir

Joseph LeNoir

1 project • 0 followers

Comments