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