Things used in this project

Hardware components:
Photon new
Particle Photon
×2
13285 01
PIR Motion Sensor (generic)
×1
11026 02
Jumper wires (generic)
×6
12002 04
Breadboard (generic)
×2
Servo (generic)
×1
Car Cell Phone Holder
We used phone holder to hold the servo motor connected to the dead bolt.
×1

Schematics

Motion Sensor Diagram
It is the diagram of the motion sensor connected to the photon.
Motion sensor 9ecfzx21ef
Servo motor
It will lock and unlock the door when the motion sensor detects any motion.
Servo motor xicmomsygw

Code

Servo MotorC/C++
Below, is the code for the servo motor attached to the subscribing Photon. When the photons gathers the code from its publisher, the servo will rotate 110 degree and wait 5000 milliseconds before reversing the rotation back to its original position.
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
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-door", anything, "270039001147353230333635");
}

void anything(const char *event, const char *data)
{
     digitalWrite(led,HIGH);
     if (strcmp(data, "Movement")==0)
     {
myservo.write(110);
delay(5000);
myservo.write(0);
     }
}

void loop()
{
  
}
Motion SensorC/C++
This is the code for the PIR sensor. Within the code, variables are initialized and when the sensor detects motion, the command below will publish to the cloud. The information that has been published to the cloud is then capture by the subscriber photon.
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-door","Movement");
       state = !state;
       delay(5000);
   }
   delay(10);
}

Credits

312ef09b321a4407ce1ec5005a8c5a88
Ian Boone
1 project • 0 followers
Contact
Img 20161029 wa0001 hjohgdvqpm
Bivek Karki
1 project • 0 followers
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