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

Arduino UNO-Based Smart Parking System with Ultrasonic Sensors and Bluetooth Connectivity

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Parking System with Ultrasonic Sensors and Bluetooth Connectivity

Circuit Documentation

Summary

This circuit is designed to manage a parking system using an Arduino UNO microcontroller. It includes an LCD screen for displaying parking slot statuses, multiple HC-SR04 ultrasonic sensors for detecting the presence of vehicles, a servo motor for controlling a gate, and an HC-05 Bluetooth module for wireless communication. The system reads distances from the ultrasonic sensors to determine if parking slots are occupied and controls the gate accordingly. The status of the parking slots is displayed on the LCD screen and sent via Bluetooth.

Component List

LCD screen 16x2 I2C

HC-SR04 Ultrasonic Sensor

Servo

HC-05 Bluetooth Module

Arduino UNO

Wiring Details

LCD screen 16x2 I2C

HC-SR04 Ultrasonic Sensor (Entrance)

HC-SR04 Ultrasonic Sensor (Slot 1)

HC-SR04 Ultrasonic Sensor (Slot 2)

Servo

HC-05 Bluetooth Module

Code Documentation

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

// Pin assignments for LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Corrected pin definitions based on the net list
#define TRIG_ENTRANCE 2
#define ECHO_ENTRANCE 5
#define TRIG_SLOT1 3
#define ECHO_SLOT1 6
#define TRIG_SLOT2 4
#define ECHO_SLOT2 7
#define TRIG_EXIT 8
#define ECHO_EXIT 9
#define SERVO_PIN 9
#define BLUETOOTH_RX 0
#define BLUETOOTH_TX 1

// Servo motor pin
Servo gateServo;

// Variables
int slot1Status = 0;
int slot2Status = 0;

// Function to calculate distance from ultrasonic sensor
long readDistance(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  long duration = pulseIn(echoPin, HIGH);
  long distance = duration * 0.034 / 2; // Distance in cm
  return distance;
}

void setup() {
  // Initialize serial communication for debugging and Bluetooth
  Serial.begin(9600);

  // Initialize LCD
  lcd.begin(16, 2);
  lcd.print("Initializing...");

  // Initialize ultrasonic sensor pins
  pinMode(TRIG_ENTRANCE, OUTPUT);
  pinMode(ECHO_ENTRANCE, INPUT);
  pinMode(TRIG_SLOT1, OUTPUT);
  pinMode(ECHO_SLOT1, INPUT);
  pinMode(TRIG_SLOT2, OUTPUT);
  pinMode(ECHO_SLOT2, INPUT);
  pinMode(TRIG_EXIT, OUTPUT);
  pinMode(ECHO_EXIT, INPUT);

  // Initialize servo
  gateServo.attach(SERVO_PIN);
  gateServo.write(0); // Close gate

  // Initialize Bluetooth
  pinMode(BLUETOOTH_RX, INPUT);
  pinMode(BLUETOOTH_TX, OUTPUT);
  
  delay(2000);
  lcd.clear();
}

void loop() {
  // Read distances
  long entranceDistance = readDistance(TRIG_ENTRANCE, ECHO_ENTRANCE);
  long slot1Distance = readDistance(TRIG_SLOT1, ECHO_SLOT1);
  long slot2Distance = readDistance(TRIG_SLOT2, ECHO_SLOT2);
  long exitDistance = readDistance(TRIG_EXIT, ECHO_EXIT);

  // Update parking slot status
  slot1Status = (slot1Distance < 10) ? 1 : 0; // Example threshold
  slot2Status = (slot2Distance < 10) ? 1 : 0; // Example threshold

  // Display status on LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Slot1: ");
  lcd.print(slot1Status ? "Occupied" : "Free");
  lcd.setCursor(0, 1);
  lcd.print("Slot2: ");
  lcd.print(slot2Status ? "Occupied" : "Free");

  // Control servo for entrance
  if (entranceDistance < 10 && (slot1Status == 0 || slot2Status == 0)) {
    gateServo.write(90); // Open gate
    delay(5000); // Delay to allow car to pass
    gateServo.write(0); // Close gate
  }

  // Send status via Bluetooth
  String status = "S1:" + String(slot1Status) + ",S2:" + String(slot2Status);
  Serial.println(status);

  // Control servo for exit
  if (exitDistance < 10) {
    gateServo.write(90); // Open gate
    delay(5000); // Delay to allow car to pass
    gateServo.write(0); // Close gate
  }

  delay(500); // Short delay to prevent sensor flooding
}

This code initializes the components, reads distances from the ultrasonic sensors, updates the parking slot statuses, displays the statuses on the LCD, controls the gate servo, and sends the statuses via Bluetooth.