Skip to content

Commit

Permalink
Merge pull request #25 from Roshanteja21/main
Browse files Browse the repository at this point in the history
Bidirectional counter
  • Loading branch information
jaguar017 authored Oct 5, 2021
2 parents 906ec51 + 3860675 commit f3d361c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Binary file not shown.
62 changes: 62 additions & 0 deletions Bidirectional Counter/Bidirectional_counter/COUNTING/COUNTING.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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;
}

}

0 comments on commit f3d361c

Please sign in to comment.