Created
November 16, 2018 13:58
-
-
Save pral2a/7c056334691a5124b255c1e54909bba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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