Servo Motors and Control with Arduino Platforms

著者 John LeDuc(ジョン・ルダック)

Digi-Key Electronics の提供

In this article, we’ll discuss the following:

(click the link below to skip to any section that suits your needs)

What is a servo motor?

How do they function? (Basic driving methods & techniques)

How to select a servo motor for your application

Working with Arduino platforms

What is a servo motor?

What is a servo motor, where are they used, what are they made of and, how do they function?

A servo motor is a motor whose shaft turns to position something based off a control signal. They are typically used to steer remote control airplanes by adjusting the wing flaps, flight position for drones, controlling valves used in flow control or continuous drive of wheels for robots. They can be used to position or adjust almost anything you can think of. They consist of a plastic housing which contains a DC motor, a control circuit and a few gears for torque (see Figure 1).

Image of Parallax’s Servo Motor showing the exposed DC motor and gears

Figure 1: Parallax’s Servo Motor # 900-00005-ND showing the exposed DC motor and gears which turn a potentiometer that provides feedback to the control IC for positioning the shaft. A notch on part of a gear limits rotation to 180 degrees. For continuous rotation, the notch can be removed.

How do they function?

Servo motor control of the shaft position comes from using a pulse width modulation signal (PWM) to turn the shaft clockwise or counter clockwise, depending on the pulse width of the signal. Typically, a pulse width of 1 ms will rotate the shaft clockwise and a 2 ms pulse will rotate the shaft counter clockwise. To position the shaft ½ way, or in the middle, a 1.5 ms pulse typically works. You will need 20 ms between each pulse. Figure 2 below shows the timing for each position.

Image of PWM Timing for different shaft positions

Figure 2: PWM Timing for different shaft positions

Image of wiring connections as shown in Parallax’s datasheet

Figure 3: The wiring connections as shown in Parallax’s datasheet.

How to select a servo motor for your application

Determine if you need limited (max of 180 degrees) or continuous rotation. You should also note the amount of torque the shaft needs to be for your application along with the speed of rotation, which is rated in RPM (revolutions per minute).

If you are building a moving object, a robot for instance, continuous rotation servos are typically used to drive the wheels. On the other hand, limited rotation servos can be used for applications such as positioning a model airplane wing flap for flight control, a water valve, a switch, or for assisting a hand grip used for a robotic arm.

Image of Parallax’s High Speed Servo Motor

Figure 4: Parallax’s High Speed Servo Motor # 900-00025-ND which provides continuous rotation of 150 RPM @ 6 VDC

The following chart lists some of the hobby servos available. For more details and a larger selection click this link.

Limited or Continuous Rotation Digi-Key Part number Torque - Rated (oz.-in) RPM Operating DC Voltage Size L/W/H Inches (mm)
Limited 900-00005-ND 38 Limited to 180° 4-6 2.2/0.8/1.6
CR 900-00008-ND 38 50 4-6 2.2/0.8/1.6
CR 900-00025-ND 22 180 6-8 2.2/0.8/1.6
Limited 1568-1320-ND 16.6 Limited to 160° 4.8-6 0.91/0.46/1.14
CR 1528-1496-ND 44.52 56 4.8-6 2.1/0.8/1.5
CR 1597-1197-ND 25.2 100 4.8-6 0.90/0.452/0.94

Working with Arduino platforms

(if you are new to Arduino – see this article link to learn more)

One of the most popular Arduino boards is known as the “UNO”. There are several popular versions from 3rd party suppliers we distribute, for example Adafruit, SparkFun, Seeed, DFRobot, etc. One of my personal favorites is the Red Board from SparkFun (they made some nice improvements over the original “UNO” board). I’ve also used Adafruit’s “Flora” which is a round circuit board that is cost effective and easy to use. To view all of Digi-Key’s Arduino boards, click this link.

Image of Arduino brand UNO and SparkFun’s Red Board (UNO)

Figure 5: On the left is the Arduino brand UNO and SparkFun’s Red Board (UNO) on the right.

If you are already familiar with using Arduino boards, you may skip the following paragraph:

My description of Arduino is as follows - an IC chip and/or board that uses a standard C based language within a popular IDE (Integrated Development Environment) called Arduino IDE where you can create code/software know as sketches to make the main IC chip (in popular boards it is the ATMEGA328 Microcontroller) activate the I/O pins to do something. There is feedback you can get on screen in the IDE (using the serial command) to show what the IC is doing with data – similar to using Windows Hyper Terminal mode to see the serial feedback from the outside world. Tremendous online support is available along with a ton of books and sample code on the internet. Arduino is always updating their IDE, so make sure you download the latest version. They have a lot of libraries of sample code and functions to make the board do what it does. The Arduino boards as they are called, have standard pin outs and have developed a standard called shields to add different functionality to the board – here is a link to the varieties available from Digi-Key.

