# How do you build a simple circuit to control a servo?

A servo is an electro-mechanical device that moves a precise amount based on an electronic signal. The servo will twist under command all the way clockwise or counter-clockwise. The motion is sometimes as much as a full revolution total, but also may be limited to something less like 180 degrees. Servos are widely used in radio controlled (RC) hobbies. For instance you can connect a linkage to it and control the angle of the wheels on a toy RC car for steering. Servos are also used in robotics.

Servos are typically controlled by commercial devices like an RC receiver or a micro controller (computer). Every model servo has different specs. They have different rotation speeds and strengths, and they offer different amounts of rotation. But the control signals can be quite similar. A square wave, which is simply a voltage that swings from zero to battery voltage and back in a repeating chain, drives the signal pin. The time that the signal remains high is the pulse width. The pulses need to repeat about 400 times a second (400hz). A short pulse width of about .0006 seconds (.6ms) corresponds to full rotation one way. A long pulse width of about .0024 seconds (2.4ms) corresponds to maximum rotation the opposite way. Any pulse width in between will proportionally result in a servo position also in between the two extremes.

The control signals are required to be too fast and precise to be controlled manually in any practical manner. So some sort of electronic circuit is needed to drive a servo. But this creates a complication for anyone building something from scratch. If you want to see if a car of your own design will steer properly, it would be useful to have a simple circuit that allows you to control the servo and put it through its paces.

The above picture is a schematic for a circuit that does just that. Every turn in the knob that controls the variable resistor R2, a potentiometer (pot), creates a change in the circuits square wave. And that creates a corresponding movement in the servo. This circuit is a variation on the typical 555 timer astable square wave circuit.

Without the diodes, the on time of the pulse is controlled by (R1 + R2) * C2, and the off time is controlled by R2 * C2. So the on time can never be smaller than half the pulse wavelength (rising edge to rising edge time). And a servo needs a narrow pulse width for the minimum position.

By adding one diode across R2, the on time is now proportional to R1 * C2 and off time is proportional to R2 * C2. Just what is needed for the servo. But the diode makes the two proportions different. So R1 equals R2 does not result in a square wave of equal on and off times.

By adding the second diode above, we create a more elegant design. The R1 and R2 become symmetrical in the circuit. R1 equals R2 then does create balanced on and off times for the square wave.

The potentiometer divides a resistor into two variable pieces

The pot is made up of a resistor with a third wire that makes contact by friction somewhere in the middle of the resistor. This middle wire then drags from one end to the other as the knob of the pot is turned. As the wiping wire gets closer to one end, the resistance between that end of the resistor and the wipe wire gets smaller. And at the same time the resistance to the farther end gets larger. But always the sum of the two resistors remains the same full amount of the pot. The wipe wire is changing which side any portion of the resistor contributes from one side to the other.

So in the above circuit, R2 is only the portion of the potentiometer from the wipe wire to the bottom terminal. And R1 is the sum of the 12k resistor and the top portion of the potentiometer resistance. And now that the second diode creates symmetrical contribution to high pulse width and low pulse width from R1 and R2, the pulse frequency doesn’t change as R1 get bigger and R2 gets smaller, and vice versa.

The diodes improved the circuit, but also made the frequency voltage supply dependent. Diodes block current in one direction, and allow current to flow in the forward direction. But in the forward direction they also create a voltage drop of almost .7 volts. This drop varies only slightly and non-linearly with change in current. This complexity makes it harder to predict pulse width and frequency for different component values.

The solution is to simulate the design on a computer. Analog circuit simulation is best done on a Berkley Spice based program. There are expensive commercial programs like Hspice. But I used the good and free for most uses LTspice IV from Linear Technology.

I used the following parts in my circuit design:

Simulation allows you to design with components you can’t purchase. So knowing what parts are available will aid you in your design. Stick with standard values, and allow for variation. The 0.027uf C2 capacitor is the only component I chose that is best to get as high precision. The C2 capacitor affects frequency and thus pulse width. By controlling the variation in C2, we can then compensate for any other component variations with pot R2. In cases where supply voltage might vary, then you may find it useful to have R1 be a 10k ohm resistor in series with a 10k ohm trip pot.

The following are screen captures from my simulations of the above design.

The simulator doesn't have a potentiometer. I manually adjusted the component values. Here I show a 50% duty cycle with R1=R2

The 100k pot can go all the way to zero, and that leads to no pulse. I simulated with 1k ohm remaining to get the maximum pulse width of 2.44ms which is more than the needed 2.4ms. The servo maximum position will be reached just before R2 drops to 1k.

R1= 111k and R2= 1k

When the 100k pot is used all for R2 the pulse width is .275ms which is less than the needed .6ms. The servo will thus reach the minimum position before R2 is fully 100k. If you wish, you can add the 10k trim pot, and you can then raise the pulse width at the expense of decreasing the frequency below the 400hz design goal.

R1=12k and R2=100k