Sarah AljishiHanin Elathram
Published

WELCOME HOME!!

Light bulbs connected to a motion sensor with a welcoming speaker.

IntermediateShowcase (no instructions)1,131
WELCOME HOME!!

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Relay Shield for Particle Photon I²C 8-Channel SPDT 10-Amp
ControlEverything.com Relay Shield for Particle Photon I²C 8-Channel SPDT 10-Amp
×1
Light bulb
×2
extension cord
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
SparkFun Speakerjet
×1
Capacitor kit
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 27k ohm
×1
Breadboard (generic)
Breadboard (generic)
×2
Mini speakers
×1

Software apps and online services

Particle
Maker service
IFTTT Maker service

Hand tools and fabrication machines

Multimeter

Story

Read more

Schematics

Motion and LED Circuit_Particle-1

Speaker Circuit_Particle-2

Speaker Alternative Circuit_Particle-2

Code

Motion and LED Code_Particle-1

C/C++
   * PIR sensor tester
 
   
  int ledPin = D1;                // choose the pin for the LED
  int inputPin = D4;               // choose the input pin (for PIR sensor)
  int pirState = LOW;             // we start, assuming no motion detected
  int val = 0;                    // variable for reading the pin status
     short VPS[] = {20,127,22,180,21,120}; //array for Volume,Pitch and speed --length: 6
short Welcome[]={8,15,147,159,194,135,140};// variable for reading the pin status

 void setup() {
  
   pinMode(ledPin, OUTPUT);      
   // declare LED as output
   pinMode(inputPin, INPUT);     // declare sensor as input
 Particle.subscribe("Hanin", 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) {
       // we have just turned on
       Serial.println("Motion detected!");
       Particle.publish("Sanin","motion");
       // We only want to print on the output change, not state
       pirState = HIGH ;
       delay(120000);
     }
   } else {
     digitalWrite(ledPin, LOW); // turn LED OFF
     if (pirState == HIGH){
       // we have just turned of
       Serial.println("Motion ended!");
       Particle.publish("Sanin","no motion");
      // We only want to print on the output change, not state
       pirState = LOW;
       delay(5000);
     }
   }
   }
   void myHandler(const char *event, const char *data)
{
 

  if (strcmp(data,"no motion")==0) {
    // if your buddy's beam is intact, then turn your board LED off
    digitalWrite(ledPin,LOW);
  }
  else if (strcmp(data,"motion")==0) {
    // if your buddy's beam is broken, turn your board LED on
    digitalWrite(ledPin,HIGH);
  }
  else {
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.
  }
 }

Speaker Code_Particle-2

C/C++
/*
   * PIR sensor tester
   */
   
    short VPS[] = {20,127,22,180,21,120}; //array for Volume,Pitch and speed --length: 6
short Welcome[]={8,15,147,159,194,135,140};// variable for reading the pin status
  int ledPin = D1;                // choose the pin for the LED
  int inputPin = D4;               // choose the input pin (for PIR sensor)
  int pirState = LOW;             // we start, assuming no motion detected
  int val = 0;   

   
 void setup() {
  
   pinMode(ledPin, OUTPUT);      // declare LED as output
   pinMode(inputPin, INPUT);     // declare sensor as input
 Particle.subscribe("Sanin", myHandler);
   Serial.begin(9600);

  {
     //  for (int i=0; i<=5 ; i++){
    // Serial1.write(VPS[i]);//output to speakJet
     
     //Serial1.write(20);
     //delay(10);
     //}
    Serial1.write(20);
    Serial1.write(127);
    Serial1.write(22);
    Serial1.write(180);
    Serial1.write(21);
    Serial1.write(120);
    //Serial1.write(20);
  }
   
   
 }
  
 void myHandler(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.
  In this case, the event will be "buddy_unique_event_name" and the data will be "intact" or "broken"

  Since the input here is a char, we can't do
     data=="intact"
    or
     data=="broken"

  chars just don't play that way. Instead we're going to strcmp(), which compares two chars.
  If they are the same, strcmp will return 0.
  */

  if (strcmp(data,"no motion")==0) {
    // if your buddy's beam is intact, then turn your board LED off
    digitalWrite(ledPin,LOW);
    //if (Serial1.available())
 
  }
  else if (strcmp(data,"motion")==0) {
    // if your buddy's beam is broken, turn your board LED on
    digitalWrite(ledPin,HIGH);
      Serial.begin(9600);
  //if (Serial1.available())
  {
    // for (int i=0; i<=6 ; i++){
    // Serial1.write(Welcome[i]);//output to speakJet
     //Serial1.write(Welcome,7);
    // delay(10);
    // }
    
    Serial1.write(8);
    Serial1.write(15);
    Serial1.write(147);
    Serial1.write(159);
    Serial1.write(194);
    Serial1.write(135);
    Serial1.write(140);
  }
  
  delay(5000);

    

 
}
  else {
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.
  }
 }

Credits

Sarah Aljishi

Sarah Aljishi

1 project • 2 followers
Hanin Elathram

Hanin Elathram

1 project • 2 followers

Comments