Skip to content

Instantly share code, notes, and snippets.

@pral2a
Created November 16, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pral2a/7c056334691a5124b255c1e54909bba7 to your computer and use it in GitHub Desktop.
Save pral2a/7c056334691a5124b255c1e54909bba7 to your computer and use it in GitHub Desktop.
int const PIRpin = 2;
unsigned long previousMillis = 0;
const long interval = 2000;
int prevPinStatus = 0;
long presenceCounter = 0;
void setup() {
Serial.begin(9600);
pinMode(PIRpin, INPUT);
prevPinStatus = digitalRead(PIRpin);
}
void loop() {
int PIRstatus = digitalRead(PIRpin);
if (PIRstatus == 1) {
presenceCounter++;
if (presenceCounter > 10) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.println("In");
presenceCounter = 0;
}
}
} else {
presenceCounter = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment