How to make a smart parking with Arduino

 

Project Description: Smart Parking Management System

This project implements a smart parking system capable of monitoring parking spots, controlling entry and exit gates using servo motors, and providing visual feedback using LEDs and an LCD. The system leverages the 74HC165 shift register to efficiently monitor the status of 4 parking spots while using minimal Arduino pins.


Key Features

  1. Real-Time Parking Monitoring:

    • Monitors up to 4 parking spots using sensors connected to a 74HC165 shift register.
    • Displays the status of parking spots on a 16x2 LCD:
      • X: Spot is occupied.
      • Y: Spot is free.
  2. Entry and Exit Control:

    • Entry IR Sensor: Detects incoming cars and opens the entry gate if a spot is free.
    • Exit IR Sensor: Detects outgoing cars and opens the exit gate.
  3. LED Feedback:

    • Green LED: Lights up when the gate opens for an incoming car.
    • Red LED: Lights up if the parking lot is full and the entry gate cannot open.
  4. Servo Motor Control:

    • Entry Gate Servo: Opens and closes the entry gate.
    • Exit Gate Servo: Opens and closes the exit gate.
  5. Efficient Resource Usage:

    • Uses a 74HC165 shift register to minimize the number of pins required to monitor parking spots.

Schematic

The connections of the arduino with the shifter, the servo motors, the leds and the ir sensors



System Workflow

  1. Parking Spot Monitoring:

    • Sensors connected to the shift register detect whether a spot is occupied.
    • The status of all spots is displayed on the 16x2 LCD.
  2. Entry Detection:

    • When a car is detected at the entry IR sensor:
      • If there’s at least one free spot:
        • The green LED turns on.
        • The entry gate servo opens for 500 ms, allowing the car to enter.
      • If all spots are full:
        • The red LED turns on for 500 ms, and the gate remains closed.
  3. Exit Detection:

    • When a car is detected at the exit IR sensor, the exit gate servo opens for 500 ms to allow the car to exit.
  4. Real-Time Display:

    • The LCD continuously displays the status of all parking spots.

Hardware connections

The first pins of the arduino with the shifter, the servo motors, the leds and the ir sensors


The second pins of the arduino with the shifter, the servo motors, the leds and the ir sensors


Software Explanation

  1. Initialization:

    • Initializes the LCD, servos, and shift register.
    • Configures the IR sensors and LEDs as inputs/outputs.
  2. Parking Spot Monitoring:

    • Reads the statuses of parking spots from the 74HC165 shift register.
    • Updates the spots[] array and calculates the number of free spots.
  3. Entry Control:

    • If the entry IR sensor detects a car:
      • The entry gate opens if there are free spots.
      • If all spots are full, the red LED turns on to signal a full parking lot.
  4. Exit Control:

    • If the exit IR sensor detects a car, the exit gate opens to allow the car to leave.
  5. LCD Update:

    • Continuously displays the statuses of all parking spots on the LCD.
  6. Shift Register Reading:

    • Reads data from the 74HC165 using clock pulses to determine the occupancy of parking spots.

Full 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
#define red 6
// 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 = 4;
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);   // Activate parallel load
  digitalWrite(red, LOW);
  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);
      entryGateServo.write(90); // Open entry gate
      delay(500);             // Keep gate open for 5 seconds
      entryGateServo.write(0);
      digitalWrite(green, LOW);
 // Close gate
    } else {
      digitalWrite(red, HIGH);
      delay(500);
      digitalWrite(red, LOW);
    }
  }
  // Handle exit
  if (digitalRead(EXIT_SENSOR) == HIGH) {
    exitGateServo.write(90); // Open exit gate
    delay(500);             // Keep gate open for 5 seconds
    exitGateServo.write(0);  // Close gate
  }
  // Update the LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("1|2|3|4|");
  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);
  }
}

    Applications

    1. Smart Parking Lots:
      • Ideal for managing entry and exit gates in a parking facility.
    2. IoT Integration:
      • Can be expanded to send real-time parking data to an online platform.
    3. Scalable Parking Solutions:
      • Easily expandable to handle more parking spots using additional 74HC165 shift registers.
    Learn how to make a smart parking lot with Arduino Uno through various Arduino Uno easy projects for beginners. Discover engaging Arduino Uno projects with code and explore Arduino Uno Proteus 8 simulations with code to enhance your understanding. Our comprehensive Arduino tutorials cover a variety of Arduino useful projects, including Arduino UNO shift register projects and a detailed shift register Proteus tutorial. Each shift register project with code is designed to help you grasp the concepts better. Check out our Proteus 8 projects featuring the latest Arduino projects and innovative microcontroller projects using Arduino. Whether you’re looking for an Arduino final year project or simply want to expand your skills, we have resources to support your learning journey!

    Comments