Let's Make Robots!

Adding a rotary encoder to a hacked servo

Provides encoder measurements to a geared motor

Recently I hacked some servos for fun. While I had the servos open and had removed all the electronics, it occurred to me that there was a lot of space in there now. I had seen some previous attempts by some on this site to add optical encoders inside gear motors. However, with all the room available inside the servo, I thought a rotary encoder might fit.

Videos:

  1. Testing the gear motor after adding the encoder
  2. Testinge the encoder with a simple circuit

Some searching found me these rotary encoders from allelectronics.com for only 75 cents each! The size looked like it would fit. I ordered four of them, and they arrived today.

First, opened up my hacked servo, and removed all the gears. This is a GWS S03N STD servo.

 

You can see the unmodified rotary encoder next to the servo parts. So innocent and unaware of what is about to happen.

In the picture below, you can see the servo bearing in the upper part of the case. The 6mm encoder shaft fits in there perfectly.

 

Unfortunately, the plastic hole in the center part of the servo case is only about 4mm. I had to drill it out to fit the shaft. Use of a drill press and very careful positioning is highly recommended.

Now the encoder shaft fit the middle of the servo body. However, when I tried to reassemble the gears, I discovered that the middle gear rubbed up against the encoder shaft. I needed 1 or 2 more mm. If you look carefully at the encoder shaft in the picture above, you can see that there is a portion of the shaft that I had to grind away with a dremel tool. I needed to leave some of the 6mm diameter above and below this grinding, because this is where the shaft rides in the enlarged 6mm hole in the plastic body of the servo.

Next I had to cut down the length of the encoder shaft. It has to end up just about flush with the metal bearing when assembled.

In the picture below you can see the encoder in the center servo body piece with the bearing installed.

Next came what might have been the biggest challenge of the whole project. In the picture below, you can see the slotted top of the encoder shaft, and also the slot inside the last driven gear of the servo.

The slot inside the gear is wider, but shorter than the slot in the encoder shaft. I needed a piece of metal to mate these two parts together so the encoder would turn with the gear.

After some thinking, I decided to try to fabricate the part I needed using a left over piece of metal from when I cut down the encoder shaft.

Below is the result.

This took a lot of careful work with the Dremel. Grind a little and test fit. Grind and test fit. It is easier to take away material than it is to put it back. I also widened the slot in the shaft of the encoder.

Below you can see the new piece installed in the encoder shaft, with the bearing around the encoder shaft. The little white plastic bit sitting on the servo body gets placed over the new piece.

Next, the final gear in the servo gear train has to fit on top. There are little plastic tabs inside the gear that match the two indents in the white plastic sleeve that sits on top of the encoder shaft.

In the picture below, you can see the encoder in place along with the servo motor with blue wires attached.

That basically completes the mechanical build. Next, it was time to solder the wires.

The center pin of the encoder is ground, wired in green. The left (yellow) and right (orange) pins are Channel A and Channel B. It doesn't matter too much which is which. The blue wires are for the motor.

I hot glued the encoder firmly in place, since otherwise it will try to turn inside the servo case. I also used some hot glue to serve as a strain relief for all the wires.

Below is the finished product, all ready for testing.

The video shows my first test, which was just to determine if the servo motor and gears still turned OK after all of my hacking and bending. I don't want to give away the ending, but it seemed to work OK.

Next test will be to try out the encoder itself. That will be for another day, and I will update this post then.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Does this kind of encoders have any usable resolution for using with a servo?

I think you are missing the point. This is a hacked servo so there is no controlling board inside. Its just a motor with a gear. Now its geared motor with full encoding and that is great stuff.

 

Geir is correct. In addition to the fact that the servo board is gone, the encoder is installed where the servo's potentiometer used to be. There'd be no way to fit an encoder into a standard servo that was still operating as a servo.

Well, of course there is no control board, as you can not interface it with the encoder. But I suppose you did not build this to be decorative! I suppose you are going to have the motor driven by an mcu (by means of an H-Bridge) and the encoder connected to the same mcu, to create a driver. What I am saying is that I don't think you are going to have any usable resolution because these encoders are used to read human input (360 deg / 30 detents =  12 degrees / detent). I hope you get what I mean now...

(With a wheel attached on it you will have a very big error!)

Great stuff! I gave up this idea long ago, when I noticed that servos are noisy (loud) geared motors. I wanted to have the encoder soldered to a small PCB with a ATtiny85 on it connected to a second board with a FAN8082 H-bridge. Besides the noise, I discovered that is harder to keep the speed of 2 motors at the same value if they are connected to separate microcontrollers.

 

Note on the poor resolution of the encoders. You may use a timer to count ticks between clicks. That means you have a timer that generates interrupts every ms or so, and count how many interrupts occur between 2 clicks of the encoder. 

OK, I understand your point now. Yes, you are correct, the resolution will only be 12 degrees, which isn't great. However, It should be OK for my purposes. With smallish wheels the error will not be too great.

For comparison, SparkFun sells this wheel encoder, which gets 48 pulses per revolution. Not that much better than mine.

Birdmun provided me with this link to Build Your Own Robot, by Karl Lunt. In his book Karl shows how to add an optical (IR) encoder to a servo. He gets 45 pulses per rotation, and discusses add a 2nd encoder to get 90 pulses per rotation.

CtC managed to add an encoder to Walter's motors, but he got it on the first gear in the gear train instead of the last. This provides MUCH better resolution. I believe he gets 360 pulses per rotation. Not bad.

I'll post my results when I get to testing.

I disagree

A 12 degree resolution on a built in home made encoder is very good indeed. I challenge anyone to build anything better and fit it inside a servo casing. 

That is some truly cool stuff, but way above my current budget. Supermodified servos beat my solution hands down as far as capabilities and performance.

You get what you pay for. My solution costs under $1, while a set of Supermodified boards for one servo mod costs over $50.

If the price ever comes down, or if I REALLY need that level of performance, I'd definitely look at the supermodified solution.


I wrote my last message at work with only a few seconds and didn't give proper credit to your servo mod.  I do think it was a cool hack and understand keeping it cheap.  I just wanted to quickly show the other project since it was a very interesting way of doing it.  I think they both have there merits.

Nice job!

-Glen