Overview
In this project, we will make a Bidirectional Visitor Counter with an Automatic Light Control System using Arduino. This project is based on a pair of Infrared Sensor that detects interrupt when it detects an obstacle. The pair of IR sensors can detect the visitor from both directions, i.e. the number of entering visitors and the number of exiting visitors.
This Arduino Bidirectional Visitor Counter Project can be used to count the number of persons entering a hall, Shopping mall, office, functions in the entrance gate. It can also be used at gates of parking areas and other public places. The device counts the total number of people entering through the gate and also the total number of people leaving through the same gate. And finally, it counts the total number of people currently present inside the room. When no people are inside the room, i.e. the total number of people is zero then the room light is turned off. When even a single person is found inside the room, the light turns on. The light control system is automatic based on the visitors’ presence.
We can make the entire project using a single Arduino Nano Board. We can use a 16×2 LCD Display to show the number of visitors. But you can prefer a 0.96″ OLED Display for the project. A 5V Single channel relay gets activated when a person is detected inside a room. The light turns ON automatically which is connected to the Relay.
Bill of Materials
The list of components that you need for making Bidirectional Visitor Counter are as follows. You can purchase all the components online from Amazon.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino Nano Board | 1 | Amazon | AliExpress |
| 2 | IR Sensor | 2 | Amazon | AliExpress |
| 3 | OLED Display | 1 | Amazon | AliExpress |
| 4 | 5V 1 Channel Relay Module | 1 | Amazon | AliExpress |
| 5 | 5V DC Power Supply | 1 | Amazon | AliExpress |
IR Sensor as Visitor Detector
The main element of this project is the IR Sensor which works as a Human Detector. Whenever the IR sensor detects an interrupt it counts the person and adds it to the previous value. You can check some of our previous project made using IR Sensor Like Digital Tachometer and also the Fan Speed Measurement.
IR Sensor module has the great adaptive capability of the ambient light. It has an infrared transmitter and a receiver. The infrared emitting tube emits a certain frequency which when encounters an obstacle reflect back to the signal. The reflected signal is then received by the receiver tube. Apart from the IR Transmitter and Receiver the circuit also consists of Opamp, Variable Resistor (Trimmer pot) & output LED.
The Sensor consists of the following Parts.
1. IR LED Transmitter
IR LED emits light, in the range of Infrared frequency with a wavelength of 700nm – 1mm. IR LEDs have a light-emitting angle of approx. 20-60 degrees and has a range up to 5-10cm. IR LED white or transparent in color, so it can emit the maximum amount of light.
2. Photodiode Receiver
Photodiode acts as the IR receiver as its conducts when light falls on it. Photodiode looks like a LED, with a black color coating on its outer side. The Black color absorbs the highest amount of light.
3. LM358 Opamp
LM358 is an Operational Amplifier (Op-Amp) is used as a voltage comparator in the IR sensor. The comparator circuit compares the threshold voltage set using the preset and the photodiode’s series resistor voltage. When the Photodiode’s series resistor voltage drop is greater than the threshold voltage, the Op-Amp output is high. Similarly, when the Photodiode’s series resistor voltage drop is lesser than the threshold voltage, the Op-Amp output is low.
When the Op-Amp output is high the LED at the output terminal turns ON. This indicates an object or obstacle has been detected.
4. Variable Resistor
The variable resistor used here is preset. It is used to calibrate the distance range at which the object should be detected.
Arduino Bidirectional Visitor Counter Circuit
The hardware part of the project is very simple to assemble. We just need to connect a pair of IR Sensor, an OLED Display and a 5V Relay Module. The Circuit Diagram is given below.
You can assemble the above circuit on a breadboard. Connect the I2C Pin of OLED Display, i.e. SDA & SCL to A4 & A5 of Arduino respectively. The OLED Display requires 3.3V VCC. Similarly, connect the digital output pin of the pair of IR Sensors to 2 and 3. You can either power on the IR Sensor via 3.3V or by 5V. The Relay module needs to be controlled via the digital pin of Arduino. So, connect its Input pin to digital pin 5 of Arduino. The Relay also needs 5V Supply.
Schematic & PCB Designing
If you don’t want to assemble the circuit on breadboard, then here is the schematic for you. You can use the schematic below to design a custom PCB. I used EasyEDA, an online Schematic & PCB Designing Tool for drawing the Schematic.
After designing the Schematic for Arduino Bidirectional Visitor Counter, you can convert the schematic to PCB. The PCB looks something like this shown in the image below.
PCB Ordering & Assembly
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.
You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
After a week, I received the PCB. The PCB quality is superb and has a very high Finish.
I then assembled all the components on the PCB. The PCB board along with the mounted component makes the final hardware which needs to be tested along with the code. The hardware image is given below.
Arduino Source Code/Program for Bidirectionl Visitor Counter
The Source Code for Arduino Bidirectional Visitor Counter with Automatic Light Control System is given below. The code requires SSD1306 & GFX OLED library for compilation. First download the following libraries and add it to the Arduino IDE.
1. Download SSD1306 Library: https://github.com/adafruit/Adafruit_SSD1306
2. Download Adafruit GFX Library: https://github.com/adafruit/Adafruit-GFX-Library
You can now copy the code and upload it to the Arduino Board.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define inSensor 2 #define outSensor 3 int inStatus; int outStatus; int countin = 0; int countout = 0; int in; int out; int now; #define relay 5 void setup() { display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64) delay(2000); pinMode(inSensor, INPUT); pinMode(outSensor, INPUT); pinMode(relay, OUTPUT); digitalWrite(relay, HIGH); display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(20, 20); display.print("Visitor"); display.setCursor(20, 40); display.print("Counter"); display.display(); delay(3000); } void loop() { inStatus = digitalRead(inSensor); outStatus = digitalRead(outSensor); if (inStatus == 0) { in = countin++; } if (outStatus == 0) { out = countout++; } now = in - out; if (now <= 0) { digitalWrite(relay, HIGH); display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0, 15); display.print("No Visitor"); display.setCursor(5, 40); display.print("Light Off"); display.display(); delay(500); } else { digitalWrite(relay, LOW); display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(1); display.setCursor(15, 0); display.print("Current Visitor"); display.setTextSize(2); display.setCursor(50, 15); display.print(now); display.setTextSize(1); display.setCursor(0, 40); display.print("IN: "); display.print(in); display.setTextSize(1); display.setCursor(70, 40); display.print("OUT: "); display.print(out); display.display(); delay(500); } } |
Testing & Results
After uploading the visitor counter code to Arduino Board, the device is ready for installation. You can use a 5V DC Adapter to Power on the Device.
The device has a pair of IR Sensor module. One of the IR Sensors needs to be placed at the entrance and the other at the exit, i.e inside the room door and outside the room door.
When no visitors are inside the room, the light turns off and the OLED Display will indicate no visitors are present inside the room.
When someone makes an entry, the visitor is added and OLED Display, displays the number of incoming visitors. At this instance, the light automatically turns ON.
When a person leaves the room or exit, the visitor is subtracted. Hence the total number of current visitors is displayed on OLED. The OLED Display also displays the number of visitors who visited the room and the number of visitors who exit.
This is how an Arduino Visitor Counter with Light Control System works. You can use this project for Hall, Schools, Office, Functions, etc.
Video Tutorial & Guide
You can also check the IoT version of Visitor Counter project. In the IoT version, the visitor’s data are uploaded to MQTT Server like Ubidots.
Similarly a better version of the industrial product counter can be designed using ESP32-CAM Module using Image Processing and Recognition algorithm.




















8 Comments
Hi, I was wondering if I could combine a program for a digital thermometer into it.
so this tool not only counts the people who enter but also calculates the temperature too
I need your help! I would like to repeat this device on a breadboard, but your diagram does not indicate how to connect the power, can you show on the diagram how to connect it?
Power the controller with usb cable
how we can sense if two person is geting at the same time
how to add agsm module to the counter setup
How do i attach a bulb to this Project?
How do I attach a Bulb to this project?
Thanks for the tutorial, but:
I think your claim is wrong, that the same door can be used to enter/leave the space with this code. As seen in the video
Maybe also using a signed int as a counter is not ideal in terms of overflows