Visitor Counter

This is a small setup that can be used to count the number of people passing by any place and display it on the serial monitor of the Arduino ide. It can be used to monitor chaos occurring at any place.

HARDWARE COMPONENTS

The components required to implement this project are:

       ARDUINO UNO

       ULTRASONIC SENSOR

       BREADBOARD

       BUZZER

       JUMPER WIRES (as per the requirement)

 

CONNECTIONS:

Interfacing of  ultrasonic  sensor with Arduino Uno:

o  VCC: 5V supply 

o GND: GND of UNO

o Trig: pin number 2

o Echo: pin number 3

 

Interfacing of piezo buzzer with Arduino Uno:

o  Positive terminal : pin number 10

o  Negative terminal : GND

 

 

Circuit Design 

 


 

 

 

CODE:

 

int piezoPin = 10; // pin for the buzzer int trigPin = 2;

int echoPin = 3;

 

int val = 0; // variable for reading the pin status int counter = 0; 

int currentState = 0;

 int previousState = 0;     

 

void setup() {

 pinMode(piezoPin, OUTPUT); // declare buzzer as output   pinMode(trigPin, OUTPUT);   pinMode(echoPin, INPUT);

Serial.begin(9600);

}

 

void loop(){ 

delay(100);// reading will be taken after 100 milliseconds Serial.println("\n");

 int duration, distance; 

digitalWrite(trigPin, HIGH);   

delayMicroseconds(7); 

 digitalWrite(trigPin, LOW); 

 duration = pulseIn (echoPin, HIGH); 

 distance = (duration/2) / 29.1;

  

    if (distance < 14) {  // Change the number for different distances.

      digitalWrite(piezoPin, HIGH);

 

    }

 else {       digitalWrite(piezoPin, LOW);

    } 

 

val = digitalRead(piezoPin); // read  value if (val ==  HIGH) { // check if the input is HIGH i.e(led on) currentState = 1;

}

else { currentState = 0;

}

 

if(currentState != previousState){

  

if(currentState == 1){ counter = counter + 1;

Serial.print(" VISITOR has been passed ");

Serial.println(counter);

Serial.print("times.");

}

}

previousState = currentState;

 

}

Comments

Popular posts from this blog