Arduino Bidirectional Visitor Counter
by ashsebdav2001 in Circuits > Arduino
4384 Views, 4 Favorites, 0 Comments
Arduino Bidirectional Visitor Counter
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 16x2 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.
Supplies
Equipments Required :
1] Arduino Board Arduino Nano
2] IR Sensor IR Infrared Sensor Module
3] OLED Display 0.96" I2C OLED Display
4] Relay Module 5V - 1 Channel Relay Module
5] Power Supply 5V Supply
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.
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.
Source Code
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.
#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.