Radha PatelJason Solomon
Published

R&J Motion Detector

Having your personal space intruded upon can leave you feeling frustrated and violated. The R&J motion detector alerts users of such events.

IntermediateWork in progress5 hours607
R&J Motion Detector

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
3 mm LED: Green
3 mm LED: Green
×1
Jumper wires (generic)
Jumper wires (generic)
×7
Buzzer
Buzzer
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Data Recording

Data Recording

Data Recording

Data Recording

PIR Sensor Circuit Diagram

This device is used to detect motion

LED/Buzzer Reciever Circuit Diagram

This device alerts user that motion has been detected near the PIR sensor

R&J Inc. - Motion Detector Kit

This is the R&J Motion Detector Kit, which includes a motion detector and motion detector Indicator (Intruder Alert !)

Photon Circuits

This is what the Photon circuits look like prior to their final assembly

Code

LED Indicating

C/C++
This code is used to analyze data collected from the PIR sensor, and enable the LED and buzzer when appropriate. This code subscribes and published to the PIR sensing code, and thus a secondary photon, to create bi-directional communication.
int buzz = D0;

int led = D7;

void setup ()
{
    pinMode(buzz,OUTPUT);
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
    
    Particle.subscribe("motion-detected", myAlert, "27003b001247343438323536");
    delay(3000);
}

void myAlert(const char *event, const char *data)
{
    if (strcmp(data, "1") == 0){
      digitalWrite(led,HIGH);
      delay(500);
      digitalWrite(led,LOW);
      
      digitalWrite(buzz,HIGH);
      delay(200);
      digitalWrite(buzz,LOW);
      
      Particle.publish("motion-d", "1");
      data = "0";
    }
    
      
}

PIR Sensing

C/C++
This code is responsible for recording and publishing the data collected by the PIR sensor to an external database, namely ThingSpeak, for graphical purposes, and the second photon. It also subscribes to the LED sensing code, and enables an LED, on the second photon to create bi-directional communication.
int PIRSensor =D0; // choose pin the input pin (For PIR sensor)
int state = LOW; // We start, assuming no motion detected
int Motion = 0; // variable for reading pin status
int Update = 0;
int led = D7;
const String key = "GPAV51OAX8RKQTQX";

void setup() {
    Particle.subscribe("motion-d", state1, "420027000247353138383138");
    pinMode(D7,OUTPUT); // delcare D7 led as output
    pinMode(PIRSensor,INPUT); // decalr sensor as input
    
}
void state1(const char *event, const char *data){
    if (state == HIGH)
        digitalWrite(led,HIGH);
        delay(500);
        digitalWrite(led,LOW);
}

void loop() {
  
    Motion = digitalRead(PIRSensor); // read input value
    delay(20000);
    if (Motion == HIGH) {           // chech if input is HIGH
        //digitalWrite(D7,HIGH);
        Particle.publish("motion-detected","1");
        state = HIGH;
    }
    
    Particle.publish("Motion", + "{ \"1\": \"" + String(state) + "\"," + "\"k\": \"" + key + "\" }",60, PRIVATE);
}

Credits

Radha Patel

Radha Patel

1 project • 1 follower
Mechanical Engineering Student at UNCC.
Jason Solomon

Jason Solomon

1 project • 0 followers
Jason Solomon is a Mech. Eng. student at UNCC. He has 15 years experience in the Staffing/Recruiting industy, both civilian and military.

Comments