Bidirectional Visitor Counter With Automatic Light Control

by sadarsh312 in Circuits > Arduino

87 Views, 0 Favorites, 0 Comments

Bidirectional Visitor Counter With Automatic Light Control

WhatsApp Image 2021-11-14 at 8.10.03 PM.jpeg

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.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. This project can also be used to count the number of objects that passed by the sensor in an factory or other related places.

Supplies

1) Arduino Board Arduino Nano Quantity: 1 Link: https://amzn.to/2tsBbp1

2) IR SensorIR Infrared Sensor Module Quantity: 2 Link: https://amzn.to/3dNiCkr

3) OLED Display0.96" I2C OLED Display Quantity:1 Link: https://amzn.to/2XaQ5uz

4) Relay Module5V 1 Channel Relay Module Quantity:1 Link: https://amzn.to/3bFiwbL

5) Power Supply5V Supply Quantity:1 Link: https://amzn.to/37OuKOn

Arduino Bidirectional Visitor Counter Circuit

circuit.jpeg

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 above.

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. The relay is used for controlling the lights.

Code

Screenshot 2021-11-14 203828.png
Screenshot 2021-11-14 203850.png
Screenshot 2021-11-14 203906.png
Screenshot 2021-11-14 203922.png

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.



#include <Adafruit_SSD1306.h>

#include <splash.h>

#include<Wire.h>


#include <Adafruit_GFX.h>

#include <Adafruit_GrayOLED.h>

#include <Adafruit_SPITFT.h>

#include <Adafruit_SPITFT_Macros.h>

#include <gfxfont.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);

 }

}

Final Circuit

f.jpeg
g.jpeg