Ian BooneBivek Karki
Published © GPL3+

Motion Sensor Smart Lock

It is an effortless way to lock/unlock your door!

IntermediateFull instructions provided8 hours394
Motion Sensor Smart Lock

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Breadboard (generic)
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

Story

Read more

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 Motor

C/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 Sensor

C/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

Ian Boone

Ian Boone

1 project • 0 followers
Contact
Bivek Karki

Bivek Karki

1 project • 0 followers
Contact

Comments

Add projectSign up / Login