The problem
Parallel parking in tight urban streets is stressful and causes many low-speed scrapes. Parking assist systems use ultrasonic sensors to measure the gap, decide whether the car fits and guide or steer it in. The project covers the full chain from sensing to slot detection, geometric path planning and manoeuvre control at a level a final-year team can complete.
Objectives
- Detect and measure a parallel parking slot from side ultrasonic distance readings.
- Plan a geometric two-arc reverse path that fits the slot and the vehicle's turning limits.
- Control the manoeuvre with a Stateflow sequence in a kinematic vehicle simulation.
- Build a kit-based bench prototype that reads ultrasonic sensors and gives graded warnings.
What you need
Tools and toolboxes
- MATLAB — Slot geometry, path planning calculations and plotting.
- Simulink — Kinematic vehicle model, simulated ultrasonic sensors and the manoeuvre controller.
- Stateflow — The parking state machine: search, slot found, align, reverse arcs, finish.
- Automated Driving Toolbox (optional) — vehicleDimensions and driving scenario visualisation of parked cars and the ego vehicle.
- STM32CubeIDE — Firmware for ultrasonic timing, filtering and warnings on the kit.
From the EV Embedded Development Kit
- STM32F103C8T6 microcontroller unit (Arm Cortex-M3)
- RGB LEDs and a buzzer
- 16×2 LCD with contrast control
- Serial UART interface
- Analog potentiometer input
- BMP280 pressure and temperature sensor
Software
- MATLAB, Simulink and Stateflow
- STM32CubeIDE with STM32 HAL
- Python with pyserial (optional, for logging)
Extra parts and data
- Two to four HC-SR04 ultrasonic sensors with a resistor divider on each echo line — The kit has no ultrasonic sensor; HC-SR04 modules provide distance readings. Their echo output is 5 V, so it must be divided down before reaching the 3.3 V STM32 input.
- Cardboard boxes or a scale model set-up for parked cars — Gives a repeatable bench slot to measure, without any vehicle.
Key concepts
- Slot detection
- As the car drives past parked vehicles, a side sensor's distance jumps up at the start of a gap and down at its end; the travelled distance between the jumps is the slot length.
- Two-arc parallel parking path
- The car reverses on one arc with full lock towards the kerb and then on an opposite arc to straighten, with the arcs tangent at the switching point.
- Minimum turning radius
- Set by wheelbase and maximum steering angle; it determines the shortest slot the car can enter in one move.
- Time of flight
- The HC-SR04 reports the echo time of a 40 kHz pulse; distance is half the time multiplied by the speed of sound, which varies slightly with temperature.
Step-by-step guide
- 1
Set requirements
Define the function: at speeds below 10 km/h, detect a parallel slot on the left or right, decide if it fits with a set margin, then complete a reverse manoeuvre in one or more moves with a final position within 0.3 m of the kerb and parallel within a few degrees. Define safety limits: stop if any sensor reads below 0.3 m. Choose a vehicle: length, width, wheelbase and maximum steering angle for a compact EV, from published specifications.
Checkpoint: A requirements table with slot margins, final pose accuracy and stop distances.
- 2
Model vehicle and sensors in Simulink
Build a kinematic bicycle model integrated at 100 Hz with speed and steering inputs and rate limits. Model each ultrasonic sensor as a ray from its mounting point that returns the distance to the nearest box-shaped obstacle, with a maximum range of about 4 m, a beam width approximation and added noise. Place parked cars and a kerb in the scene with a gap of variable length.
Checkpoint: Simulated sensor distances that show clear jumps at the edges of a gap as the car drives past.
- 3
Detect and measure the slot
Process the side sensor signal: filter it with a median filter, detect a rise above a depth threshold as the slot start and a fall as the slot end, and use odometry (integrated speed) to compute slot length. Estimate slot depth from the sensor reading inside the gap. Reject slots that are too short or too shallow. Test with gap lengths from 1.1 to 1.6 times the car length.
Checkpoint: Measured slot length within 10 cm of the true value across test gaps.
- 4
Plan the parking path
Compute the two-arc path analytically: from a start pose parallel to the slot at a set lateral distance, reverse on a circle of minimum radius until heading reaches a switching angle, then reverse on the opposite circle until parallel. Solve for the start position so the final pose is centred in the slot. If the slot is too short for one move, plan a multi-move sequence with forward corrections. Check the path in MATLAB plots for clearance with the car corners.
Checkpoint: Plotted paths that keep all vehicle corners clear of obstacles with the required margin.
- 5
Build the Stateflow controller
Create a chart with states Search, SlotFound, DriveToStart, ReverseArc1, ReverseArc2, Correct and Done, plus an Abort state for sensor stop conditions. Command steering and a low reverse speed in each state and switch on travelled distance or heading thresholds. Add a driver-override input that aborts the manoeuvre. Run the full chain from search to parked in simulation. Log the active state alongside the vehicle pose so every transition can be checked against the plan.
Checkpoint: The car parks in simulation for slots of 1.3 times its length and larger with the final pose inside tolerance.
- 6
Bring up the ultrasonic sensors on the kit
Wire two HC-SR04 sensors to free GPIO pins: a trigger output and an echo input through a resistor divider, with a common ground and 5 V supply. Use a timer in input-capture mode to measure echo pulse width, triggering sensors one after another to avoid crosstalk. Convert to distance with temperature-corrected speed of sound, using the kit's BMP280 temperature if enabled. Filter readings with a short median filter.
Checkpoint: Distances to a flat board at 0.3, 1 and 2 m match a tape measure within a few centimetres.
- 7
Implement bench warnings and slot measurement
Show distances on the LCD, set the RGB LED and buzzer beep rate by the closest distance (for example below 1.0 m, 0.6 m and 0.3 m), and stream readings over UART. For slot measurement, slide the kit along a rail past two boxes at a fixed speed set by the potentiometer, or log position by hand, and run the same edge-detection logic as in Simulink. Compare the measured gap with the real one.
Checkpoint: Bench gap measurements within the stated tolerance, and graded warnings at the set distances.
- 8
Test and evaluate
In simulation, run a batch of slot lengths, initial lateral distances and sensor noise levels. Record success rate, final position and heading error, number of moves and minimum clearance. On the bench, record distance accuracy and gap measurement error over repeated trials. Identify failure cases, such as angled parked cars or low kerbs the sensor misses. Run each simulation case several times with different noise seeds and report mean and spread.
Checkpoint: Simulation and bench results tables with failure cases listed.
- 9
Report
Document the sensing, slot detection, path geometry, state machine, bench prototype and results. Explain the relationship between minimum turning radius and minimum slot length. Discuss limitations of the kinematic model, idealised sensor beams and the bench rig. State that the manoeuvre was tested only in simulation and that the hardware was used for sensing on the bench only. Add photos of the bench set-up and wiring diagram.
Checkpoint: A final report and demo video of simulation and bench prototype.
Testing & validation
- Slot length measurement error in simulation and on the bench.
- Parking success rate, final pose error and number of moves across slot lengths.
- Minimum clearance to obstacles during the manoeuvre.
- Ultrasonic distance accuracy and warning thresholds on the kit.
Expected results
A simulated parallel parking assist that measures slots and parks with a two-arc path, plus a kit-based ultrasonic bench prototype with measured distance and gap accuracy.
Take it further
- Add perpendicular parking with a different path geometry.
- Send ultrasonic distances over CAN from the kit to a Simulink model running on a PC with a USB-CAN adapter.
- Replace the geometric planner with Hybrid A* for cluttered slots.
Viva and review questions
What sets the minimum slot length?
The vehicle length plus the extra space the front corner needs while swinging in, which depends on the minimum turning radius and the front overhang.
Why trigger the ultrasonic sensors one at a time?
Sensors firing together can receive each other's echoes, giving false short readings.
Why is the HC-SR04 echo line divided down?
It outputs 5 V pulses, and the STM32 input should not be driven above its 3.3 V supply on a non-tolerant pin; a divider keeps it within range.
Learn it at DIYguru
These DIYguru courses and programmes teach what this project needs.
