SmartUltrasonic – Predictive Non-Blocking Ultrasonic Sensor Library with EEPROM Logging

Hello Arduino Community,
I would like to share a library I developed called "SmartUltrasonic" – a non-blocking and intelligent ultrasonic sensor library designed to improve the reliability and responsiveness of the HC-SR04 sensor.
This library helps overcome common challenges in ultrasonic sensing, such as blocking delays and invalid readings, by incorporating a smart prediction system and EEPROM-based memory storage.
Key Features:

  • Non-blocking distance measurements (no use of delay)
  • Predicts distance when sensor readings are invalid or lost
  • Saves and restores the last valid distance value using EEPROM
  • Easy to use and integrate with Arduino-based projects
    GitHub Repository: The REPO
    Example Usage:
#include <SmartUltrasonic.h>

const int trigPin = 9;
const int echoPin = 10;
const int eepromAddress = 0;

SmartUltrasonic sensor(trigPin, echoPin, eepromAddress);

void setup() {
  Serial.begin(9600);
  sensor.begin();
}

void loop() {
  sensor.update();  // Refresh sensor data
  Serial.println(sensor.getDistance());
  delay(100);
}

Hardware Used:

  • Arduino Uno
  • HC-SR04 Ultrasonic Sensor
  • Built-in EEPROM
    Use Cases:
  • Obstacle detection systems
  • Autonomous robots
  • Power failure-resilient distance logging
    Documentation:
    A PDF guide is available explaining the algorithm, features, and implementation details. You can access it here: PDF Link
    Feedback:
    I welcome your feedback, suggestions, and contributions to improve this library. Feel free to raise issues or submit pull requests via GitHub.
    Best regards,
    Abdalrahman Hossam Othman
    Linkedin

This could lead to early EEPROM failure, due to the limited number of write operations.

Dear J. Remington,
Thank you for your insightful feedback on the memory management aspect of the algorithm. You have raised a critical point regarding the long-term endurance of EEPROM under frequent write cycles.
The current baseline implementation of the algorithm addresses this by employing a fixed-size buffer that operates on a First-In, First-Out (FIFO) principle. Once the buffer's capacity is reached, new data systematically overwrites the oldest entries. While this design ensures a constant-size historical dataset is always available, we concur that for applications with very high data-logging frequency, this approach could accelerate memory wear.
To address this limitation and to enhance scalability for more data-intensive applications, our immediate roadmap includes the development of a modular external storage extension. We are currently implementing a feature to offload historical data logging to high-capacity, non-volatile media such as an SD card. This enhancement will serve a dual purpose: first, it will preserve the onboard EEPROM for critical, low-frequency configuration data, and second, it will allow for a virtually limitless archival of sensor readings, which is essential for long-term trend analysis and system diagnostics.
Your comment has been valuable in affirming the priority of this development path. We appreciate your contribution to strengthening the research.