# Bidirectional Counter using Arduino and IR sensor

Hey guys, welcome back to the Techatronic. We are making a very useful project today which is the Bidirectional Counter. in this project we will count the person who passes through the sensor. Bidirectional counters are very common nowadays and are usually helping us during the pandemic. Bidirectional counter specifically used in the seminar halls & conference room to count the total number of people get inside the outside from the area. For example, if there are 100 people allowed in a specific place then it would automatically count the number without any man effort. ## Introduction

this project simply counts the people across the sensor. we called this bidirectional counter because in this project there are two sensors. one each at both side and with the combination of the sensors it easily count the people which are going inside and the people which are coming out. there we are using a 16×2 LCD display which is output of this project. The number of people inside and a number of people outside of the area, and also the net number of people inside the room.

## Construction of bidirectional Counter

Here, we are going to share all the required stuff and detail to make this Arduino counter project. You need to follow the given instructions and use the given data to make this project work. After completing the circuit and code assemble the circuit the same as given in the picture.

### Bidirectional Counter Code

We have done this project on Arduino Uno. So, we have used c/c++ to program this and use Arduino IDE software. we are sharing the sketch here. you need to upload the given program into your Arduino uno.

``````#include<LiquidCrystal.h>
const int rs=12, en=11, d4=5, d5=4, d6=3, d7=2 ;
const int in=6,out=7;
int temp=0,femp=0,wemp=0;

LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {
Serial.begin(9600);
lcd.begin(20,4);
pinMode(in,INPUT);
pinMode(out,INPUT);
pinMode(8, INPUT_PULLUP);
lcd.print("bidirectional counter");
lcd.setCursor(0,1);
lcd.print("IN");
lcd.setCursor(6,1);
lcd.print(femp);

lcd.setCursor(0,2);
lcd.print("OUT");
lcd.setCursor(6,2);
lcd.print(wemp);

lcd.setCursor(0,3);
lcd.print("NET");
lcd.setCursor(6,3);
lcd.print(temp);

}

void loop() {

if(m==1)
{

{
delay(100);
{
temp=temp+1;
femp=femp+1;
wemp;

lcd.clear();

lcd.print("HOPE SECURITY");
lcd.setCursor(0,1);
lcd.print("IN");
lcd.setCursor(6,1);
lcd.print(femp);

lcd.setCursor(0,2);
lcd.print("OUT");
lcd.setCursor(6,2);
lcd.print(wemp);

lcd.setCursor(0,3);
lcd.print("NET");
lcd.setCursor(6,3);
lcd.print(temp);

delay(1000);
}}
{   delay(100);
{
temp=temp-1;
femp;
wemp=wemp+1;
// if(temp<=0)
//{temp=0;
//wemp=0;
//femp=0;
//    }

lcd.clear();
lcd.print("HOPE SECURITY");
lcd.setCursor(0,1);
lcd.print("IN");
lcd.setCursor(6,1);
lcd.print(femp);

lcd.setCursor(0,2);
lcd.print("OUT");
lcd.setCursor(6,2);
lcd.print(wemp);

lcd.setCursor(0,3);
lcd.print("NET");
lcd.setCursor(6,3);
lcd.print(temp);

delay(1000);
}}

}

else
{lcd.clear();
lcd.print("HOPE SECURITY");

femp=0;
temp=0;
wemp=0;
lcd.setCursor(0,1);
lcd.print("IN");
lcd.setCursor(6,1);
lcd.print(femp);

lcd.setCursor(0,2);
lcd.print("OUT");
lcd.setCursor(6,2);
lcd.print(wemp);

lcd.setCursor(0,3);
lcd.print("NET");
lcd.setCursor(6,3);
lcd.print(temp);
}

}``````

## Bidirectional Counter Working

Working of a Bidirectional counter is very simple. first of all, we should refer to the components list to understand the working of each of the components. so first we would like to point to the sensor. we are using the IR sensor here to detect the presence of any person in front of the sensor. like if anyone comes in front of the sensor the sensor will detect and pass this information. if you want to see in full detail what is the working of IR sensor. you can see this on my website.

Now the next part is the controller or the CPU of this project. We are using Arduino Uno as the Controller of this project. Of course, we need a controller which will control all the things in this project. like getting input processing and giving output. It is the brain part of this system. It is getting input from the IR sensor. Basically, we interface the IR sensor with Arduino. It is also known as the Arduino counter. Arduino gets the input from the IR sensor and processes the input and according to the input the Arduino will take action according to the condition.

The last part of the system will be done by Arduino which is the Output of this project. Also, Arduino will send the information to the display on what should print on the display this controller will decide.

We are using here the 16×2 LCD display which displays all the detail about the project and the counting of the people. people went outside the room and inside the room also the total number of people inside the room. Liquid crystal display using the analog signal to lit the crystal for the desired numbers or letters. if you still getting trouble connecting the Display refer to our 16X2 display with Arduino.

Let’s understand the working of bidirectional counter project there are two sensors named the first sensor is S1 and the other sensor is s2 When a person crosses the S1 sensor first the system will wait for the s2 sensor to be crossed. if both conditions will true the project will count the person who went inside the sensor. next, if the s2 sensor is crossed first and then the s1 sensor will be crossed by a person then it will count the person who goes outside the system or room. This is how the bidirectional counter works. we have given all the detail like the code and circuit for the bidirectional visitor counter using Arduino

## Application of Bidirectional Counter

Use in Seminar hall to count the People

Use in Conference hall to count the people

Can be also used in school and college classes

can also be used in parking

## FAQ on Bidirectional Counter

question1:- What if one sensor not working in the bidirectional counter

answer1. :- we need to change the sensor after finding otherwise it will give the wrong information

question2:- How accurate the bidirectional counter

answer2. :- the bidirectional counters are much more accurate in all condition

question3:- IR sensor error possibility

answer3:- yes, their sensor not properly works in sunlight