DEV Community

Cover image for How I Built a Smart Parking System with ESP32 and FastAPI
mmsalmanfaris
mmsalmanfaris

Posted on

How I Built a Smart Parking System with ESP32 and FastAPI

Project Overview
Finding a secure and available parking space in urban areas is a daily struggle. My final year project aimed to address this issue by creating a Smart Parking System using ESP32, IR sensors, FastAPI, Firebase, and React. The system automates vehicle parking, slot booking, mismatch alerts, display operations and monitoring using a real-time dashboard and IoT devices, ensuring a smoother, more secure parking experience.

Key Features
Real-time slot detection using IR sensors.
Automatic number plate recognition using computer vision.
Smart gate control via servo motors.
User-friendly web interface for booking, tracking, and payments.
Admin dashboard for system monitoring and device management.
Alerts and mismatched parking notifications.
Technology Stack
Frontend — React, Tailwind CSS, Flowbite
Backend — FastAPI, Python, JWT Auth, Pydantic , C++
Database — Firebase Firestore
IoT Devices — ESP32, IR sensors, SG90 Servo Motor, 16x2 LCD Display
ML Model — OpenCV with custom-trained number plate detection
Deployment — Localhost testing via Wifi and static IP

System Architecture
The system follows a 3-tier architecture:

Presentation Layer (React App)
Logic Layer (FastAPI Backend)
Hardware Layer (IoT + Computer Vision)

IoT Workflow

Security & Access Control
User and Admin roles with protected endpoints.
JWT authentication ensures session control.
Route-level protection on the frontend using token validation.
Admin Dashboard Features
View system usage (slots, bookings, users, alerts).
Manage packages, slots, and devices.
Access full system reports with export options (CSV, PDF).
Real-time alerts for mismatch or functional errors.

Machine Learning Component
A lightweight OpenCV-based solution is implemented for Number Plate Recognition (NPR). The model filters blurry or low-confidence results, only sending high-confidence data to the backend. This integrates smoothly into the FastAPI pipeline.

Handling Network & WiFi Changes
ESP32 uses the router’s IP to send/receive data. When switching networks (e.g., to a mobile hotspot / Wifi), I updated the ESP32 IP and ensured the host device (backend) shared the same network range. This ensured stable communication across components.

Challenges Faced
Real-time sync between ESP32 and backend over WiFi required careful timeout tuning.
Limited camera quality affected plate recognition, which was resolved with pre-processing.
The Firebase structure had to be carefully designed for scalability and speed.

Conclusion
This smart parking system merges the power of IoT, computer vision, and web development to tackle real-world challenges. It’s scalable and secure, and solves a common urban problem with automation and innovation.

GitHub Repository: Link

Let’s connect on LinkedIn if you’re hiring or have feedback!

Top comments (0)