Course Content
IoT Engineering Course using ESP32 with 12 Real-World Projects

📡 Smart Parking System – Bluetooth Terminal Version

Bluetooth Terminal App
✅ No WiFi required
✅ Direct ESP32 Bluetooth communication
✅ Real-time parking status on mobile

📱 Before Starting

Install app:

👉 Serial Bluetooth Terminal (Kai Morich)

ESP32 Bluetooth name will appear as:
SmartParking_BT


💻 Complete ESP32 Code (Bluetooth Version)

#include "BluetoothSerial.h"
#include <Servo.h>

BluetoothSerial SerialBT;

// -------- IR Sensors --------
int ir1 = 14;
int ir2 = 27;
int ir3 = 26;
int ir4 = 25;
int ir5 = 33;

// -------- Ultrasonic --------
#define TRIG 4
#define ECHO 5

// -------- Servo --------
Servo gateServo;
int servoPin = 18;

long duration;
float distance;

void setup() {

Serial.begin(115200);
SerialBT.begin("SmartParking_BT"); // Bluetooth device name

pinMode(ir1, INPUT);
pinMode(ir2, INPUT);
pinMode(ir3, INPUT);
pinMode(ir4, INPUT);
pinMode(ir5, INPUT);

pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);

gateServo.attach(servoPin);
gateServo.write(0); // Gate closed

Serial.println("Bluetooth Smart Parking Started");
}

void loop() {

int available = 0;

bool slot1 = digitalRead(ir1);
bool slot2 = digitalRead(ir2);
bool slot3 = digitalRead(ir3);
bool slot4 = digitalRead(ir4);
bool slot5 = digitalRead(ir5);

if (slot1 == HIGH) available++;
if (slot2 == HIGH) available++;
if (slot3 == HIGH) available++;
if (slot4 == HIGH) available++;
if (slot5 == HIGH) available++;

SerialBT.println("------ Parking Status ------");

SerialBT.print("Slot 1: ");
SerialBT.println(slot1 ? "Available" : "Occupied");

SerialBT.print("Slot 2: ");
SerialBT.println(slot2 ? "Available" : "Occupied");

SerialBT.print("Slot 3: ");
SerialBT.println(slot3 ? "Available" : "Occupied");

SerialBT.print("Slot 4: ");
SerialBT.println(slot4 ? "Available" : "Occupied");

SerialBT.print("Slot 5: ");
SerialBT.println(slot5 ? "Available" : "Occupied");

SerialBT.print("Total Available: ");
SerialBT.println(available);

// -------- Ultrasonic --------
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);

duration = pulseIn(ECHO, HIGH);
distance = duration * 0.034 / 2;

SerialBT.print("Entrance Distance: ");
SerialBT.print(distance);
SerialBT.println(" cm");

if (distance < 15) {

SerialBT.println("Car detected at entrance!");

if (available > 0) {
SerialBT.println("Slots Available - Opening Gate");
gateServo.write(90);
delay(3000);
gateServo.write(0);
}
else {
SerialBT.println("Parking Full - Gate Closed");
}
}

SerialBT.println("------------------------------");
delay(2000);
}

🧠 FULL CODE EXPLANATION (Understand Clearly)


🔹 1️⃣ Bluetooth Library

 
 
#include “BluetoothSerial.h”
 

This enables Bluetooth Classic communication in ESP32.


🔹 2️⃣ Create Bluetooth Object

 
 
BluetoothSerial SerialBT;
 

This object is used to send data to mobile app.


🔹 3️⃣ Start Bluetooth

 
 
SerialBT.begin(“SmartParking_BT”);
 

ESP32 becomes discoverable device with name:

SmartParking_BT


🔹 4️⃣ IR Sensor Reading

 
 
bool slot1 = digitalRead(ir1);
 

If HIGH → Slot Available
If LOW → Slot Occupied

We count total available slots.


🔹 5️⃣ Sending Data to Bluetooth App

 
 
SerialBT.println(“Slot 1: Available”);
 

This prints message inside Bluetooth Terminal app.

Important:

Serial.print → USB Serial Monitor
SerialBT.print → Bluetooth App


🔹 6️⃣ Ultrasonic Distance

 
 
distance = duration * 0.034 / 2;
 

If distance < 15 cm:
→ Car detected


🔹 7️⃣ Gate Logic

If:
Car detected AND available > 0
→ Open gate

Else:
→ Keep closed


📱 How To Connect Bluetooth Terminal App

1️⃣ Upload code
2️⃣ Turn ON mobile Bluetooth
3️⃣ Open Serial Bluetooth Terminal app
4️⃣ Pair with:

SmartParking_BT

5️⃣ Click CONNECT

Now live parking data will appear.


📊 Example Bluetooth Output

 
 
—— Parking Status ——
Slot 1: Available
Slot 2: Occupied
Slot 3: Available
Slot 4: Occupied
Slot 5: Available
Total Available: 3
Entrance Distance: 10 cm
Car detected at entrance!
Slots Available – Opening Gate
 

🎓 Viva Explanation (Professional)

“In this version, ESP32 uses Bluetooth Classic to communicate with a mobile device. The system reads five IR sensors to determine slot occupancy and an ultrasonic sensor to detect vehicles at the entrance. Based on availability, the servo motor controls the gate. All parking status data is transmitted wirelessly to the Bluetooth Terminal application.”

Scroll to Top