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/himplements an edge‑interrupt decoder that emits aParkingControllerFramecontaining four distance values.src/ParkingDisplay.cpp/hwraps the display’s peculiar wiring, providingbegin(),setDistancesMeters(),setDistancesTenths(), andupdate()to refresh the digits.library.jsonandlibrary.propertiesexpose the package to the Arduino IDE and PlatformIO.examples/contains four sketch demos that use the library:ControllerDecoder,MultipleControllers,MultipleDisplays, andSerialControl.
The library abstracts the low‑level timing, allowing a sketch to focus on higher‑level logic.
How It Is Wired
Entry Points
- Sketch (e.g.,
ControllerDecoder/ControllerDecoder.ino) - InstantiatesParkingController controller(32);- Callscontroller.begin();insetup(). - Controller Loop -
controller.read(frame)inloop()triggersParkingController::read()→ParkingController::decode()(private). -decode()reads the interrupt‑driven pin change buffer, validates framing, and populatesParkingControllerFrame.
Display Flow
- Sketch (e.g.,
MultipleDisplays/MultipleDisplays.ino) - InstantiatesParkingDisplay display(32);- Callsdisplay.begin();→ParkingDisplay::begin()initializes the pin. - Updating -
display.update();inloop()callsParkingDisplay::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
| File | Responsibility |
|---|---|
src/ParkingController.cpp | Interrupt logic, frame parsing |
src/ParkingDisplay.cpp | Display protocol, refresh timing |
examples/ControllerDecoder/ControllerDecoder.ino | Demonstrates decoding |
examples/MultipleDisplays/MultipleDisplays.ino | Demonstrates driving display |
platformio.ini | Build configuration for PlatformIO |
library.json / library.properties | Library 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) –
LICENSEpresent, 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.