Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Bidirectional Visitor Counter with Automatic Light Control using Arduino
Arduino Projects

Bidirectional Visitor Counter with Automatic Light Control using Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:November 27, 20238 Comments7 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Bidirectional Visitor Counter Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

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.

Visitor Counter Light Control Arduino

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 NameQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2IR Sensor2Amazon | AliExpress
3OLED Display1Amazon | AliExpress
45V 1 Channel Relay Module1Amazon | AliExpress
55V DC Power Supply1Amazon | 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

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.

Bidirectional Visitor Counter Circuit

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.

Download Gerber File: Visitor Counter PCB

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.

Visitor Counter Hardware


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.

Visitor Counter Light Control Arduino

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

Bidirectional Visitor Counter with Automatic Light Control System using Arduino & IR Sensor
Watch this video on YouTube.

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.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleESP32/ESP8266 BME680 Weather Station & IAQ Monitoring on MQTT
Next Article DIY 3.7V to 9V Boost Converter Circuit using MC34063

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 8 Comments

8 Comments

  1. Yuda on February 9, 2022 1:36 PM

    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

    Reply
  2. edvin083 on February 17, 2022 5:20 PM

    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?

    Reply
    • Admin on February 17, 2022 6:51 PM

      Power the controller with usb cable

      Reply
  3. jemila bekele on June 22, 2022 11:57 PM

    how we can sense if two person is geting at the same time

    Reply
  4. funnah charles on July 12, 2022 5:11 PM

    how to add agsm module to the counter setup

    Reply
  5. Charles Max on November 20, 2022 2:57 AM

    How do i attach a bulb to this Project?

    Reply
  6. Max Leclerc on November 20, 2022 2:59 AM

    How do I attach a Bulb to this project?

    Reply
  7. Matt on April 20, 2023 12:31 AM

    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

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
    MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.