8 spots Smart Parking Using Arduino and 74HC165 Shift Register

Smart Parking Management System Using Arduino and 74HC165 Shift Register
As urban areas grow and parking spaces become increasingly limited, efficient parking management systems have become essential. This project demonstrates a Smart Parking Management System that monitors the status of 8 parking spots, controls entry and exit gates using servo motors, and provides real-time feedback via an LCD and LEDs. By leveraging a 74HC165 shift register, the system efficiently manages multiple parking spots while minimizing the number of Arduino pins required.

Project Overview

Global schematic


The Smart Parking Management System integrates the following features:

  1. Parking Spot Monitoring:

    • Monitors up to 8 parking spots using sensors.
    • Displays parking statuses (X for occupied, Y for free) on a 16x2 LCD screen.
  2. Gate Control:

    • Opens the entry gate when a car is detected at the entry sensor and a parking spot is available.
    • Opens the exit gate when a car is detected at the exit sensor.
  3. LED Feedback:

    • A green LED lights up when the entry gate opens.
    • A red LED lights up when the parking lot is full, indicating no entry is allowed.
  4. Shift Register Integration:

    • The 74HC165 shift register efficiently reads the states of the 8 parking spots using just 3 Arduino pins.

System Workflow

  1. Parking Spot Monitoring:

    • Each parking spot is equipped with a sensor connected to the shift register.
    • The shift register converts the parallel sensor inputs into serialized data, which is sent to the Arduino.
    • The Arduino processes this data to determine which spots are occupied or free.
  2. Entry Control:

    • When a car is detected at the entry IR sensor:
      • If a spot is available, the green LED turns on, and the entry gate opens.
      • If all spots are full, the red LED lights up, and the gate remains closed.
  3. Exit Control:

    • When a car is detected at the exit IR sensor, the exit gate opens to allow the car to leave.
  4. Real-Time Feedback:

    • The 16x2 LCD displays:
      • Row 1: Labels for the 8 parking spots (1|2|3|4|5|6|7|8).
      • Row 2: Current statuses of the spots (X|Y|X|Y|...).
    • LEDs provide additional visual feedback for gate operations.

Hardware Requirements

ComponentQuantityDescription
Arduino Uno1Main microcontroller board
16x2 LCD Display1Displays parking status
74HC165 Shift Register1Reads parking spot statuses
IR Sensors2Detects car entry and exit
Servo Motors2Controls entry and exit gates
Green LED1Indicates gate is opening
Red LED1Indicates parking is full
Parking Spot Sensors8Monitors occupancy of each parking spot
Resistors8Pull-down resistors for parking sensors
Jumper WiresAs neededFor connecting components
Breadboard1For prototyping and connections

Hardware Connections

Shift Register (74HC165)
  • SH/LD (Shift/Load): Connect to Arduino pin A1.
  • CLK (Clock): Connect to Arduino pin 3.
  • SO (Serial Output): Connect to Arduino pin 2.
  • D0-D7 (Parallel Inputs): Connect to sensors monitoring the parking spots.
  • VCC: Connect to Arduino 5V.
  • GND: Connect to Arduino GND.
IR Sensors
  • Entry IR Sensor:
    • VCC: Connect to Arduino 5V.
    • GND: Connect to Arduino GND.
    • OUT: Connect to Arduino pin 4.
  • Exit IR Sensor:
    • VCC: Connect to Arduino 5V.
    • GND: Connect to Arduino GND.
    • OUT: Connect to Arduino pin 5.
Servo Motors
  • Entry Gate Servo:
    • Signal: Connect to Arduino pin A2.
    • VCC: Connect to Arduino 5V.
    • GND: Connect to Arduino GND.
  • Exit Gate Servo:
    • Signal: Connect to Arduino pin A3.
    • VCC: Connect to Arduino 5V.
    • GND: Connect to Arduino GND.
LEDs
  • Green LED:
    • Anode: Connect to Arduino pin 7 (with a 220Ω resistor).
    • Cathode: Connect to GND.
  • Red LED:
    • Anode: Connect to Arduino pin 6 (with a 220Ω resistor).
    • Cathode: Connect to GND.
16x2 LCD
  • RS: Connect to Arduino pin 13.
  • E: Connect to Arduino pin 12.
  • D4-D7: Connect to Arduino pins 11, 10, 9, 8.
  • VSS: Connect to GND.
  • VDD: Connect to 5V.
  • VO: Connect to the middle pin of a potentiometer (contrast control).

Software Functionality

Code:

#include <Wire.h>
#include <LiquidCrystal.h>
#include <Servo.h>

// LCD pins
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

// 74HC165 pins
#define SH_LD A1  // Shift/Load Bar pin
#define CLK 3     // Clock pin
#define SO 2      // Serial Output pin
#define green 7    // Green LED for gate open
#define red 6      // Red LED for parking full

// IR sensors
#define ENTRY_SENSOR 4   // Entry sensor pin
#define EXIT_SENSOR 5    // Exit sensor pin

