Arduino and RC Servos Frequently Asked Questions

The engineering brief addresses Frequently Asked Questions (FAQs) for students getting started with Arduino microcontroller control of RC servos.

What is an RC servo?

At a fundamental level, we define a servo as a system of components designed to control a mechanism. The featured RC servo is a position-based system that moves an actuator in response to a control signal originating from the Arduino microcontroller.

An RC servo is an electromechanical actuator originally designed to control a surface in a hobby Remote Controlled (RC) airplane, boat, or car. The RC servo accepts a Pulse Width Modulated (PWM) control signal from the local controller installed on the craft. The operator sends commands to the craft’s controller using a remote-control radio frequency transmitter. This three-part system is designed for low cost to maximize the number of people who could participate in the hobby. The “RC” ecosystem has grown over the years to include high performance servos, controllers, and transmitters.

The servo itself consists of a motor, geartrain, sensing element, and control circuitry. These components are designed to work as a system to move the servo mechanism to the desired position. No single component is more important than the other. However, for academic purposes we will focus on the sensing element.

Figure 1 shows the servo components removed from the protective case. The sensing element is the black variable resistor. When installed, it is physically located directly underneath the servo’s large output gear. It provides feedback to the controller indicating the servo’s position.

See “How is an RC servo related to the PID controller?” at the end of this article for additional information about the RC servo. There we explore the relationship between the RC servo and the popular Proportional Integral Derivative (PID) controller.

Figure 1: Components of an RC servo showing motor, gears, variable resistor, and controller.

Tech Tip: An RC servo’s operation is dependent on the operation of the variable resistor. A worn out or dirty resistor will cause the servo to jump or to hunt. Damaged gears are also problematic. High-performance servos will often include metal gears for the final output.

Why does an RC servo have three wires?

The three wires are used to provide both power and control to the servo. These wires are typically terminated into a three-pin (female) 0.1 inch (2.54 mm) connector with a black, red, yellow wire order. This is important, as it prevents damage if the header is accidentally installed backwards.

  • Black: Return wire for the DC power supply

  • Red: Positive DC supply wire with a voltage between 4.8 and 6 VDC.

  • Yellow: Control wire for the Pulse Width Modulation signal.

Tech Tip: For breadboarding purposes, header pins such as the Sullins Connector Solutions PRPC040SACN-RC provide a convenient way to connect to the servo to the breadboard. An example is shown in Figure 2.

Figure 2: The RC servo may be connected to a breadboard using long 0.1 inch (2.54 mm) header pins.

Which Arduino should I use?

As a rule, every Arduino may be used to control an RC servo. However, there has been a progression of Arduinos since the original 2005 debut leading to better performance.

There may be advantages to using the latest version such as the Arduino UNO R4 Minima. The 32-bit processor with additional memory provides additional speed and resources. Also, the newest UNO R4 Minima is less expensive than the UNO R3.

As I prepared this article, I did perform several experiments to measure the jitter associated with the servos. An Arduino Nano Every was compared to a UNO R4 Minima. The servos were programmed to sweep back and forth. The R4 did sound smoother, implying that there is less jitter. Yet, there was no sound from either system when the servos were stationary. In practical terms, this is unlikely to make a difference as real-world RC servos are not precision actuators. Apologies, as I was unable to derive a meaningful comparison. While there was some observed difference with an oscilloscope display set for persistence, the measurement was not definitive or otherwise worthy of showing on this forum.

Tech Tip: A traditional timer-based Interrupt Service Routine (ISR) could be used to further reduce the timing jitter. This is highly desirable low-level programming technique used to produce precise intervals from within a microcontroller. The ISR solution is beyond the scope of this article, yet you are encouraged to add it to your growing list of microcontroller skills that must be mastered.

Can the Arduino directly power the RC servo?

The Arduino’s power supply is limited. It can generally power one or perhaps two tiny RC servos provided they are not heavily loaded. If the servos move fast, are heavily loaded, or bind, there will be a momentary current spike. This could cause the microcontroller to reset.

You may be able to improve this situation by placing a large electrolytic capacitor across the servo’s supply wires. Note that this technique has limited application as the size and number of servos grows.

How many RC servos can an Arduino control?

The answer depends on the hardware and programming interface:

  • Direct control using the Servo library is limited to 12 servos for most Arduinos with boards such as the Mega controlling up to 48.

  • Indirect control using devices such as the NXP PCA9685 allow a single microcontroller to control hundreds of servos. The limit is a function of the code complexity, servo power requirements, and wiring of the system. There is also a requirement for unique addresses when using protocols such as I2C. As an example, consider the MIKROE Servo Click and the Adafruit PWM Servo Shield they each support up to 16 RC servos. Multiple servo driver boards could be used thereby increasing number of servos by a multiple of 16 for 32, 48, or even 64 devices, all controlled from a single microcontroller.

