Technologies

Technologies used, in addition to the HC-SR04, include:

  • Control of an addressable (WS2812B) LED strip via the FastLED library
  • Sensing the ambient air temperature to compute an accurate speed of sound for distance measurement
  • WiFi connection to the home network for control
  • Setting the “target” parking distance via pushbutton
  • Setup of parameters by web application
  • Web application implemented an approach where the characteristics of the set of control parameters were defined in a JSON file
  • Websocket interface for delivery of parameters
  • A telnet interface for debugging and/or monitoring the status of the unit from within the home network
  • Supported ArduinoOTA for code downloads over the network
  • mDNS for network address discovery
  • Parameters retained in the ESP32 using nonvolatile storage in the ESP32
  • A real-time clock, synchronized to an NTP time server, to turn off the unit during off-hours
  • Printed circuit board designed to fit within a standard plastic enclosure

Design Approach:

The design was inspired by an article in Makerguides here. I added to the basic distance-measurement functionality for this application by:

  • Driving an LED strip based on distance to target, to give a visual indication on approach
  • Using a web interface to set up various parameters
  • Shutting down measurement-taking during specified hours of the day
  • Implementing a state machine to manage behavior

As shown in the diagram, there are six states:

  • Night: quiescent state where measurement-taking is paused due to time of day being outside of operating hours
  • Vacant: the state that is entered when the vehicle is moved away from the parking space
  • Homing: in this state, the vehicle is approaching the target distance and the unit indicates on the LED display closeness to target
  • Home: the vehicle has reached the target distance and has not overshot
  • TooClose: the state that is entered if the distance to the sensor is less than a set level
  • Parked: this state is achieved after reaching Home state, following a set timeout

Once the Parked state is entered, that state remains active until measurements indicate the vehicle is no longer parked nearby, and a certain time has passed. This state ensures that the LED display is stable (e.g. the lights do not blink, or the TooClose state is not entered) due to people walking between the car and the sensor.

Parameters driving the state transitions are illustrated in the following figure:

The lower-case labels correspond to parameter names in the code. These correspond directly with values specified by the user in the web interface for determining the desired behavior. All parameters are specified in inches, with resolution of 0.1 inch:

target_distance: the distance from the sensor that represents the optimum location for the parked vehicle.

approach_zone_depth:  the distance over which the driver will be guided by the LEDs to reach the target.

landing_zone_depth: the depth of the area that is considered OK for the car to be safely parked.

garage_door_clearance: the distance from the rear of the vehicle to the garage door, when the vehicle is parked at the target distance.

The above parameters are delivered via Websockets as integer numbers, in units of tenths of an inch.

The uppercase labels (APPROACH, AZ_DEPTH, TARGET, WARN, GARAGE) are derived from the user settable parameters, and for clarity are used in the state-change calculations. These numbers, as used in the code, are floating point numbers in units of one inch, and are derived from the parameters listed above by dividing by 10.0.

APPROACH:  when the vehicle reaches this distance from the sensor, the sample rate for depth measurements is increased (for faster response), and the display changes to a “ready” condition. During the vehicle approach toward the target distance, the top LED is illuminated white, and the bottom LED is illuminated red...

Read more »