Download Sample Code HERE!

PIR_2_Detection
Do NOT just copy and paste the code below. Simply click the arrow to download the file.

                    
                        // This code assumes the PIR Motion sensor is connected to pin D2 
// and the Grove LED Socket is connected to pin D4.

#define PIR_MOTION_SENSORA 2 // Motion Sensor on Pin 2 - Away from Door
#define PIR_MOTION_SENSORB 3 // Motion Sensor on Pin 3 - Nearest Door
#define LED 13 //the Grove - LED is connected to D4 of Arduino

int pirStateA = LOW;
int pirStateB = LOW;
int count = 0;

void setup()
{
    pinMode(PIR_MOTION_SENSORA, INPUT);
    pinMode(PIR_MOTION_SENSORB, INPUT);
    pinMode(LED,OUTPUT);
}

void loop()
{
  // Get current state of motion sensors.
  int valA = digitalRead(PIR_MOTION_SENSORA);
  int valB = digitalRead(PIR_MOTION_SENSORB);

  if (valA == HIGH && pirStateB == HIGH) {
    count++; // Someone entered.
    pirStateA = LOW;
    pirStateB = LOW;
    showStatus(true);
  } else if (valB == HIGH && pirStateA == HIGH) {
    count--;
    pirStateA = LOW;
    pirStateB = LOW;
    showStatus(false);
  } else {
    pirStateA = valA;
    pirStateB = valB;
  }
}

void showStatus(boolean bEntered) {
  digitalWrite(LED, HIGH);
  delay(100);
  if (bEntered) {
    digitalWrite(LED, HIGH);
    delay(100);
  } else {
    digitalWrite(LED, HIGH);
    delay(100);
    digitalWrite(LED, HIGH);
    delay(100);
    digitalWrite(LED, HIGH);
    delay(100);
  }
  digitalWrite(LED, LOW);
}