Javier LeonBryan Doria Gomez
Published

Motion Alarm 9000

The Motion Alarm 9000 will alert you when anyone enters your room.

IntermediateFull instructions provided1 hour20
Motion Alarm 9000

Things used in this project

Hardware components

5 mm LED: Red
5 mm LED: Red
×3
5 mm LED: Yellow
5 mm LED: Yellow
×3
Photon
Particle Photon
×2
5mm LED:White
×1
Grove - PIR Motion Sensor
Seeed Grove - PIR Motion Sensor
×1
Buzzer
Buzzer
×1

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Motion alarm schematic

Schematic iehq00ewzx

Code

Motion Sensor

Arduino
// First photon, Motion sensor
int inputPin = D0;              
int ledPin = D1;                
int pirState = LOW;             
int val = 0;
int light = D7;

int calibrateTime = 10000;      

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     
  digitalWrite(light, LOW);
  pinMode(light, OUTPUT);
  Particle.subscribe("bothways", event2, "400021000c47363433353735");
}
void setLED( int state )
{
  digitalWrite( ledPin, state );
}
void event2(const char *event, const char *data)
{
  digitalWrite(light, HIGH);
  delay(500);
  digitalWrite(light, LOW);
  //Particle.publish("test", "on");
}
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("Motion1", "Detected");
    //  delay(1500);
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}

Led alarm

Arduino
//Second Photon, LED
int led = D7;
int led2 = D4;
int led3 = D3;

void setup() {

pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
Particle.subscribe("Motion1", motion_detected, "34001b000947363339343638");


}

void motion_detected(const char *event, const char *data)
{

  Particle.publish("bothways", "on");
 // digitalWrite(led, HIGH);
  	unsigned long startTime = millis();
	while (digitalRead(D6) != LOW && millis() - startTime < 10000) {
        digitalWrite(led2, HIGH);
        digitalWrite(led, HIGH);
        delay(100);
        digitalWrite(led2, LOW);
        digitalWrite(led, LOW);
        delay(100);
        digitalWrite(led3, HIGH);
        digitalWrite(led, HIGH);
        delay(100);
        digitalWrite(led3, LOW);
        digitalWrite(led, LOW);
	}
//    digitalWrite(led, LOW);
}

Credits

Javier Leon

Javier Leon

0 projects • 0 followers
Bryan Doria Gomez

Bryan Doria Gomez

0 projects • 0 followers

Comments

Add projectSign up / Login