ahmed elbazDemetrio Ramos
Published

The Locker

Two Photon Particles are used to detect motion and lock\unlock the door when motion is detected.

IntermediateFull instructions provided5 hours1,032

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Legos
×1
Servos (Tower Pro MG996R)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

Servo Motor Diagram

PIR Sensor Data

This is the data gathered from the PIR Sensor. If the sensor detected motion then it was labeled as 1. If there were no motion then it was labeled as 0. The data was captured at least an hour while testing. It shown in increments of five minutes.

PIR Schematic Diagram

Code

PIR sensor code

C/C++
To sum up this code initializes the variables that will be used in the loop statement. Which states if if the motion sensor senses movement to publish that information to the cloud. motion-door is the event name and Movement is the data that is sent to the cloud.
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);
}

Servo Motor Publish

C/C++
This is the script for the servo motor that is connected to the second particle that will subscribe to the PIR sensor particle that published the information.
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(175);
delay(5000);
myservo.write(0);
     }
}

void loop()
{
  
}

Credits

ahmed elbaz

ahmed elbaz

2 projects • 1 follower
Mechanical Engineering Student at UNCCharlotte
Demetrio Ramos

Demetrio Ramos

1 project • 1 follower
UNCC Mechanical Engineering Student MEGR 3171 Fall 2016

Comments