Skip to content

Use servo motors with Arduino


Hi Everyone, this is a tutorial on how to use the servo motors with Arduino Uno you can check it in the video, here I’m gonna post the wiring and codes I used in the video hope you like it.

Servo motors are used in a lot of projects, so everyone learning how to use Arduino should know how to use one. These motors have a high torque, up to 13 kg-cm depending on the type of motor and the operating voltage, they are mostly known for positioning and robots articulations. Also as we can see in codes used, we make them rotate  by mentioning the position, they have a known angle some are between 0-180° and others 0-360°, once the reach their limit they should return, not like the continuous servo-motors they can rotate freely but they cannot be positioned like this and I’ll do another tutorial on these types of motors.

A variety of servo motors and their attachements. (Courtesy of Sparkfun)


Servo motors have three wires: GND/VCC/Signal, here in this case its powered using Arduino’s 5V, you can use 9V or 12V, but read your Servomotor datasheet first to know its supported voltage, just don’t forget Arduino and the Servo external power source should have common ground.

The Signal pin should be wired with one of Arduino’s PWM pins, they are marked with (~), the PWM signal will determine the Servo rotation angle.


The servo library is an Arduino built-in, you don’t need to install a new one.

Code 1 : Simple write/rotation of the servo motor

Code2 : Sweep mode (taken from the Arduino Servo library)


Code 3: Simple code on rotating the servo and keep it in that position, I used it on the video so I decided to write it here too


Code 4: How to use the function “detach”

The “detach” function is a bit forgotten, but it turned to be important in some projects I tested with.
When you send a command to a servo motor it stays on that position until you move it by another command, but sometimes you need the servo to have some “free rotation”, this is where the function is handy, it stops the command signal and the servo can be rotated by hand or external mechanism…



Code 5: Code to read the postion of the Servo motor, I didn’t use it in the video but here is it, it will be useful in the future

The read function is important as well, sometimes you need to know the servo current position before proceeding to other actions, this function returns the servo current angle.



Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

One thought on “Use servo motors with Arduino Leave a comment

Leave a Reply

%d bloggers like this: