Created
July 2, 2020 17:19
-
-
Save goedecke/9aa76ec551124a5d80db9524413e3e36 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 irPin1=7; | |
int irPin2=8; | |
int count=0; | |
boolean state1 = true; | |
boolean state2 = true; | |
boolean insideState = false; | |
boolean outsideIr=false; | |
boolean isPeopleExiting=false; | |
int i=1; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(irPin1, INPUT); | |
pinMode(irPin2, INPUT); | |
} | |
void loop() { | |
if (!digitalRead(irPin1) && i==1 && state1){ | |
outsideIr=true; | |
delay(100); | |
i++; | |
state1 = false; | |
} | |
if (!digitalRead(irPin2) && i==2 && state2){ | |
Serial.println("Entering into room"); | |
outsideIr=true; | |
delay(100); | |
i = 1 ; | |
count++; | |
Serial.print("No of persons inside the room: "); | |
Serial.println(count); | |
state2 = false; | |
} | |
if (!digitalRead(irPin2) && i==1 && state2 ){ | |
outsideIr=true; | |
delay(100); | |
i = 2 ; | |
state2 = false; | |
} | |
if (!digitalRead(irPin1) && i==2 && state1 ){ | |
Serial.println("Exiting from room"); | |
outsideIr=true; | |
delay(100); | |
count--; | |
Serial.print("No of persons inside the room: "); | |
Serial.println(count); | |
i = 1; | |
state1 = false; | |
} | |
if (digitalRead(irPin1)){ | |
state1 = true; | |
} | |
if (digitalRead(irPin2)){ | |
state2 = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment