Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

ServoEasing

> 编程语言
Open source

Arduino library to enable smooth servo movement.

382 stars0 likes0 views
WebsiteGitHub

About

Arduino library to enable smooth servo movement.

If you find this library useful, please give it a star.

🌎 Google Translate

YouTube video of ServoEasing in action

Table of contents

  • Servo easing library for Arduino
  • Features
  • List of easing functions
  • API
  • Usage
  • Multiple servo handling
  • Comparison between Quadratic, Cubic and Sine easings.
  • Useful resources
  • Initial movement of Servo
  • Resolution of servo positioning
  • Mapping of servo positioning
  • Speed of servo positioning
  • Minimum number of pulses for reliable servo positioning
  • Why *.hpp instead of *.cpp
  • Using the new *.hpp files
  • Compile options / macros for this library
  • Using PCA9685 16-Channel Servo Expander
  • Using the included Lightweight Servo library for ATmega328
  • Handling multiple servos with the internal ServoEasingArray
  • Examples for this library
  • QuadrupedControl
  • RobotArmControl
  • Servo utilities
  • WOKWI online examples
  • Building breadboard servo adapter
  • Internals
  • Supported Arduino architectures
  • Timer usage for interrupt based movement
  • Adding a new platform / board
  • Troubleshooting
  • Revision History
  • Commercial license

Servo easing library for Arduino

Its purpose is to interpolate the movement between two servo positions set by software.

If your servo control data is e.g. generated by an joystick or other "slow" changing inputs and therefore does not change suddenly or does not jump, you most likely do not need this library!, you may consider to use a digital low pass or simple EMA filters to smooth your values used to control the servos.

ServoEasing works with the Arduino Servo library as well as with PCA9685 servo expanders. The expander in turn requires the Arduino Wire library or a compatible one and is bound to their restrictions.

For ESP32 you need to install the Arduino ESP32Servo library.

If you require only one or two servos, you may want to use the included LightweightServo library which is like the Adafruit TiCoServo library, but more lightweight and currently only for Uno, Nano, instead of the Arduino Servo library. The LightweightServo library uses the internal Timer1 with no software overhead and therefore has no problems with servo twitching or interrupt blocking libraries like SoftwareSerial, Adafruit_NeoPixel and DmxSimple.

For instructions how to enable these alternatives, see Compile options / macros.

Features

  • Linear and 9 other ease movements are provided.
  • All servos can move synchronized or independently.
  • Non blocking movements are implemented by the startEaseTo* functions by using a timer. This functions are not available for all platforms.
  • A degree value of 400 or more is taken as a microsecond value for the servo pulse, which allows for fine-grained control.
  • Float angels are supported to allow fine-grained servo control comparable to using microseconds.
  • User-specified callback function at "servo arrived" enables movement control independent of main loop.
  • Stop and resume of servo movement.
  • Detach and reattach. No servo signal is generated for a detached servo / the output is constant LOW. Therefore, it is not blocked and can be moved manually.
  • A trim value can be set for any servo. Its value is internally added to each requested position.
  • Reverse operation of servo is possible e.g. if it is mounted head down.
  • Constraints for minimum and maximum servo degree can be specified. Trim and reverse are applied after constraint processing.
  • Allow to specify an arbitrary mapping between degrees and microseconds by attach(int aPin, int aInitialDegreeOrMicrosecond, int aMicrosecondsForServoLowDegree, int aMicrosecondsForServoHighDegree, int aServoLowDegree, int aServoHighDegree).
  • Servo speed can be specified in degree per second or milliseconds for the complete move.
  • Multiple servo handling by *ForAllServos() functions like setIntegerDegreeForAllServos(3, 135, 135, 135).
  • All ServoEasing objects are accessible by using the ServoEasing::ServoEasingArray[].
  • Easy implementation of a move list - see ConsecutiveEasingsWithCallback example.

List of easing functions

Linear     Quadratic     Cubic     Quartic

Sine     Circular     Back     Elastic     Bounce

Precision     Dummy     User defined

  • Precision is like linear, but if descending, add a 5 ° negative bounce in the last 20 % of the movement time. So the target position is always approached from below. This enables it to taken out the slack/backlash of any hardware moved by the servo.
  • Dummy is used for delays in callback handler.

All easing functions can be used in the following variants:

All ease functions are called internally with the value: PercentageOfCompletion / 100 giving a call value from 0 to 1.

  • In: Start the function with 0 and go to 1 linear. Except for PRECISION, where we do a bounce if approaching from above (go in to origin).
  • Out: Start the function with 1 and go to 0 linear. Except for PRECISION, where we do a bounce if approaching from below (go out from origin).
  • InOut: Start the function with 0 go to 1 and back to 0.
  • Bouncing: Start with OUT, then return with IN to start degree. E.g. Bouncing of the SINE function results in the upper (positive) half of the sine.

All easing types (starting in flavor IN_OUT, then IN, OUT and BOUNCE) in one plot.

Since the values are computed in a fixed 20 ms raster, the last degree increment or decrement in an easing may be much smaller than the increment/decrement before, resulting in some small discontinuities between adjacent movements.

Constraints

To restrict servo movements to a fixed range, you can specify constraints with setMinMaxConstraint(int aMinDegreeOrMicrosecond, int aMaxDegreeOrMicrosecond) like it is done in the TwoServos example.

Arduino Plotter Output with constraints at 5 ° and 175 ° activated.

Disable easing temporarily

By setting speed -which is an uint16- to a real high value like e.g. 50000, you can effectively disable easing and get almost the same behavior as if using Servo.write() function directly.

API

For floating point constants, use the notation of 123.456f with trailing f (for a floating point constant) to avoid compiler errors. A Doxygen documentation of the sources is available here.

Usage

See also the examples here.

cpp
void setup() {
    Servo1.attach(SERVO1_PIN, 45);
}
void loop() {
    Servo1.setEasingType(EASE_CUBIC_IN_OUT); // EASE_LINEAR is default
    Servo1.easeTo(135, 40);                                 // Blocking call
    Servo1.startEaseTo(45, 40, START_UPDATE_BY_INTERRUPT);  // Non blocking call
    // Now the servo is moving to the end position independently of your program.
    delay(5000);
}

Just call myServo.startEaseTo() instead of myServo.write() and you are done. Or if you want to wait (blocking) until servo has arrived, use myServo.easeTo().

  • Do not forget to initially set the start position for the Servo, since the library has no knowledge about your servos initial position and therefore starts at 0 ° at the first move, which may be undesirable.

    Setting the start position of the servo can be done as the second parameter to myServo.attach(int aPin, int aInitialDegree) or by calling myServo.write(int aDegree),

  • And do not forget to initially set the moving speed (as degrees per second) with myServo.setSpeed() or as second parameter to startEaseTo() or easeTo(). Otherwise the Servo will start with the speed of 5 ° per second, to indicate that speed was not set.

Multiple servo handling

You can handle multiple servos simultaneously by special functions like writeAllServos(), setSpeedForAllServos(), setIntegerDegreeForAllServos(), setEaseToDForAllServos(), updateAndWaitForAllServosToStop(), `setEaseToForAllServosSynchronizeAndWaitFor

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++arduinoarduino-libraryavrbounce

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言