This tutorial shows how to get feedback from an Analog or digital servo.
Let's have a look at what a servo is.
Servos are small, inexpensive, mass-produced servomotors or other actuators used in radio control and small-scale robots.
Although there are various types of servos, rotary actuators are the most common. Servo is a general term for a closed loop control system using negative feedback.
Now let hack the Servo!
This hobby Servo use a potentiometer which is attached to the shaft to find the current position of the rotor. Since a potentiometer is implemented we can able to use this as a analog signal which can feed to Arduino board where we can see the real time shaft position using a serial monitor.
Parts and Tools required for this mod.
- Servo MG995/MG945/mini 9g servo( all are applicable )
- jumper wire
- Soldering iron kit
- tape
- knife
STEP 1: Remove the Case
Remove case of the servo and find the 3 pin potentiometer and solder on middle pin to use as analog signal. Why middle pin ? for that we need to see Potentiometer pinout. It has 3 pin which is followed by Gnd, Vout, 5v .we are only focused on Vout from the potentiometer.
STEP 2: Solder a Jumper wire
Take a jumper wire about 20 cm and match with servo lead cable and cut according to the requirement then solder the Jumper wire to middle ( Vout ) which is shown above.
STEP 3: Dressing
Make a little adjust by using detailed knife or soldering iron in order to assembly the case for the new wire and close the case and secure it with screws. Now move to the coding part.
STEP 4: Testing the Feedback
Connect the servo to the Arduino Uno or any other Arduino board by the following pinout.
- 5v to 5v
- Gnd to Gnd
- Signal to Pin 9
- New wire to Pin A2
Upload the code and switch serial monitor to see the servo in action.
#include <Servo.h>
Servo servo_1; // name of the servo
int val = 0;
const int Pot = 2; //New Analog wire from the servo
//init the scr
void setup(){
Serial.begin(9600);
Serial.println("Servo feedback hack");
delay(1000);
servo_1.attach(9); //attached pin number
}
void call(){
servo_1.write(10);
servo_1.detach(); // To turn off the Torque
}
void seek(){
val = analogRead(Pot); // read the potentiometer (value between 0 and 600)
val = map(val, 0, 600, 0, 180 ); // 0 and 180 define degree value
Serial.println(val);
delay(val);
}
void loop(){
seek();
call();
}
I was able to retrieve the current position of the servo without any more tweaking after uploading the file. We can also calibrate by iterating the value and saving to constant. As a result, we may analyze the value and assign a tolerance variable to it, as well as add -2 or +2 based on the adjustment and feed it to the val variable.
Conclusion:
We can reach a specified position with the assistance of this new mod, and we can also utilize this servo as an input device. Now that we have a feedback signal, we may use it in a variety of projects. In order to use with the Raspberry Pi 4, it doesn't have analogue GPIO pins, we'll need an ADC converter to use this feedback. However, we can use this mod on the Raspberry Pico board, which has five analogue pins but two of them are occupied by the dedicated system temperature and system voltage, leaving us with only three GPIO analogue pins to use.
Happy hacking♥
End of experiment
Result: Pass