Ingo Lohs
Published © GPL3+

MyPIR-Sensor Informs Me Via IFTTT

Cheap & easy alarm-system.

BeginnerFull instructions provided1 hour1,350
MyPIR-Sensor Informs Me Via IFTTT

Things used in this project

Hardware components

Photon
Particle Photon
in my case I used a Particle/Spark Core
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Buzzer
Buzzer
active buzzer thats makes "peep"
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
counted around 7
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

Schematic

Code

Ingos Code

C/C++
// PIR Sensor triggers IFTTT-Services to inform a motion detection

// Ingo Lohs, v1.0 - 17.05.2017

int inputPin = D0;              // choose the input pin (for PIR sensor)
int ledPin = D1;                // LED Pin
int buzzerPin = D2;             // Sound in case of motion detected
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int boardLed = D7;              // photon onBoard LED
int calibrateTime = 10000;      // wait for the thingy to calibrate

void setup() {

  pinMode(boardLed,OUTPUT);     // on-board LED 
  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(inputPin, INPUT);     // declare sensor as input
  
     // Now flash the D7 LED on and off 
  digitalWrite(boardLed,HIGH); // Start der Kallibrierung mit D7 on
  Particle.publish("Nicks Security Project","now online",100,PRIVATE);
  digitalWrite(boardLed,LOW); // Start der Kallibrierung mit D7 off

}
 
void loop() {
  
  // if the sensor is calibrated
  if ( calibrated() )
  {
  // get the data from the sensor
    readTheSensor();

    // report it out, if the state has changed
    reportTheData();
  }
}
 


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


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


void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("Nicks Security Project", "Motion detected", PRIVATE);

      pirState = HIGH;
      setLED( pirState );

    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}


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

Credits

Ingo Lohs

Ingo Lohs

182 projects • 194 followers
I am well over 50 years and come from the middle of Germany.

Comments