Hamad AlalyanAhmed Bajodah
Published

Motion Detector

This is a project that uses two Particle Photons, PIR motion sensor, and LED light to detect when someone walks into the room.

IntermediateFull instructions provided4 hours1,071
Motion Detector

Things used in this project

Hardware components

Photon
Particle Photon
×2
5 mm LED: Yellow
5 mm LED: Yellow
×1
Particle PIR morion sensor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Male/Male Jumper Wires
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×2

Software apps and online services

Google Sheets
Google Sheets
Maker service
IFTTT Maker service
Fritzing
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Motion Sensor Photon Circuit

LED light Photon Circuit

Code

LED Light Code

C/C++
//Second Photon, LED
int led = D7;



void setup() {

pinMode(led, OUTPUT);
digitalWrite(led, LOW);

Particle.subscribe("invader", myHandler, "43001b001951353337343731");


}

void myHandler(const char *event, const char *data)
{
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  
}
void loop() {
delay(1000);
}

PIR Motion Sensor Code

C/C++
// First photon, Motion sensor
int inputPin = D0;              
int ledPin = D1;                
int pirState = LOW;             
int val = 0;                    

int calibrateTime = 10000;      

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     
}

void loop()
{

  
  if ( calibrated() )
  {

    readTheSensor();

   
    reportTheData();
  }
}

void readTheSensor() {
  val = digitalRead(inputPin);
}

bool calibrated() {
  return millis() - calibrateTime > 0;
}

void reportTheData() {

  
  if (val == HIGH) {

   
    if (pirState == LOW) {
     
     // Particle.publish("invader", "Detected");
      Particle.publish("invader", "1"); 
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}

void setLED( int state )
{
  digitalWrite( ledPin, state );
}

Credits

Hamad Alalyan

Hamad Alalyan

1 project • 0 followers
Ahmed Bajodah

Ahmed Bajodah

1 project • 0 followers

Comments