📡 Smart Parking System – WiFi Terminal (Hotspot Mode)
✅ Show output in Serial WiFi Terminal App
✅ Use ESP32 Hotspot Mode (SoftAP)
✅ No home WiFi required
✅ Works directly with mobile connection
💻 Complete ESP32 Code (Hotspot + TCP Server)
#include <WiFi.h>
#include <Servo.h>
// -------- WiFi Hotspot Credentials --------
const char* ssid = "SmartParking";
const char* password = "12345678";
WiFiServer server(8080);
WiFiClient client;
// -------- 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);
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);
// Start Hotspot
WiFi.softAP(ssid, password);
Serial.println("Hotspot Started");
Serial.print("IP Address: ");
Serial.println(WiFi.softAPIP());
server.begin();
Serial.println("TCP Server Started on Port 8080");
}
void loop() {
client = server.available();
if (client) {
client.println("Smart Parking System Connected");
client.println("--------------------------------");
while (client.connected()) {
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++;
// Print Slot Status
client.println("------ Parking Status ------");
client.print("Slot 1: ");
client.println(slot1 ? "Available" : "Occupied");
client.print("Slot 2: ");
client.println(slot2 ? "Available" : "Occupied");
client.print("Slot 3: ");
client.println(slot3 ? "Available" : "Occupied");
client.print("Slot 4: ");
client.println(slot4 ? "Available" : "Occupied");
client.print("Slot 5: ");
client.println(slot5 ? "Available" : "Occupied");
client.print("Total Available: ");
client.println(available);
// Ultrasonic Measurement
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
duration = pulseIn(ECHO, HIGH);
distance = duration * 0.034 / 2;
client.print("Entrance Distance: ");
client.print(distance);
client.println(" cm");
// Gate Logic
if (distance < 15) {
client.println("Car detected at entrance!");
if (available > 0) {
client.println("Slots Available - Opening Gate");
gateServo.write(90);
delay(3000);
gateServo.write(0);
}
else {
client.println("Parking Full - Gate Closed");
}
}
client.println("------------------------------");
delay(2000);
}
client.stop();
}
}
🧠 FULL CODE EXPLANATION (Understand Deeply)
🔹 1️⃣ WiFi Hotspot Setup
This makes ESP32 act like a WiFi router.
Your phone will see:
📶 SmartParking
Password: 12345678
No internet required.
🔹 2️⃣ TCP Server
ESP32 opens communication on Port 8080.
Your WiFi Terminal app connects using:
IP: 192.168.4.1
Port: 8080
🔹 3️⃣ Client Handling
This checks if mobile app connected.
When connected:
→ ESP32 starts sending live data.
🔹 4️⃣ Slot Detection Logic
Each IR sensor read:
If HIGH → Available
If LOW → Occupied
Then we count available slots.
🔹 5️⃣ Ultrasonic Logic
Distance formula:
If distance < 15 cm:
→ Car detected at gate
🔹 6️⃣ Gate Control
If car detected AND slots available:
→ Servo rotates 90°
→ Wait 3 sec
→ Close gate
If parking full:
→ Gate remains closed
📱 How To Connect WiFi Terminal App
1️⃣ Upload code
2️⃣ Open Serial Monitor
You’ll see IP:
192.168.4.1
3️⃣ Connect mobile to WiFi:
SmartParking
Password: 12345678
4️⃣ Open Serial WiFi Terminal app
Add new connection:
Host: 192.168.4.1
Port: 8080
Click CONNECT
📊 Example App Output
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 (Short Version)
“In this system, ESP32 creates a WiFi hotspot and runs a TCP server. A mobile app connects using IP and port number. The ESP32 reads IR sensors to detect slot availability and uses an ultrasonic sensor to detect cars at the entrance. If slots are available, the servo motor opens the gate. All system data is transmitted wirelessly to the WiFi Terminal app.”