Weekly Trending

How to Build a Smart Car Parking System with Arduino: A Step-by-Step Guide

How to Build a Smart Car Parking System with Arduino: A Step-by-Step Guide

Description:

Learn how to build a Smart Car Parking System using Arduino. This DIY project uses I2C LCD displays, IR sensors, and a servo motor to automate parking gate control and slot monitoring. In this tutorial, we’ll guide you through setting up the system and scanning for I2C devices, helping you develop an efficient parking system from scratch.

**Alt Text:**   "Step-by-step guide for building a smart car parking system using Arduino, IR sensors, servo motor, and I2C LCD display. The system automates gate control and monitors available parking slots, providing real-time feedback on the LCD screen."

You will also learn how to scan for I2C devices, which helps identify the address of your connected LCD display, ensuring smooth integration of your components.


**Alt Text:**   "Step-by-step guide for building a smart car parking system using Arduino, IR sensors, servo motor, and I2C LCD display. The system automates gate control and monitors available parking slots, providing real-time feedback on the LCD screen."

Step 1: Components Required

Before starting the project, ensure you have the following components:

  • Arduino UNO x1
  • IR Sensors x2 (for car detection)
  • Servo Motor x1 (for gate control)
  • I2C LCD Display (16x2) x1 (for slot status display)
  • Breadboard (optional, for clean wiring)
  • Jumper Wires (Male-to-Male)

Step 2: Understanding the I2C Scanner Code

Before we connect the LCD display, we need to determine its I2C address using an I2C Scanner. Every I2C device has a unique address that the Arduino uses to communicate with it. The following code will help scan and find the I2C address of the LCD display or any other I2C device.

I2C Scanner Code:

#include <Wire.h>


void setup() {

  Wire.begin();

  Serial.begin(9600);

  Serial.println("\nI2C Scanner");

}


void loop() {

  byte error, address;

  int Devices;

  Serial.println("Scanning...");

  Devices = 0;


  for(address = 1; address < 127; address++ ) {

    Wire.beginTransmission(address);

    error = Wire.endTransmission();


    if (error == 0) {

      Serial.print("I2C device found at address 0x");

      if (address < 16)

        Serial.print("0");

      Serial.print(address, HEX);

      Serial.println("  !");

      Devices++;

    } else if (error == 4) {

      Serial.print("Unknown error at address 0x");

      if (address < 16)

        Serial.print("0");

      Serial.println(address, HEX);

    }

  }


  if (Devices == 0)

    Serial.println("No I2C devices found\n");

  else

    Serial.println("done\n");


  delay(5000);

}


How to Use the I2C Scanner:

  1. Upload the Code: Upload the above code to your Arduino UNO.
  1. Open the Serial Monitor: After uploading, open the serial monitor at 9600 baud rate.
  1. Scan for Devices: The scanner will begin searching for I2C devices connected to your Arduino. It will display the device address in hexadecimal format (e.g., 0x27).
  1. Note the I2C Address: This address is essential for configuring the LCD display in the next steps.

Step 3: Wiring the Parking System Components

  • Now that we have the I2C address of the LCD, we can wire up the parking system components, including the IR sensors, servo motor, and LCD display.

Connections:

  1. IR Sensors:

    • IR1 (Entry Detection):
      • VCC → Arduino 5V
      • GND → Arduino GND
      • OUT → Arduino Pin 4
    • IR2 (Exit Detection):
      • VCC → Arduino 5V
      • GND → Arduino GND
      • OUT → Arduino Pin 7
  2. Servo Motor (Gate Control):

    • VCC → Arduino 5V
    • GND → Arduino GND
    • Signal → Arduino Pin 9
  3. I2C LCD Display:

    • SDA → Arduino A4
    • SCL → Arduino A5
    • VCC → Arduino 5V
    • GND → Arduino GND

Step 4: The Smart Parking System Code

This is the main code for the car parking system. The system monitors the entry and exit of vehicles using IR sensors and updates the available parking slots on the LCD display. The servo motor acts as the gate, opening and closing based on sensor readings.

----------------------------------------------------------------------------------------------
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);  // Set I2C address obtained from the I2C scanner
Servo myservo1;  // Servo motor

int IR1 = 4;  // IR Sensor 1 (Entry)
int IR2 = 7;  // IR Sensor 2 (Exit)
int Slot = 4;  // Total parking slots
int flag1 = 0, flag2 = 0;

void setup() {
  lcd.init();
  lcd.backlight();
  pinMode(IR1, INPUT);
  pinMode(IR2, INPUT);
  myservo1.attach(9);
  myservo1.write(100);  // Gate initially closed
  lcd.setCursor(0, 0);
  lcd.print("ARDUINO PARKING");
  lcd.setCursor(0, 1);
  lcd.print("SYSTEM");
  delay(2000);
  lcd.clear();
}

void loop() {
  if (digitalRead(IR1) == LOW && flag1 == 0) {
    if (Slot > 0) {
      flag1 = 1;
      if (flag2 == 0) {
        myservo1.write(0);  // Open gate
        Slot = Slot - 1;    // Reduce available slots
      }
    } else {
      lcd.setCursor(0, 0);
      lcd.print("SORRY :(");
      lcd.setCursor(0, 1);
      lcd.print("Parking Full");
      delay(3000);
      lcd.clear();
    }
  }

  if (digitalRead(IR2) == LOW && flag2 == 0) {
    flag2 = 1;
    if (flag1 == 0) {
      myservo1.write(0);  // Open gate
      Slot = Slot + 1;    // Increase available slots
    }
  }

  if (flag1 == 1 && flag2 == 1) {
    delay(1000);
    myservo1.write(100);  // Close gate
    flag1 = 0, flag2 = 0;
  }

  lcd.setCursor(0, 0);
  lcd.print("WELCOME!");
  lcd.setCursor(0, 1);
  lcd.print("Slot Left: ");
  lcd.print(Slot);
}

Step 5: Testing the System

**Alt Text:**   "Step-by-step guide for building a smart car parking system using Arduino, IR sensors, servo motor, and I2C LCD display. The system automates gate control and monitors available parking slots, providing real-time feedback on the LCD screen."




  1. Power Up the System: Upload the car parking system code to your Arduino and power up the system.
  1. Entry Detection: When an object (car) is detected by IR1 (entry sensor), the servo motor (gate) will open, and the number of available slots will decrease.
  1. Exit Detection: When an object is detected by IR2 (exit sensor), the servo motor will open again, and the available slots will increase.
  1. LCD Display: The LCD display will continuously show a welcome message and the number of available parking slots. If the parking lot is full, it will display a "Parking Full" message.

Post a Comment

0 Comments