Let’s get into driving a servo motor using the Red Board:

First the latest version of the Arduino IDE was downloaded and the program started. Then the Red Board was hooked up.

This board uses a mini-B to A USB cable which serves to power the board and download your sketch or written code to the onboard MCU. In this example, standard library example called “Servo- Sweep” was used to drive my servo (see Figure 6).

Image of where the Servo Sweep program is located

Figure 6: Where the Servo Sweep program is located.


/* Sweep


 This example code is in the public domain.


 modified 8 Nov 2013

 by Scott Fitzgerald


#include <Servo.h>


Servo myservo;                                                // create servo object to control a servo

// twelve servo objects can be created on most boards

int pos = 0;                                                           // variable to store the servo position


void setup()    {

    myservo.attach(9);                                      // attaches the servo on pin 9 to the servo object



void loop()   {

    for (pos = 0; pos <= 180; pos += 1)         // goes from 0 degrees to 180 degrees

                                                                                // in steps of 1 degree


    myservo.write(pos);                                 // tell servo to go to position in variable 'pos'

    delay(15);                                                   // waits 15ms for the servo to reach the position



  for (pos = 180; pos >= 0; pos -= 1)           // goes from 180 degrees to 0 degrees


    myservo.write(pos);                                  // tell servo to go to position in variable 'pos'

    delay(15);                                         // waits 15ms for the servo to reach the position



Figure 7: Code for the sweep program. This program is by BARRAGAN modified by Scott Fitzgerald (noted in the code above).

The USB cable was then plugged into the board and then the “Arduino UNO” board was selected under “Tools” at the top left of the IDE. In the same menu, Port was selected to verify that the program picked up which COM port the board was connected to. Finally, the download button on the top left (small arrow pointing right ward) was clicked. After a few seconds, the Red Board flashed some LEDs (indicating the compiled program was being downloaded to the board).

The servo motor was then connected to a separate power supply with the ground tied to the board’s ground (USB power can only drive so much current and the servo is a bit noisy with inductive pulses that are not good for the board).

To control the motor, the PWM input needs to be connected to the board. By looking at the code above, the PWM output is attached to pin 9. Using Figure 3 above, use the white lead or the middle wire, and attach it to pin 9 of the board.

Now it’s time to run the program. The program starts out by zeroing the shaft clockwise as far as it can go and slowly sweeps it counter clockwise 180 degrees and then back the other way - clockwise to zero. An oscilloscope was used to measure the PWM pulse width as it went through the program. It was found that 1.5 ms was correct for 90 degrees and close to 600 µs for zero or all the way clockwise. At 180 degrees, or all the way counter-clockwise, the PWM pulse was close to 2.2 ms. The program worked well and you can change some of the values to see various effects such as locked positions or that changing the delay to a smaller value makes the sweep speedup.

免責条項:このウェブサイト上で、さまざまな著者および/またはフォーラム参加者によって表明された意見、信念や視点は、Digi-Key Electronicsの意見、信念および視点またはDigi-Key Electronicsの公式な方針を必ずしも反映するものではありません。


John LeDuc(ジョン・ルダック)

Digi-Key ElectronicsのデジタルビジネスプロジェクトマネージャであるJohn LeDuc(ジョン・ルダック)は、1984年に彼のキャリアを開始し、当初はDigi-Keyでお客様の技術的質問への回答や、製品のレビューとカタログへの製品追加を担当していました。彼は、National SemiconductorのINS8073 Tiny Basicデモボードのサポートを得意としていました。現在は、当社Webサイトを改善するための独自のアイデアを考えたり、収集することにより、当社のエンジニアリング関連のお客様のデジタル体験を向上させています。彼はエレクトロニクス技術の準学士号を持っています。余暇には電子機器をいじくり回したり、3Dプリンタでユニークな設計を作成する「真夜中のエンジニア」でもあります。


Digi-Key Electronics

ミネソタ州シーフリバーフォールズに拠点を置くDigi-Key Electronicsは、試作および設計段階、量産段階のいずれにおいても、電子部品を卓越したサービスとともにグローバルに提供し、Digi-Keyでは、750社以上の一流メーカーから提供される600万点以上の製品を取り扱っている。