How servo motors work and how to control servos using Arduino


Dejan Nedelkovski over at HowToMechatronics shared detailed tutorial on how servo motors work and how to control servos using Arduino and PCA9685 PWM driver:

There are many types of servo motors and their main feature is the ability to precisely control the position of their shaft. A servo motor is a closed-loop system that uses position feedback to control its motion and final position.
In industrial type servo motors the position feedback sensor is usually a high precision encoder, while in the smaller RC or hobby servos the position sensor is usually a simple potentiometer. The actual position captured by these devices is fed back to the error detector where it is compared to the target position. Then according to the error the controller corrects the actual position of the motor to match with the target position.
In this tutorial we will take a detailed look at the hobby servo motors. We will explain how these servos work and how to control them using Arduino.

MoreĀ details atĀ HowToMechatronics.

Check out the video after the break.


Join the Conversation


  1. A thing I wish I knew getting into Arduino-controlled servos is that the typical “180 degrees” servos DO NOT move 180 degrees for the standard 1-2ms pulse width range (only 90ish) and that the Arduino’s 0-180 range servo command DOES NOT mean 0-180 (but 0-90), considering it’s outputting the 1-2ms standard range. Instead, you generally have to go outside that range to get your “0-180” (actually, more like “5-175”) servo to hit its end stops (which is a bad idea by the way). To the credit of this article, they at least mention that this is a thing that does happen…

    1. So it’s a servo library designed by a software guy, or a library targeted at embedded newbies, or a learner bike. Given the design of cheap servos, nobody publishes specs for the input signal. Nobody is also going to publish position error graphs given probable non-linearities of the potentiometer etc.

      It is not realistic to easily plug in a servo and immediately command it to move so many degrees. The manufacturer is not going to calibrate the servo and add to his cost. Even if he tries to calibrate it, a position error graph is going to look ugly. So forget that. The onus is on the buyer to calibrate the part for the project. A library that expects to command a servo in degrees upon plug-in is a metric truckload of crock, there has to be calibration setting features.

    2. IMHO PCA9685 is not a really good part for this application. It’s a PWM LED driver for goodness’ sake. NXP _does_not_ mention servos in the datasheet! Don’t listen to Alibaba sellers!

      PCA9685 has an internal oscillator, but remember, it’s for LED control, where just the duty cycle is needed. Now get this: the datasheet has no spec entry for the oscillator! They don’t wanna tell! It may well be 5% around room temps and 10-20% over the full range. The oscillator is probably not going to be calibrated during testing either. Every module you use with servos will have to be calibrated, and oh, don’t use it where there are big temp swings and you need accuracy and not bang-bang positioning.

      Folks, read the part datasheet before you buy modules. Make an effort to avoid promoting poor practices.

Leave a comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.