Kelvin Yong
Published

Automated Visitor Counter

Amidst of COVID 19. Many places has set SOP to enter premises. Setting the limit for occupants entering is key one on social distancing.

BeginnerFull instructions provided5 hours3,241
Automated Visitor Counter

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×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

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Schematics

AVC schematic

Code

AVC

Arduino
One distance sensors, 75cm for IN lane, 75 till 180cm for OUT lane
#include <LiquidCrystal.h>
const int trigPin=7, echoPin=8 ;
const int rs=12, en=11, d4=5, d5=4, d6=3, d7=2 ;
//const int buttonPin=6;
const int ledPin=13;    //led & buzzer
int counter = 0;
int currentState1 = 0;
int previousState1 = 0;
int currentState2 = 0;
int previousState2 = 0;
int inside = 0;
int outside = 0;
//int buttonState=0;      //disabled

LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup()
{
 // initialize the LCD
Serial.begin (9600);
lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
//pinMode(buttonPin, INPUT);
}

void loop()
{
lcd.setCursor(0, 0);
lcd.print("IN: ");
lcd.setCursor(8, 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 (counter >= 30)
{
digitalWrite(ledPin, HIGH); //LED & Buzzer ON
delay(100);                //100ms
digitalWrite(ledPin, LOW);  //LED & Buzzer OFF
lcd.setCursor(0, 1);
lcd.print("exceed limit");
Serial.println((String)" Total Inside: " + counter + "  Outside: " + outside + " Exceed Limit ");             
}
if (distance <= 75)      
{
delay(300);            
currentState1 = 1;
digitalWrite(ledPin, HIGH);
delay(100);                
digitalWrite(ledPin, LOW); 
}
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 > 75 && distance <= 170)
{
delay(300);
currentState2 = 1;
digitalWrite(ledPin, HIGH);
delay(100);                
digitalWrite(ledPin, LOW);
}
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(13, 0);
lcd.print(outside);
lcd.setCursor(14, 1);
lcd.print(counter);
Serial.println((String)"Total Inside:" + counter + "  Outside: " +outside);  //added by me
if (distance > 75 || distance < 0)   //deleted by me
{
delay(300);            //setup today
lcd.setCursor(14, 1);
lcd.print(counter);
delay(1000);
lcd.clear();
}
}

Credits

Kelvin Yong

Kelvin Yong

3 projects • 3 followers
Government servant in Sarawak. Strong interest in electronic and IOT related.
Thanks to Roboticadiy.com.

Comments