SteadyPing is a high-stability Arduino library developed and maintained by CaptainEXE to solve the common "jitter" problem found in HC-SR04 ultrasonic sensors.
While traditional ultrasonic sensor code often produces unstable readings such as 25.1, 26.4, and 24.8, SteadyPing uses lightweight signal-processing techniques to deliver smooth, reliable, single-decimal measurements.
- Median Filtering: Captures a burst of 5 samples and selects the true median value to eliminate random interference and "ghost" pings.
- Precision Rounding: Automatically formats measurements to one decimal place for clean and professional Serial output.
- Micro-Delay Timing: Optimized
pulseIn()handling prevents freezes or hangs when no object is detected. - Universal Compatibility: Efficiently designed for Arduino Uno, Mega, Nano, and ESP-based boards.
- Lightweight Performance: Minimal memory overhead for embedded projects and robotics systems.
- Open the Arduino IDE.
- Navigate to Sketch → Include Library → Manage Libraries...
- Search for SteadyPing.
- Click Install.
- Download the latest
.ziprelease. - Open the Arduino IDE.
- Navigate to Sketch → Include Library → Add .ZIP Library...
- Select the downloaded archive.
#include <SteadyPing.h>
// Initialize: SteadyPing objectName(TrigPin, EchoPin);
SteadyPing sonar(9, 10);
void setup() {
Serial.begin(9600);
}
void loop() {
// Retrieve a stable distance reading
float distance = sonar.getDistance();
Serial.print("Stable Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100);
}SteadyPing does not rely on basic averaging methods, since averages can still be heavily affected by large sensor errors or invalid readings.
Instead, the library uses a sorting-based median filtering system to determine the mathematical center value of the sensor sample buffer. Even if the sensor accidentally reports a 0 or invalid spike, the final output remains smooth and stable.
This makes SteadyPing especially useful for:
- Robotics
- Distance monitoring systems
- Obstacle avoidance
- STEM and classroom projects
- Embedded automation systems
Maintainer: CaptainEXE Organization: CaptainEXE Studios Website: https://captainexe.vercel.app Status: v1.1.0-Stable
SteadyPing is open-source software released under the MIT License.