What hardware is required?

The answer depends on the type, number, and power requirements of the servo:

  • A Simple experiment with small servos may be conducted using a breadboard as shown in Figure 2. The servo may be powered via the Arduino 5 VDC supply. We recognize that the Arduino’s power supply is very limited, and the servo could power supply glitches large enough to reset the microcontroller.

  • Multiple servos may be powered from a breadboard, provided as external power supply is used. Once again, we recognize that there are limitations, as the breadboard is limited to about 1 A as described in this engineering brief.

  • Large servos and systems with many servos will require dedicated hardware. The previously mentioned MIKROE click is limited to about 3 A. The high-end large RC servos will require a direct connection to the DC power source.

Tech Tip: For reference, the small 5-servo robot on my desk consumes 400 mA when stationary with no load in a semi-folded position. It required significantly more current when moving, fully extended, or when multiple servos are moving fast.

How is an Arduino Connected to an RC servo?

The servo should be powered from an independent source as the on-board Arduino supply is limited.

The PWM control pin for the Arduino may be connected directly to the microcontroller. I recommend using a series-connected 1 kΩ resistor as shown in Figure 2. This provides a level of protection should a servo accidentally be connected incorrectly.

Tech Tip: You are encouraged to observe the current draw for a servo. Note the current when the servo is stationary with no load, moving fast, and stationary while holding a load against gravity. Also watch the current as you gently push against the servo; be sure to push in both directions.

Should I use the write(angle) or the writeMicroseconds(us) function?

That depends on your application, as we balance simplicity against performance.

  • The write() method takes a type int parameter with a value between 0 and 180. Consequently, the ideal servo’s position is defined using 180 unique steps.

  • The writeMicroseconds() method takes a type int parameter with values between 544 and 2400 us. An ideal servo’s position is defined using 1846 unique steps.

In practice, it may be difficult to differentiate between the two methods. Real-world servos have limited loop gain which implies that they do not snap to the ideal position. You can verify this fact by gently pushing against a servo. There will be a certain give (droop) as if pushing against a spring. There is also a certain amount of backlash (slop) in the geartrain.

Tech Tip: The writeMicroseconds() method is confined to 554 to 2400 us. This can be modified using the servo.attach(pin, min, max) where min and max define the servo limits. This should be done for all servos. For example, there may be mechanical obstructions, or the wire harness may bind.

How can I organize my code to control many servos?

That is a topic worthy of its own article which I am currently working on.
As a general statement, place your servos into a struct. Then code functions to iterate over the servo data held within the struct. As an example, we should include the servo’s min and max values in the structure. These are used for servo initialization where a FOR loop iterates and initializes all servos. For the same reason, include I/O pin numbers.

The fun is just beginning as we need to construct C-based getter and setter functions or C+±based methods to control the servos using the information contained within the struct.

More to follow on this topic.

How is an RC servo related to the PID controller?

To fully appreciate the operation of the servo we would need to explore the Proportional Integral Derivative (PID) controller as shown in Figure 3. Here we see the feedback, the control algorithm and motor (physical plant).

We won’t go into details in this article. However, we recognize that the RC servo contains an analog control mechanism to position the servo in response to an input. The ideal servo uses a negative feedback loop to ensure that the mechanical output (position) is set according to the input signal. A brief analysis of this topic is included as Figure 1.

We recognize that this is not a perfect system. In fact, the controller is tuned with conservative values with stability being prioritized over absolute position. Consequently, there will always be a slight difference between the command signal and physical output. The difference between setpoint and measured output varies in proportion to the load applied to the servo. A heavily loaded servo will droop.

Figure 3: The RC servo is related to this Proportional Integral Derivative (PID) controller.

Video 1: High-level comparison between the RC servo and the PID controller.

Parting thoughts

The RC servo isn’t as simple as it seems.

From a control perspective, we see a robust and stable implementation of a negative feedback system used to position the servo’s position in response to a PWM (setpoint). From a software perspective, controlling one servo is easy. Controlling many servos requires a methodical software design which will be explored in a future article.

Please add your questions and comments in the space below. We may boost your questions and add it to this FAQ.

Best wishes,

APDahlen

Related information

Please follow these links to related and useful information:

About this author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this.