Things used in this project

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

Schematics

Servo Motor Circuit
Servo circuit febpxgst8u
PIR Motion Sensor Circuit
Pir circuit m4kednbcsi

Code

PIR Motion SensorC/C++
This code allows photon 1 to publish an event to the cloud when motion is detected.
int PIRSensor = D0;
int state=0;
void setup(){
pinMode(D7,OUTPUT);
pinMode(PIRSensor,INPUT);
}

void loop() {
    
  if (digitalRead(PIRSensor) == HIGH){
       digitalWrite(D7, (state) ? HIGH : LOW);
       Particle.publish("motion-detected","light");
       state = !state;
       delay(1000);
   }
   delay(10);
}
Servo MotorC/C++
This code allows photon 2 to trigger the servo motor by subscribing to the event published by photon 1.
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created


int pos = 75;    // variable to store the servo position
int led = D7;


void setup( ) {
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
  // attaches the servo on the D0 pin to the servo object
  myservo.attach(D0);

  // register the Spark function

  Particle.subscribe("motion-detected", monkey, "4b0050001451353432393433");
}

void monkey(const char *event, const char *data)
{
     digitalWrite(led,HIGH);
     if (strcmp(data, "light")==0)
     {
myservo.write(115);
delay(1800000);
myservo.write(75);
     }
}


void loop()
{
  
}

Credits

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

Similar projects you might like

Well House Temperature Manager
Easy
  • 283
  • 6

Full instructions

Monitors the temperature of the well house to prevent the well from freezing.

Drink Alert!!! (Beverage Can Monitor)
Easy
  • 343
  • 4

Full instructions

Tired of going to grab a soda only to find they're all gone!? Well now you have an alert system to let you know when you need to refill.

The Food Thief Catcher
Easy
  • 161
  • 4

Work in progress

Are you tired of all of your pesky roommates stealing your food? Me too, thats why we have the Food Thief Catcher!

Happy Wife =  Happy Life
Easy
  • 261
  • 3

Full instructions

Wife not a morning person? Improve your life by improving your wife's temperament in the morning. Fresh coffee makes wife happy!

Happy Wife = Happy Life

Team We Are Not Coders

Temperature Sensor
Easy
  • 401
  • 5

Full instructions

A photon that measures the temperature and humididty with a DHT 22 sensor and communicates the temperature data to another photon.

Motion Activated Room Light
Easy
  • 160
  • 4

Full instructions

With this project, you'll never have to search for the light switch in the dark again.

Add projectSign up / Login
Respect project