Introduction: Make Your Own Low-cost Servo

Picture of Make Your Own Low-cost Servo

I had a problem with some servos which i bought for my arduino but i don't know why , they were making some strange noises and were drawing too much current. So i decided to make my own servos ! . First of all its important to know exactly how a servo works.
The servo is mainly a DC motor with a motor driver , a comparator and a "feedback potentiometer". The potentiometer (as its name suggests ) gives a feedback to the controller about the current position of the servo shaft. These servos are usually expensive and are fragile. To make our own servo we'll need :
1. A microcontroller  ( preferably Arduino coz i have made a library specially for these DIY Servos -- I've attached the library below
2. a 10k ohm free moving potentiometer as shown
3. a piece of strong flexible wire ( for mount )
4. some super glue
5. a motor driver :  build your own 30 AMP MOTOR DRIVER :

Step 1: Start Building It !

Picture of Start Building It !

1. First bend the pins of the potentiometer outward as shown and Solder three wires to it .
2. now apply some superglue on the tip of the motor-shaft and place the potentiometer's knob carefully on the motor shaft
NOTE : Do not apply too much superglue as the viscosity of superglue is very less and it can easily lock your shaft / gears or ruin the potentiometer

3. now bend a piece of strong and flexible wire in such a way that it will hold the pot firmly in it's place

4. glue the ends of the wire mount to the potentiometer's body ( not the knob ) and fix it on the motor

Now your servo is ready !  

Step 2: Library and Basic Working

Extract the folder from the zip to   Program files (x86) /  Arduino  / libraries / CustomServo

Now restart the Arduino IDE and paste the code in it and upload it.

The custom servo can be used in robots , etc but not for RC planes or copters.  
The servo shaft's position is encoded by the feedback pot from 0 to 1023 ( zero to extreme )  to  avoid excess turning due to momentum of the shaft , the actual turn area has been limited to 160 degree cutting off 10 degree offset from each side. 
When we send a value to the microcontroller , it compares the value and the position of the servo shaft . If there is a difference between these values  ,the arduino commands the motor driver to drive the servo CW or CCW and equalize the values. To have smooth motion and less momentum build-up , PWM values are required to calculate the phase difference and set the motor speed accordingly. It has been tested with minimum 2 degrees of noticeable displacement .

It requires many PWM outputs , these can be multiplexed using a 8-bit multiplexer ( 4051 )  to reduce the pin count

Step 3: Hook It Up to Arduino

Picture of Hook It Up to Arduino

The pin connection has been shown in the picture. The wiper goes to analog 0 , one of the wires from the potentiometer to GND on arduino and the other to +Vcc on arduino.  The motor is to be connected to a motor driver and the inputs of the motor driver are connected to arduino PWM pins only ***

Step 4: Upload the Code

Download the provided CustomServo libray 

here is the code by which you can tell the servo to set it's position as commanded by the used using serial monitor
it can take values from 0 to 160 (in degree)

/* Program and library made by electro18 (Tanay P.)
This code is an example of the CustomServo library
The user can input any value from (0 to 160) in the serial monitor
and drive the custom servo
pin connection :
motor driver input 1 : pin 9
motor driver input 2 : pin 11
Servo feedback pin   : analog 0
pot pins to +5 and gnd on arduino

#include<CustomServo.h> //include the custom servo library
int angle;                // angle by which the servo will rotate
CServo servo1(9,11,0);    // initialize the servo with CServo myservo( pin 1 , pin 2 , analog feedback pin )
void setup()

  Serial.begin(9600);    // setup serial connection

void loop()
while(Serial.available())     // check for availability of serial port
   angle=Serial.parseInt();    // input an integer from 0 to 160 as the angle value and hit enter

};         // drive the servo using angle ) where   0 <= angle <= 160
  Serial.println(angle);      // print the current angle
The CustomServo library description :

1. setting up a custom servo    --- >   CServo myservo( pwm pin 1 , pwm pin 2, analog pin )

eg :    CServo myservo(9,11,0);

2. Commanding it  ----->               angle )
                                                                where angle lies b/w  0 and 160

eg :;         // the servo will rotate 120 degrees


RobinC57 (author)2016-02-07

How is this low-cost? You don't really need a arduino to make a servo...
It's a nice project, but far from low-cost.

SethS1 (author)RobinC572016-03-30

I beg to differ. I am gonna use this to turn a gear motor from a drill into a servo, using a $0.50 potentiometer, a $10 Adafruit Pro Trinket (stripped down Uno), and a $23 18V drill from Harbor Freight. It will have more than 100 in-lb or over 1600 in-lb of torque, i.e. equivalent to this:

I think low cost applies :)

electro18 (author)RobinC572016-02-07

Well in that case you might want to consider using a window comparator or a rather cheap microcontroller. Generally high torque servos are really expensive and if you use cheaper components then it may save you a couple of bucks or so.
Applications involving a combination of microcontrollers and multiple servos together would prove to be "low-cost" because you won't need an in-built controller circuit for that ( excluding RC applications ). In any case you'll have to feed PWM variable signals to the servo to make it work. ( Here the purpose is solved by an arduino else you'll need an RC Tx - Rx pair or a simple PWM generator ).

JaviL2 (author)2016-02-08

electro ill be emailing your instructables account look for me in your box, im trying to use your lib for this model i created

JustinD8 (author)2015-11-23

is this gonna work with 24 volt dc motor? thanks

should do, 24v goes to motor power side and logic side (feedback resistor) to arduino power. For the H-Bridge most fets need 12v or so to switch correctly so you will need to take care to get logic level fets that can operate on 5v and handle the 24v motors current (I learned the hard way, non logic level fets explode if you try to switch 24v with only 5v driving them, wear sun glasses..).

Norhamdillah (author)2015-02-26

good work!!' can I use arduino motor sheild as the motor driver? would there be any changes to the code if I use the sheild?,If so, can you point out which lines of code do I need to change?

electro18 (author)Norhamdillah2015-03-05

Yeah the Arduino Motor shield would serve the purpose as well. The only thing that you have to change is the enable pins and the brake pins.
The motor driver that I'm using depends on the values given to the PWM inputs, i.e. it changes the direction of the spin according to the PWM inputs.
Whereas in the arduino motor shield, you have to consider the enable and the brake enable pins. Some changes are required in the code to make it work with the shield, the changes have to be done in the library itself ( the .cpp and header file ). If you want, I can rebuild the library for you.

hard2man (author)electro182015-05-21

hello , plz can you send me the library cuz i'm working with the motor shield and does'nt work just the noises :(

Norhamdillah (author)electro182015-03-05

It would be much appreciated if you can make the library for me, thanks in advance :)

electro18 (author)Norhamdillah2015-03-05

Okay sure, but I won't be able to build and test it for now because I have my school exams right now. As they end, I'll test it and then mail it to you. I need you email ID for that.

Norhamdillah (author)electro182015-03-06

It's ok bro, take your time,here's my email

Ironspine (author)2015-04-11

hi there I have a sabertooth dual motor speed control the + gives 5 volts to power a rc receiver im wanting to try this im a newbie strictly rc but just to be sure the 5 v out do I not need to hook that wire up doesn't it just use ground and the signal wire ? like if I didn't want to power my rc reciver with the BEC in the ESC the controller has an rc mode that just uses pwm inputs wasn't sure if this was for a different kind of motor controller

Mr AbAk (author)2015-03-06

Awesome idea...

schel (author)2015-02-09

Darn cool!!! Much Thanks! I do wish the "pins" you name were a bit more clear.

I want to try this this but, as I can't figure out from your instructable' what are pins 1 and 2 that you use /'s in the code as well but, I'm not using any pins 1 and 2 anywhere..? also could you show how to do 2 of these on 1 arduino/MC? as in for the use of "robot legs" etc....I think if you could do that, the "pins" in question would become more clear. Much Thanks!! Great, very useful method!

electro18 (author)schel2015-02-10

The pin 1 and pin 2 are the two inputs of the motor driver. The Arduino PWM pins 9 and 11 are directly connected to the pin 1 and pin 2 on the motor driver which controls the motor. Depending on the configuration of the motor pins, you may have to swap the connections.

schel (author)electro182015-02-10

OH! IN1 IN2 gotcha' Much Thanks!! Im still not gettin' how to move the motor tho'...I can read the pot' when I turn the motor shaft by hand...but no movement from the code itself to make the motor turn? I think my issue is more in the code than "hookin' up" stuff. I want a "sweep" like the servo sweep with this rig. x2 Awesome job and thanks for taking the time to answer my lame questions!!

electro18 (author)schel2015-02-10

Okay, so did you check your motor driver ? does it work as expected ? Did you try swapping the IN1 and IN2 pins ? If this still doesn't seem to work then paste your entire code in the comment box, I'll try to run it myself and get back to you soon ! :)

IsaacErickson (author)2015-01-29

Has anyone been successful in getting this to work with Servo.h? The famed Arduino servo library? I want to control my new homemade servo with another Arduino. I have been able to change the angles through the serial port.

electro18 (author)IsaacErickson2015-01-29

This servo will NOT directly work with the default servo.h. To make this happen , you'd need two things :

a comparator and an on-board motor driver,

the potentiometer feedback would be then given to the comparator which will provide input to the motor driver. The arduino PWM pin should be now connected to the other input of the comparator.

Now you should be able to run your custom servo with the Arduino Servo library.

Though this method would cause too much jittering and unnecessary swinging of the motor shaft due to it's high moment of inertia ( as compared to the commercially available servos ).

This problem won't occur in the CustomServo library as it is optimized to decelerate the rotor as it approaches the given position.

Hope this helps ! :)

IsaacErickson (author)2015-01-17

Thank you so much!

I built this and it works well, but I have one problem.

My custom servo rotates to whatever angle I write into the code, then it holds the shaft there rock solid! Can I use an additional micro to program it, though? I'd like to use a second Arduino to give the angle and delays using servo.h, the same way one would program an RC servo. Please help. I have a big, beefy geared PMDC, big h-bridge circuit and a 12 volt/6 amp power supply.


electro18 (author)IsaacErickson2015-01-17

It seems that you're using a constant value for the function 100 ). Instead you could use a variable ( say, int angle ) and then take the values of angle from the serial monitor. Just use the above code to run your servo , after opening the serial monitor , write the desired angle in the command bar. The servo should then move accordingly. Hope this helps :)

In case the servo doesn't respond to your commands, reset your arduino and make sure that the main power is isolated from the microcontroller. Also make sure that your serial monitor is working properly ( i.e. your arduino is properly communicating with the PC ).

IsaacErickson (author)electro182015-01-18

I am not using a constant. I copied your code posted above. I would like to program this just like a standard Futaba RC motor (for a robot). Is that possible? I would like to program in the delays and angles, like this:


I also tried the serial connection. It shows the angle. It also updates (and scrolls) when I type in the angle, but the motor doesn't respond. It just stays locked on whatever angle that I type in, like ';' Of course, I can take the potentiometer off of the shaft and rotate it. The motor will slow, rotate and reverse accordingly.

I'm sorry to be a bother. This was a fantastic post, but don't think I am completely there yet.

electro18 (author)IsaacErickson2015-01-29

Well, the library works fine with the servo that I've made. The library has nearly the same commands as the default servo library.

The code works fine for me ! I'd require some photos or if possible , a working video of your creation if the problem persists.

rasjefferson (author)2014-10-31

this is wonderful, it works perfectly, i've learnt a lot. however i am trying to make a continuously moving servo using a rotary encoder, arduino and a h-bridge, have you worked on it?

electro18 (author)rasjefferson2014-10-31

Thanks :)

I'm sorry but I haven't worked with mechanical rotary encoders yet. Though you can make the same with an optical IR encoder to track the number of revolutions.

EliasS2 (author)2014-10-06

So, I have the servo part built, ie the motor and a 5kohm potentiometer (off of an M8 Snowmobile), and I need to control it (the 12V motor). Can the Arduino Uno do all of that or do I need a motor driver still?

electro18 (author)EliasS22014-10-06

Assuming that the motor in your snowmobile is brushed and requires high current , there is no way you could control it directly using Uno. You'd need a high current motor driver for that purpose ( though you'd still need an Uno for controlling the motor driver ). The I/O pins on Uno are capable of delivering 40 mA max and drawing too much current ( even a simple 12VDC motor ) could damage it.

vu2aeo (author)2014-08-16

Great Job! I like the 2 degree accuracy!

electro18 (author)vu2aeo2014-08-17

Thanks !

vinderoed12 (author)2014-07-14

thanks for a very good instructabels

electro18 (author)vinderoed122014-07-18


vinderoed12 (author)2014-07-14

hej do you know how to control the home made servo with a secondary potentiometer

electro18 (author)vinderoed122014-07-15

What do you mean by a secondary potentiometer ? If you want to use the "knob" program from the servo library using another potentiometer ( on breadboard ) then you just have to map the values of the potentiometer from 0-1023 to 0-160 ( i.e from analog values to values in angle ) .

robobot3112 (author)2014-06-18

anyway is the servo controller that potentiometre

electro18 (author)robobot31122014-06-19

Sorry , but I don't get your question. Are you asking about the servo controller or the potentiometer ?

robobot3112 (author)electro182014-06-19

servo controller what is it?

electro18 (author)robobot31122014-06-19

To run a servo you'll need a controller ( usually an MCU ) to provide a PWM signal. In my case the custom servo has to be connected to an MCU board ( eg. Arduino ) . As this servo is custom made and has no "on-board" comparator , the pin-usage and the programming part becomes quite complex as compared to a regular servo. In a regular servo , they use the concept of a window comparator circuit whereas in my design , the job is done by an external MCU.

robobot3112 (author)2014-06-15

awesome . i was looking for cheap servos but each were more than 300 rs i finnally got a cool thing

electro18 (author)robobot31122014-06-15

Yeah ! well these are really cheap. These would cost around INR 80 .

vgregorio (author)2014-04-18

Is it required to use a motor driver in the circuit? Or can i just connect the pins of the motor directly to ground & +5V?

electro18 (author)vgregorio2014-04-24

Yes it is necessary to use a motor driver because , the motor needs a driver to spin in both the directions ( CW & CCW ) and with different speeds. If you connect the motor directly to the power supply then it won't work as a servo but a simple DC motor.( You can connect your motor to L293D motor driver if you are using a less powerful motor )

darkbain (author)2014-03-20

Love it, exactly what I was searching for. Will be giving it a go tonight I hope. Thanks for posting this.

electro18 (author)darkbain2014-03-24

Thanks ! I'm glad that my instructable helped you ! :)

gada888 (author)2014-03-04


electro18 (author)gada8882014-03-05

Thanks :)

About This Instructable




Bio: Hey there ! I'm Tanay , a hobbyist interested in making robots and sharing stuff. I hope that my instructables help you in solving your problems ... More »
More by electro18:USB Chameleon Lamp ( Color replicating )Your Own Color Sensor using LEDsMeasure RPM - Optical Tachometer
Add instructable to: