Member robots
    Member Robots
    Ancient Stuff
Gallery: Flickr

Portland Area Robotics Society Photos

This is a Flickr badge showing public items from the Portland Area Robotics Society group pool.

Quadrature Encoder Inside and R/C Servo

by Giuseppe Marullo -- giuseppe@marullo.it R/C servos are an invaluable resource for small robots, but they lack feedback. I will describe here how I put a quadrature encoder inside a standard R/C servo. A little step toward motion control. This could be an ideal solution on small robots like the Mark III, you save a lot of space and complexity. Another advantage is that you can use it on almost every robot that already has servos. Quadrature encoders have many advantages over regular encoders: Unfortunately, embedding a quadrature encoder inside a servo is not easy, at least, was not easy for a total mecha-nerd like me. Your mileage may vary.

The Theory

On a standard servo, the first gear gives you roughly 52 counts per revolution (CPR). While this seems a low resolution, using a 4X decoder it really means 208 CPR. This sounds more adequate. The first gear is accessible from above, just drill two holes at 90 degrees each other, push two reflective IR sensors inside and voila, you have your encoder on a servo.

The Reality

The only reflective sensor I was able to get in Italy is CNY70. It has no fancy features present on sensors like the Hamamatsu P5587. I need to use a comparator and a Schmitt trigger to clean up the signal. At first I tried to keep only the IR sensors inside the servo, but soon I discovered that noise was a problem.

The second board included the entire comparator circuit. At this point, there was no space left for the original board. The next release will let you to leave the original board inside.

Stuff Needed

The servo: 2 standard Parallax Servos already modified for continuous rotation. The key here is that everything under the "gear plane" is clear. Probably a modified servo that has the pot left in place won't work.

You need to reach the space under the first gear (approximately the center area), being able to put some stuff under.

The sensors: 4 CNY70 sensors (2 on each sensors)

The electronic stuff:

The Tools:

Begin disassembling the servo on a table. Put away all the parts you won't need. You are going to produce dirt, and gears are greased. They will instantly retain every single particle you have around.

Put away the gears, and take away electronics. You will need two wires connected to the motor, so if the board is soldered directly to the motor, please remove it carefully.

Codewheel Marking

Take the first gear, turn it upside down and paint black exactly one half.
Use the first gear to see if the space under it is suitable to be fitted with the sensors. There should be plenty of space. I think that it is not feasible if you leave the pot -- let me know if it fits.

Almost half of the gear overlaps with the motor; you should have the opposite side free.

Use a cutter to mark the place where holes should be placed. The sensors are square, so it makes sense to cut the holes square as well. You should avoid cutting structural plastic, especially the one that supports the shaft.

Be careful when choosing the place to put the sensors. The center of the sensor should be around 90 degrees from other with respect to the center of the codewheel. This is because the signal should be shifted 90 degrees.

90 degrees between the center of the sensors

  1. Transition between black and white
  2. Middle of white

The effect will be that when on sensor is exactly switching between black and white (or vice-versa), the other sensor will be in the middle of black or white slice.

Once you have the holes done, you have to remove as much plastic as possible inside to accommodate the circuit. Don't cut anything near the motor, or in the corners.


This is the block description of the circuit:

Encoder Board

Try to use this as a starting point for your board, but you need to find out how to build our own. Remember that the circuit will fit tightly, so you will not have to glue it. Try several times to put it inside. Modify it bit by bit, and when it enters with a little effort but does not move you have the right size.

Solder the following circuit, except the reflective IR sensors:

I used the following method to successfully put the electronics inside:

Cutting the holes is not a 5 minute thing. For me it was the most challenging task. You need to align them correctly and try several times to put sensors in. They must remain locked without glue, so you can get the circuit out of the servo.

Another thing to check is that the gear must run free. Double-check it using all the gears.

External Board

This simply has to accommodate the Schmitt inverter IC and 4 LEDs. Only one half (one encoder) is shown:


You need to set the comparators' levels. Turn the pot completely counter-clockwise. You should have LOW on the 74HCT14 output.

Turn the first gear until both sensors "see" black. Gently turn clockwise until the LEDs turn off. Try to turn the first gear and let one sensor see white. Does the LED light up? If the answer is yes, it is okay. Move on the other sensor and repeat. Try to move the wheel; do the LEDs turns on and off like a quadrature encoder's signal?

If you don't see signals while moving the wheel, you could check the IR diodes using a webcam:

Under strong light the sensors may saturate easily: Try to perform the procedure using low lights or using the servo cover.

When you are done, remember to solder two wires to the motor before closing the case. You should use a H-bridge from now on, but just for testing you could connect the electronic board that was inside the servo to the motor using the original circuit.

If you own a scope, you should get a signal similar to this:

As you may note, the phase difference is not exactly 90 degrees but the decoder should not complain about it.


Yes, it is not easy, but I think that it is worth the effort. The next step will be a board that will process quadrature encoders’ signals in hardware and possibly P5587 sensors.


Encoder Wheels

CNY70 - http://www.vishay.com/docs/83751/83751.pdf

Application of Optical Reflex Sensors TCRT1000, TCRT5000, CNY70 - http://new.vishay.co