Sensing your servo's position
Sometimes you need to know what position a servo is currently in. Two examples are:
1. The robot has lots of legs and the power has just been turned on. Without knowing the servos current position the legs may become tangled when the servos are initialized.
2. A servo is being used to opperate a gripper. When an object is grabbed it prevents the servo from closing the gripper. By knowing what the actual position of the servo is we can:
(a) determine the aproximate size of the object
(b) adjust how tightly the servo grips the object
Most hobby servos use a simple pot to measure the position of the servo. Because the supply voltage of the servo can vary this pot usually connects between an internally regulated reference voltage and ground.
The internal reference voltage is usually between 2V - 4V (depends on the servo being used), well below the minimum opperating voltage of the servo. This means the voltage on the output of the pot (The middle pin) should be between 0V and the reference voltage which is easily measured by your processors analog inputs.
You can see in this terrible photo that the white wire goes to the center pin of the pot. I soldered a yellow wire to the PCB on the opposite side so that it fitted neatly inside the tiny servo case.
Using a cheap blue miniature servo my analog input gives me a reading between 97 and 801 as the servo rotates through almost 180 degrees. that gives me a resolution of aproximately 0.25 degrees which is plenty for most applications.
I have also tried this with a Futaba servo which seems to have a reference voltage of 2V. as such I only got values from 65 to 425 over almost 180 degrees which gave an aproximate resolution of 0.6 degrees.
I was getting some noise from the motor on my analog input. By inserting a 100nF capacitor between the power pins of the servo socket (no soldering required) the electrical noise was reduced noticeably. I recommend using sheilded cable with the sheild grounded if noise is still an issue.
Hope this helps, good luck and enjoy!