A modern technology banner image

Visitor counter with Automatic gate

OBJECTIVE

To develop an automatic visitor counting system using Arduino that tracks people entering and exiting through IR sensors. The system controls a gate using a servo motor and displays the current count on an LCD.

MODULES REQUIRED

  • Arduino nano
  • 2 x IR sensors
  • LCD Display 16 x 2 i2c
  • Servo (gate )

SCHEMATIC DIAGRAM

Schematic diagram showing an Arduino connected to an LED and a push button.

SCHEMATIC CONNECTION

Connect Lcd :

  • Connect the VCC pin to Arduino nano pin 5V .
  • Connect the GND pin to Arduino nano pin GND.
  • Connect the SDA pin to Arduino nano pin A4.
  • Connect the SCL pin to Arduino nano pin A5.
  • Connect IR1 and IR2 :

  • Connect the IR1 and IR2 SENSOR VCC pins to Arduino Nano pin 5V.
  • Connect the IR1 and IR2 SENSOR GND pins to Arduino Nano pin GND.
  • Connect the IR1 and IR2 SENSOR data pins to Arduino Nano pins D2 and D3.
  • Connect Servo:

  • Connect the servo Gnd pin to Arduino nano pin Gnd.
  • Connect the servo VCC pin to Arduino nano pin 5V.
  • Connect the servo sig pin to Arduino nano pin D9
  • To begin your project, click this template link:

    Simulate on Wokwi

    ARDUINO CODE

    
    
    #include (Wire.h)
    #include (LiquidCrystal_I2C.h)
    #include (Servo.h)
    
    LiquidCrystal_I2C lcd(0x27, 16, 2);  // LCD address may vary
    Servo gateServo;
    
    const int entryIR = 2;   // IR sensor at entry
    const int exitIR = 3;    // IR sensor at exit
    int peopleCount = 0;
    bool entryState = false;
    bool exitState = false;
    
    void setup() {
      pinMode(entryIR, INPUT);
      pinMode(exitIR, INPUT);
      gateServo.attach(9);
      lcd.begin(16, 2);
      lcd.backlight();
      lcd.setCursor(0, 0);
      lcd.print("Visitor Counter");
      delay(2000);
      lcd.clear();
      updateDisplay();
    }
    
    void loop() {
      // Detect Entry
      if (digitalRead(entryIR) == LOW && !entryState) {
        entryState = true;
        peopleCount++;
        openGate();
        updateDisplay();
      }
      if (digitalRead(entryIR) == HIGH) {
        entryState = false;
      }
    
      // Detect Exit
      if (digitalRead(exitIR) == LOW && !exitState) {
        exitState = true;
        if (peopleCount > 0) peopleCount--;
        openGate();
        updateDisplay();
      }
      if (digitalRead(exitIR) == HIGH) {
        exitState = false;
      }
    }
    
    void updateDisplay() {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("People Inside:");
      lcd.setCursor(0, 1);
      lcd.print(peopleCount);
    }
    
    void openGate() {
      gateServo.write(90);  // Open gate
      delay(1000);
      gateServo.write(0);   // Close gate
      delay(1000);
    }
    
    
    
    
    

    INSTRUCTIONS

  • Assemble the circuit by connecting all components as shown in the schematic diagram.
  • On the left side of the screen, open sketch.ino and write your Arduino code.
  • After completing the circuit and writing the code, click the green Play button to start the simulation.
  • Place the IR sensors at the entrance and exit to detect movement. The system will automatically open the gate for each visitor and update the count on the LCD display.
  • WORKING PRINCIPLE

  • IR sensors detect entry and exit of individuals, triggering the Arduino to update the count. The servo motor opens the gate automatically, and the LCD displays the current number of people inside.

  • Project Link

    for your reference.

    `