// Servo motors
Servo entryGateServo;  // Servo for entry gate (A4)
Servo exitGateServo;   // Servo for exit gate (A3)

// Number of parking spots
const int NUM_SPOTS = 8; // Updated to handle 8 spots
bool spots[NUM_SPOTS];   // Parking spot statuses
int freeSpots = NUM_SPOTS; // Counter for free spots

void setup() {
  // LCD setup
  lcd.begin(16, 2);
  lcd.clear();

  // Servo setup
  entryGateServo.attach(A2);
  exitGateServo.attach(A3);
  entryGateServo.write(0); // Keep entry gate closed
  exitGateServo.write(0);  // Keep exit gate closed

  // 74HC165 control pins
  pinMode(SH_LD, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(SO, INPUT);
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  digitalWrite(green, LOW); // Turn off green LED initially
  digitalWrite(red, LOW);   // Turn off red LED initially
  digitalWrite(SH_LD, LOW); // Activate parallel load
  digitalWrite(CLK, LOW);   // Pulse the clock to shift data

  // IR sensors
  pinMode(ENTRY_SENSOR, INPUT);
  pinMode(EXIT_SENSOR, INPUT);

  Serial.begin(9600);
}

void loop() {
  // Read parking spot statuses
  readShiftRegister(spots);

  // Calculate the number of free spots
  freeSpots = 0;
  for (int i = 0; i < NUM_SPOTS; i++) {
    if (!spots[i]) { // If the spot is free
      freeSpots++;
    }
  }

  // Handle entry
  if (digitalRead(ENTRY_SENSOR) == HIGH) {
    if (freeSpots > 0) {
      digitalWrite(green, HIGH);      // Green LED ON
      entryGateServo.write(90);       // Open entry gate
      delay(500);                     // Keep gate open for 500 ms
      entryGateServo.write(0);        // Close gate
      digitalWrite(green, LOW);       // Green LED OFF
    } else {
      digitalWrite(red, HIGH);        // Red LED ON
      delay(500);                     // Keep LED ON for 500 ms
      digitalWrite(red, LOW);         // Red LED OFF
    }
  }

  // Handle exit
  if (digitalRead(EXIT_SENSOR) == HIGH) {
    exitGateServo.write(90);          // Open exit gate
    delay(500);                       // Keep gate open for 500 ms
    exitGateServo.write(0);           // Close gate
  }

  // Update the LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("1|2|3|4|5|6|7|8|"); // Labels for spots
  lcd.setCursor(0, 1);
  for (int i = 0; i < NUM_SPOTS; i++) {
    lcd.print(spots[i] ? "X|" : "Y|"); // Display spot statuses
  }

  delay(500); // Refresh every 500 ms
}

// Function to read the shift register
void readShiftRegister(bool ar[NUM_SPOTS]) {
  digitalWrite(SH_LD, LOW);   // Activate parallel load
  delayMicroseconds(5);       // Wait for data to load
  digitalWrite(SH_LD, HIGH);  // Set to shift mode

  for (int i = 0; i < NUM_SPOTS; i++) {
    digitalWrite(CLK, LOW);  // Pulse the clock to shift data
    delayMicroseconds(5);
    ar[i] = digitalRead(SO); // Read the SO pin and store the bit
    digitalWrite(CLK, HIGH);
    delayMicroseconds(5);
  }
}


  1. Initialization (setup):

    • Configures the pins for the LCD, servos, shift register, IR sensors, and LEDs.
    • Initializes the LCD to display parking information.
  2. Parking Spot Monitoring:

    • The readShiftRegister function reads the state of 8 parking spot sensors via the shift register.
    • The statuses are stored in the spots[] array.
  3. Entry Gate Control:

    • If a car is detected at the entry IR sensor:
      • If there’s a free spot:
        • The green LED turns on.
        • The entry gate servo opens for 500ms and then closes.
      • If all spots are full:
        • The red LED turns on briefly to indicate the parking is full.
  4. Exit Gate Control:

    • If a car is detected at the exit IR sensor, the exit gate servo opens for 500ms and then closes.
  5. Real-Time Display:

    • The LCD displays:
      • Row 1: Labels for all 8 parking spots.
      • Row 2: Current status of each spot (X for occupied, Y for free).

Expected Output
example of passing car and parking

LCD Example Output:

  • When parking has free spots:

    1|2|3|4|5|6|7|8| Y|X|Y|X|Y|Y|Y|X|
  • When parking is full:

    1|2|3|4|5|6|7|8| X|X|X|X|X|X|X|X|

LED Behavior:

  • Green LED: Lights up when the entry gate opens.
  • Red LED: Lights up when parking is full.

Applications

  1. Parking Facilities:
    • Ideal for managing entry and exit in parking lots.
  2. Smart City Projects:
    • Can be integrated into IoT systems for remote parking management.
  3. Scalable Parking Solutions:
    • Supports expansion by daisy-chaining additional shift registers for more spots.

Comments