Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Smart Parking System with IR Sensors and Servo Gate Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Smart Parking System with IR Sensors and Servo Gate Control

Circuit Documentation

Summary

The circuit in question is designed to manage a smart parking system. It utilizes an Arduino UNO as the central microcontroller to interface with various components including two IR sensors, a Tower Pro SG90 servo motor, a buzzer, and an I2C LCD 16x2 screen. The IR sensors are used to detect the entry and exit of cars, the servo motor acts as a barrier control, the buzzer provides audible alerts, and the LCD screen displays parking information. The Arduino UNO controls the logic of the system, processes sensor inputs, drives the servo and buzzer, and communicates with the LCD via the I2C protocol.

Component List

Arduino UNO

IR Sensors (2x)

Tower Pro SG90 Servo

Buzzer

I2C LCD 16x2 Screen

Wiring Details

Arduino UNO

IR Sensors

Tower Pro SG90 Servo

Buzzer

I2C LCD 16x2 Screen

Documented Code

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

// Initialize the LCD with I2C address 0x27, 16 columns and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define the GPIO pins directly
const int servo_pin = 9;   // Servo pin (use pin 9)
const int in_pin = 2;      // Input pin for entering (use pin 2)
const int out_pin = 3;     // Input pin for exiting (use pin 3)
const int buzzer_pin = 11; // Buzzer pin (use pin 11)

// Initialize the servo
Servo myservo;
int count = 0;

void IN() {
    count++;
    lcd.clear();
    lcd.print("CAR INCOMING");
    lcd.setCursor(0, 1);
    lcd.print(count);
    delay(1000);
}

void OUT() {
    count--;
    lcd.clear();
    lcd.print("CAR OUTGOING");
    lcd.setCursor(0, 1);
    lcd.print(count);
    delay(3000);
}

void smoothServoMove(int targetAngle) {
    int currentAngle = myservo.read();
    int step = (targetAngle > currentAngle) ? 1 : -1;

    for (int angle = currentAngle; angle != targetAngle; angle += step) {
        myservo.write(angle);
        delay(15); // Adjust this delay for speed of movement
    }
}

void setup() {
    // Initialize the LCD
    lcd.init();
    lcd.backlight();

    // Initialize serial communication
    Serial.begin(115200);

    // Set up pin modes
    pinMode(in_pin, INPUT_PULLUP);
    pinMode(out_pin, INPUT_PULLUP);
    pinMode(buzzer_pin, OUTPUT); // Initialize buzzer pin

    // Initial LCD message
    lcd.setCursor(0, 0);
    lcd.print("SMART PARKING ");
    delay(1000);

    lcd.clear();
    lcd.print("CAR INSIDE");
    lcd.setCursor(0, 1);
    lcd.print(count);

    // Attach the servo
    myservo.attach(servo_pin, 500, 2400);
}

void loop() {
    // Check input pins and update count
    if (digitalRead(in_pin) == LOW) {
        IN();
    }
    if (digitalRead(out_pin) == LOW) {
        OUT();
    }

    // Check count and control servo and buzzer
    if (count >= 10) {
        lcd.clear();
        lcd.print("PLEASE WAIT....");
        lcd.setCursor(0, 1);
        lcd.print("LIMIT IS Full");
        
        smoothServoMove(100);           // Move to open position (100 degrees)
        tone(buzzer_pin, 1000);        // Start buzzer at 1000 Hz
    } else {
        smoothServoMove(0);             // Move to closed position (0 degrees)
        noTone(buzzer_pin);             // Stop buzzer
    }
    
    delay(100);  // Short delay to reduce flicker and CPU usage
}

This code is responsible for controlling the smart parking system. It initializes the LCD screen, sets up the GPIO pins, and defines the behavior for car entry and exit. The servo motor is controlled to act as a barrier, and the buzzer provides audible feedback when the parking limit is reached. The LCD screen displays the current status and the number of cars inside the parking area.