Published 2026-03-06
When playing with theservo, have you ever encountered this situation: even though the program has been written, theservojust won't obey, either shaking constantly, or getting stuck halfway through the rotation, or even not moving at all? This "Schrödinger's turn" is really driving people crazy. In fact, nine out of ten reasons behind this are the "soul" of theservo- the PWM signal is not given correctly. Today we are going to talk about what the servo PWM is all about, and how to make the servo "obey your words".
Simply put, PWM is a "code" or "language" that controls the rotation of the steering gear. Think about it, to make the servo motor turn to a specific angle, you have to tell it how much and where to turn, right? This command is transmitted in the form of PWM wave through a signal line. It is actually a square wave with constantly changing high and low levels.
This square wave has a key parameter called "pulse width", which is the duration of the high level. For ordinary servos, this pulse width is usually between 0.5ms and 2.5ms. You can think of it like turning a steering wheel. A pulse width of 0.5ms corresponds to the full left position, 1.5ms corresponds to the steering wheel returning to the center, and 2.5ms corresponds to the rightmost full position.
There is a control circuit inside the steering gear, and it will always keep an eye on this pulse width. When the pulse width changes, it drives the motor to the corresponding angle. So you see, controlling the servo is essentially to precisely control the duration of this high level. This is what PWM does.
Servo vibration is a very common headache problem, especially when you first get started. It feels like you asked the servo to move east, it hesitated, then swayed west, and finally moved east. The whole process was full of "reluctance". When this happens, 99% of the reasons are that the PWM signal is unstable.
If you think about it, if the "code" given to the servo is not clear and fluctuates, the servo will constantly correct its position according to the wrong instructions, which will manifest itself as high-frequency jitter. It's like someone keeps shaking your steering wheel from side to side. Can the car stop shaking?
There are many reasons for signal instability, such as insufficient power supply, and when the voltage fluctuates, the signal will become chaotic. Also, the timer that generates PWM in the code is configured incorrectly, or a function likedelay()is used that will block the running of the program, resulting in inaccurate signal timing. Therefore, to solve the jitter problem, we must first start from the source - signal quality and power supply stability.
Many novices will get stuck at the step of "What number should I fill in the code?" This is actually not difficult. The key is to understand how the development board or driver library you use converts the time concept of "pulse width" into "digits".
Take the most common Servo.h library as an example. It useswrite(angle)function to operate directly, which is simple but not accurate enough. A more advanced method is to use(microseconds)to directly tell it how many microseconds the high level lasts. For example.(1500);is to return the servo to the midpoint.
If you operate registers directly or use other platforms without the Servo library, you have to calculate it yourself. For example, if a PWM period is 20ms and you want the pulse width to be 1.5ms, then the duty cycle is 1.5/20 = 7.5%. If your PWM resolution is 8 bits (0-255), the corresponding value is 255 * 7.5% ≈ 19. Once we find this correspondence, everything suddenly becomes clear.
After you have solved the jitter and allowed the servo to control where to hit, the next pursuit is to make its movements look more natural and smooth. If it jumps directly from 0 degrees to 90 degrees in an instant, the servo will bounce over with a "pop", which will appear very abrupt and have an impact on the mechanical structure.
If you want smoothness, the secret is "interpolation". Don't throw the target angle to the servo all at once, but divide the path into many small steps, and add a very short delay between each step. It's like playing a movie, switching frame by frame, and the continuous movement becomes smooth.
️Operating steps :
1. Set the starting point and end point: for example, from 0 degrees to 90 degrees.
2. Determine the step length: for example, turn 1 degree per step.
3. Circular movement: Use aforloop, from 0 to 90, increasing by 1 degree each time. In the loop body, first let the servo rotate to the current angle, thendelay(15)milliseconds or so before entering the next step. In this way, the servo will rotate smoothly through 90 degrees like an animation. This delay time can be adjusted according to how fast you want the action to be.
This issue must be mentioned because it is too easy to be ignored, and the failure phenomena caused by it are all kinds of strange. The steering gear is essentially a motor. The stronger the power, the greater the current required. If you directly use the 5V pin on the development board to power a large servo, it is equivalent to using a small water pipe to supply water to a fire truck.
Unreasonable restart: When the servo is turned, the instantaneous current pulls the mainboard voltage low, causing the microcontroller to reset.
Crazy spinning: The voltage is unstable. Not only does the servo itself not work properly, it may even interfere with the program operation of the microcontroller and cause the code to run away.
There was no response: the current could not carry it at all, and the servo just hummed and did not move at all.
Therefore, if your servo is a little powerful, such as this, it is strongly recommendedto prepare a separate power supply for the servo(such as a battery or a voltage stabilizing module), and then connect the development board and the power ground wire (GND) of the servo to the same ground to ensure that the signals have a common reference point. This is the basic operation for playing with large servos.
There are all kinds of servos on the market, ranging from a few yuan to hundreds of yuan. How to choose the most suitable one? Mainly look at a few hard indicators, don't just look at appearance.
1. Look at the torque: Torque determines how powerful the steering gear is. The unit is usually kg·cm, which means how heavy an object can be lifted 1 cm from the center of the steering wheel axis. How heavy is the structure in your project, how big is the range of movement, and how much force is required? Just do some conversions and leave a little margin, and you can decide.
2. Look at the speed: the unit is seconds/60 degrees, such as 0.12sec/60°, which means it takes 0.12 seconds to rotate 60 degrees. This depends on your requirements for movement speed. If you want it to be faster, choose a smaller number.
3. Look at the type: analog steering gear and digital steering gear. Simply put, digital servos respond faster, control more delicately, and have stronger holding power, but they are also more expensive. For most entry-level projects, analog servos are enough. Once you understand these points, you can quickly identify your target among a large number of products.
After talking so much, I wonder what projects you are currently working on. Have you encountered any weird problems with the servo? Welcome to share your story in the comment area, and let's discuss and solve it together. If you find this article useful, don’t forget to give it a like and share it with friends around you who are also tortured by steering gear!
Update Time:2026-03-06
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.