The Problem

Parking sensors with four independent ultrasonic ranges are hard to interface with microcontrollers because the controller emits a proprietary pulse‑width modulated stream. Developers need a ready‑made decoder and a way to drive a 4‑digit display that expects a different wire order.

What This Does

The repo ships an Arduino library that decodes the controller’s signal and drives the 4‑digit display.

  • src/ParkingController.cpp/h implements an edge‑interrupt decoder that emits a ParkingControllerFrame containing four distance values.
  • src/ParkingDisplay.cpp/h wraps the display’s peculiar wiring, providing begin(), setDistancesMeters(), setDistancesTenths(), and update() to refresh the digits.
  • library.json and library.properties expose the package to the Arduino IDE and PlatformIO.
  • examples/ contains four sketch demos that use the library: ControllerDecoder, MultipleControllers, MultipleDisplays, and SerialControl.

The library abstracts the low‑level timing, allowing a sketch to focus on higher‑level logic.

How It Is Wired

Entry Points

  1. Sketch (e.g., ControllerDecoder/ControllerDecoder.ino) - Instantiates ParkingController controller(32); - Calls controller.begin(); in setup().
  2. Controller Loop - controller.read(frame) in loop() triggers ParkingController::read() → ParkingController::decode() (private). - decode() reads the interrupt‑driven pin change buffer, validates framing, and populates ParkingControllerFrame.

Display Flow

  1. Sketch (e.g., MultipleDisplays/MultipleDisplays.ino) - Instantiates ParkingDisplay display(32); - Calls display.begin(); → ParkingDisplay::begin() initializes the pin.
  2. Updating - display.update(); in loop() calls ParkingDisplay::refresh() → writes digits via the single data line (S).

External Dependencies

  • The only external effect is the microcontroller pin used for the data line.
  • No file I/O, network, or database access occurs.

Responsibility Map

FileResponsibility
src/ParkingController.cppInterrupt logic, frame parsing
src/ParkingDisplay.cppDisplay protocol, refresh timing
examples/ControllerDecoder/ControllerDecoder.inoDemonstrates decoding
examples/MultipleDisplays/MultipleDisplays.inoDemonstrates driving display
platformio.iniBuild configuration for PlatformIO
library.json / library.propertiesLibrary metadata

The module graph is linear: sketch → library class → hardware pin. No cycles or complex dependencies.

How To Use It

Setup

# Clone the repo
git clone https://github.com/moses-y/ParkingSensor

# If using PlatformIO
cd ParkingSensor
pio lib install
pio run

For the Arduino IDE, copy the entire src/ folder and the library.properties file into the libraries/ParkingSensor directory and restart the IDE.

Configuration

No environment variables are required. The only configuration is the data‑line pin, passed to the constructor (ParkingController controller(32);).

Running It

Upload one of the example sketches to an Arduino-compatible board.

# Using PlatformIO
pio run --target upload -e <env>

The sketch will start the controller or display and begin processing real sensor data.

Real-World Use

A typical deployment in a parking lot controller board:

#include <ParkingController.h>
#include <ParkingDisplay.h>

ParkingController controller(2);   // Controller data line
ParkingDisplay  display (3);     // Display data line

void setup() {
  controller.begin();
  display.begin();
}

void loop() {
  ParkingControllerFrame frame;
  if (controller.read(frame)) {
    display.setDistancesMeters(frame.distA, frame.distB,
                               frame.distC, frame.distD);
  }
  display.update();
}

The board reads distances, updates the display, and can forward the frame to a central system over serial or Ethernet.

Code Health & Issues

  • Medium (SDLC) – No test files detected → untested code paths.
  • Medium (SDLC) – No CI/CD pipeline → no automated build/test gate.
  • Low (Licensing) – LICENSE present, but empty body → unclear terms.
  • Low (Documentation) – README explains usage but lacks API reference.

The Bottom Line

This library gives a straightforward way to interface Arduino boards with a four‑channel ultrasonic parking sensor kit. The code is small, linear, and easy to integrate, but the lack of tests and CI means that edge cases are not verified automatically. The library is suitable for hobbyists and rapid prototyping but would benefit from added unit tests and a clear license.