Shashwat Raj
Published © GPL3+

How to make a bidirectional visitor counter

In this project tutorial, I will show you how to make a bidirectional visitor counter with arduino, 16*2 lcd display, ultrasonic sensor.

IntermediateFull instructions provided8,558
How to make a bidirectional visitor counter

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Circuit Diagram

Use this diagram for making this project

Code

Arduino code

Arduino
Upload this code to your arduino
#include <LiquidCrystal.h>
#define trigPin 18
#define echoPin 19

LiquidCrystal lcd(2,3,4,5,6,7);
int counter = 0;
int currentState1 = 0;
int previousState1 = 0;
int currentState2 = 0;
int previousState2 = 0;
int inside = 0;
int outside = 0;

void setup()
{
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 
 lcd.begin(16,2);
 lcd.setCursor(0,0);
 lcd.print(" Visitor");
 lcd.setCursor(0,1);
 lcd.print(" Counter");
 delay(8000);
 lcd.clear();
 lcd.print(" Shashwat__Raj");
 delay(8000);
 lcd.clear();
}

void loop()
{
lcd.begin(16,2);   // iInit the LCD for 16 chars 2 lines
lcd.setCursor(0, 0);
lcd.print("IN: ");
lcd.setCursor(7, 0);
lcd.print("OUT: ");
lcd.setCursor(0, 1);
lcd.print("Total Inside: ");
long duration, distance;
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 9){
currentState1 = 1;
}
else {
currentState1 = 0;
}
delay(100);
if(currentState1 != previousState1){
if(currentState1 == 1){
counter = counter + 1;}
lcd.setCursor(14, 1);
lcd.print(counter);
inside = inside +1;}
lcd.setCursor(4, 0);
lcd.print(inside);
if (distance > 9 && distance <= 18){
currentState2 = 1;
}
else {
currentState2 = 0;
}
delay(100);
if(currentState2 != previousState2){
if(currentState2 == 1){
counter = counter - 1;}
lcd.setCursor(14, 1);
lcd.print(counter);
outside = outside +1;}
lcd.setCursor(12, 0);
lcd.print(outside);
lcd.setCursor(14, 1);
lcd.print(counter);
if (counter > 9 || counter < 0){
lcd.setCursor(14, 1);
lcd.print(counter);
delay(100);
lcd.clear();
 }
}

Credits

Shashwat Raj

Shashwat Raj

7 projects • 12 followers
My name is Shashwat Raj. I love doing projects with arduino and Raspberry Pi. You want to view more please subscribe to my YouTube Channel.

Comments