Back to Parent

Code
#include <time.h>
int inputPin = D2;
int lightPin = D0;
int val = 0;                   // variable for reading the pin status
int lastMailReceivedAt = 0;
int currentTime = 0;

void setup() {
  /*Initialize*/
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(lightPin, OUTPUT);
  lastMailReceivedAt = Time.now();
  Serial.begin(9600);
  digitalWrite(lightPin, LOW);
}

void loop() {
  val = digitalRead(inputPin);  // Read PIR sensor input value
  if( val == 1 ) {
    digitalWrite(lightPin, HIGH);
    currentTime = Time.now();
    /*If condition based on 30 seconds threshold, for email notification*/
    if(currentTime - lastMailReceivedAt > 30 ) {
      Particle.publish("motion-detected","You got mail", PRIVATE);
      lastMailReceivedAt = Time.now();
      delay(1000);
      digitalWrite(lightPin, LOW);
    }
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0