All examples with up to 2 Servos can be used without modifications with the Lightweight Servo library
for AVR by by activating the line #define USE_LIGHTWEIGHT_SERVO_LIB
.
YouTube video of SymmetricEasing and AsymmetricEasing example
- Simple
- SimpleCallback
- OneServo
- TwoServos
- ThreeServos
- ConsecutiveEasingsWithCallback
- SymmetricEasing
- AsymmetricEasing
- ContinuousRotatingServo
- LightweightServoExample
- CatMover
- QuadrupedControl
- RobotArmControl
- PCA9685_ExpanderAndServo
- PCA9685_ExpanderFor32Servos
- Servo utilities
- WOKWI online examples
This example does not use interrupts and should therefore run on any platform where the Arduino Servo library is available.
This example shows the usage of a callback function for multiple moves independent of the main loop function.
This example moves one Servo in different flavors. It uses different speeds and blocking as well as interrupt commands. The internal LED blinks when using interrupt based commands.
This example is the OneServo example with activated line #define USE_PCA9685_SERVO_EXPANDER
to run it on a PCA9685 expander board.
This example shows how to move 2 servos attached at pin 9 and 10 synchronized or independently using the LightweightServo library for an ATmega328 (Uno board etc.). This saves 640 bytes program memory compared to using Arduino Servo library and reduces jitter caused by interrupt handling.
In this example target degrees are specified as floating point values.
It operates the first servo from -90.0 ° to +90.0 ° using attachWithTrim().
This example shows how to move 3 servos synchronized or independently. It demonstrates the use of ServoEasingArray
and ServoEasingNextPositionArray
.
WOKWI online simulation of the ThreeServos example.
.
This example shows a trajectory consisting of 1 linear and 7 non-linear easings in flavor IN_OUT for 1 servo, followed with flavors of IN, OUT and BOUNCING.
Note, that Back and Elastic may not be totally visible at your servo, since they use angels above 180 ° and below 0 ° in this example.
This example uses a callback handler and specification arrays to generate the movement cycle.
Arduino Serial Plotter result of this example if #define PRINT_FOR_SERIAL_PLOTTER
is enabled.
This example shows symmetric (end movement is mirror of start movement) linear, quadratic and cubic movements for 3 servos synchronously.
Arduino Serial Plotter result of this example if #define PRINT_FOR_SERIAL_PLOTTER
is enabled.
This example shows asymmetric (end movement is different from start movement) non linear movements for 3 servos synchronously.
It includes a partially user defined easing function EaseQuadraticInQuarticOut()
.
Arduino Serial Plotter result of this example if #define PRINT_FOR_SERIAL_PLOTTER
is enabled.
This example shows EASE_PRECISION_OUT
type moving up/out to 135 ° with a bounce and way back without a bounce.
Then it does this again with EASE_PRECISION_IN
, doing a bounce on moving down/in to 45 °.
Arduino Serial Plotter result of this example if #define PRINT_FOR_SERIAL_PLOTTER
is enabled.
Example for using the servoEasing library to create speed ramps for a continuous rotating servo. This example rely on your servos stop value being exacly 1500 microseconds. If the stop value of your servo is NOT exactly 1500 microseconds, you must modify the MICROSECONDS_FOR_ROTATING_SERVO_STOP
value in the library file ServoEasing.h.
This example moves 2 servos attached at pin 9 and 10 using the LightweightServo library for ATmega328*.
Demo of using two servos in a pan tilt housing to move a laser pointer.
This example controls 8 servos to move a Quadruped robot.
It is documented here.
Program for controlling a robot arm with 4 servos using 4 potentiometers and/or an IR Remote.
To calibrate your robot arm, open the Serial Monitor, move the arm manually and change the microsecond values for the PIVOT_MICROS_AT_*
, LIFT_MICROS_AT_*
, HORIZONTAL_MICROS_AT_*
and CLAW_MICROS_AT_*
positions in RobotArmServoConfiguration.h.
The example uses the EASE_USER_DIRECT
easing type for all servos except the claw to implement movements by inverse kinematics.
This example is a combination of OneServo example and PCA9685_Expander example. Move one servo attached to the Arduino board and one servo attached to the PCA9685 expander board simultaneously.
Program to show the usage of 2 PCA9685 expander boards with 32 servos.
On the ESP32, the I2C library interferes with the 29 millisecond timer and therefore can only run at 100000 Hz or lower.
Front view | Back view |
---|---|
![]() |
![]() |
This example helps you determine the right end values for your servo.
These values are required for the attach(int aPin, int aInitialDegree, int aMicrosecondsForServo0Degree, int aMicrosecondsForServo180Degree)
function, if your servo does not comply to the standard values.
E.g. some of my SG90 servos have a 0° period of 620 µs instead of the standard 544.
This example does not use the ServoEasing functions.
This example gives you a feeling how fast your servo can move, what the end position values are and which refresh rate they accept.
It starts with setting the servo to 90 °, to easily put your servos to a reference position.
This example does not use the ServoEasing functions.
Not for ESP8266 because it requires at least 2 analog inputs.