Arduino UNO-Based Smart Parking System with Ultrasonic Sensors and Bluetooth Connectivity
View and Edit Project In Cirkit Designer
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
- Description: A 16x2 character LCD display with I2C interface.
- Pins: SCL, SDA, VCC, GND
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic distance sensor used to measure the distance to an object.
- Pins: VCC, TRIG, ECHO, GND
Servo
- Description: A servo motor used to control the gate.
- Pins: GND, VCC, PWM
HC-05 Bluetooth Module
- Description: A Bluetooth module used for wireless communication.
- Pins: Key, VCC, TXD, RXD, State, GND
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
Wiring Details
LCD screen 16x2 I2C
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- SCL: Connected to Arduino UNO A5
- SDA: Connected to Arduino UNO A4
HC-SR04 Ultrasonic Sensor (Entrance)
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- TRIG: Connected to Arduino UNO D2
- ECHO: Connected to Arduino UNO D5
HC-SR04 Ultrasonic Sensor (Slot 1)
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- TRIG: Connected to Arduino UNO D3
- ECHO: Connected to Arduino UNO D6
HC-SR04 Ultrasonic Sensor (Slot 2)
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- TRIG: Connected to Arduino UNO D4
- ECHO: Connected to Arduino UNO D7
Servo
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- PWM: Connected to Arduino UNO D9
HC-05 Bluetooth Module
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- TXD: Connected to Arduino UNO D0
- RXD: Connected to Arduino UNO D1
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.