ServoHack is an Arduino library for hacked/modified servo motors that extends the standard Servo library with advanced features for precise servo control. It includes potentiometer feedback, fail-safe operation, and EEPROM-based calibration. This library is designed for applications like robotics, automation, and testing rigs where reliable servo positioning is critical.
- https://www.instructables.com/Using-SG90-or-MG90-Servo-Feedback-Modification-for/
- https://www.instructables.com/Servo-Feedback-Hack-free/
- Potentiometer Feedback: Reads servo position via a potentiometer for accurate angle verification
- Fail-Safe Mode: Detects mechanical obstructions and triggers a callback function to prevent damage
- EEPROM Calibration: Stores pulse and potentiometer ranges for consistent operation across power cycles
- Smooth Movement: Supports speed-controlled movements with customizable step delays
- Flexible Configuration: Set angle ranges, pulse widths, potentiometer ranges, home position, and tolerance
- Open Library Manager (Sketch > Include Library > Manage Libraries)
- Search for "ServoHack"
- Click Install
- Add to your platformio.ini:
lib_deps = ServoHack
- Or clone the repository into your lib folder:
cd lib git clone https://github.com/TheKvc/ServoHack.git
- Include in your code:
#include <ServoHack.h>
#include <ServoHack.h>
ServoHack servo;
const uint8_t SERVO_PIN = 9;
const uint8_t POT_PIN = A0;
const uint16_t EEPROM_ADDR = 0;
void failSafeCallback() {
Serial.println("Servo stuck!");
servo.detach();
}
void setup() {
Serial.begin(9600);
servo.attach(SERVO_PIN, POT_PIN);
servo.setPulseRange(500, 2500);
servo.setAngleRange(0, 180);
servo.setHome(90);
servo.setTolerance(5);
servo.setFailSafe(true, failSafeCallback);
servo.calibrate(EEPROM_ADDR);
servo.write(90, 20);
}
void loop() {
// Move to 0 degrees at speed 20
servo.write(0, 20);
delay(2000); // Wait for the servo to reach position
// Move to 180 degrees at speed 20
servo.write(180, 60);
delay(2000); // Wait for the servo to reach position
}
- DualServoTest: Demonstrates dual-servo testing with feedback, fail-safe, and EEPROM storage.
- Arduino Servo library
- Arduino EEPROM library
MIT License
Submit issues or pull requests on GitHub.
TheKvc karanveerchouhan@gmail.com