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

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

Particle Photon Based Security System with Alerting
Intermediate
  • 1,345
  • 20

Full instructions

Be alerted to any door or window opening and closing in your house on your smart phone.

Happy Plant Notifier
Intermediate
  • 290
  • 5

Full instructions

Get a text or call if your plant is getting too dry, along with a nice LCD display giving information regarding your plant's health.

My Guardian for the Workshop
Intermediate
  • 202
  • 4

Full instructions

Device will send emails if the door or window has been opened, and will monitor the temperature and humidity of the place.

Smart and Safe Outdoor Plant Watering System
Intermediate
  • 2,526
  • 18

Monitors soil moisture and weather forecasts to give plants just the water they need. Safe garden hose hookup for season long watering.

Christmas Gift Box
Intermediate
  • 3,684
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Carbon Fiber Vacuum Chamber
Intermediate
  • 3,035
  • 94

Full instructions

Our project is a carbon fiber vacuum chamber that is monitored by multiple particle photons and various sensors.

Add projectSign up / Login