0% found this document useful (0 votes)
9 views

Servo - Arduino Documentation

Uploaded by

gaaloul ghaith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Servo - Arduino Documentation

Uploaded by

gaaloul ghaith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Search on Docs / A R D U I N O .

C C

Go Back
Home / Programming / Library / Servo ON THIS PAGE

Library
DEVICE CONTROL Usage/Examples

Servo Compatibility
Recents viewed
Releases
V1.2.2 Michael Margolis, Arduino Arduino 27/06/2024
Servo
Methods

Allows Arduino boards to control a variety of servo motors.


This library can control a great number of servos.
It makes careful use of timers: the library can control 12 servos using only 1 timer.
On the Arduino Due you can control up to 60 servos.

GO TO REPOSITORY

Usage/Examples Compatibility Releases

This library allows an Arduino board to control RC (hobby) servo motors. Servos have integrated gears
and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various
angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to
be set to various speeds.
Help
The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On
boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9
and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without
interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.

To use this library:

COPY

1 #include <Servo.h>

Circuit
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be
connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be
connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and
should be connected to a digital pin on the Arduino board. Note that servos draw considerable power, so
if you need to drive more than one or two, you'll probably need to power them from a separate supply
(i.e. not the 5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power
supply together.

Examples
Knob: control the shaft of a servo motor by turning a potentiometer

Sweep: sweeps the shaft of a servo motor back and forth

Methods

attach()

write()

writeMicroseconds()

Writes a value in microseconds (us) to the servo, controlling the shaft accordingly. On a standard
servo, this will set the angle of the shaft. On standard servos a parameter value of 1000 is fully
counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle.

Note that some manufactures do not follow this standard very closely so that servos often respond
to values between 700 and 2300. Feel free to increase these endpoints until the servo no longer
continues to increase its range. Note however that attempting to drive a servo past its endpoints
(often indicated by a growling sound) is a high-current state, and should be avoided.

Continuous-rotation servos will respond to the writeMicrosecond function in an manner analogous


to the write function.### Syntax
COPY

1 servo.writeMicroseconds(us)

Parameters

servo: a variable of type Servo


us: the value of the parameter in microseconds (int)

Example
COPY

1 #include <Servo.h>
2
3 Servo myservo;
4
5 void setup()
6 {
7 myservo.attach(9);
8 myservo.writeMicroseconds(1500); // set servo to mid-point
9 }
10
11 void loop() {}

See also

attach()
read()

read()

attached()

detach()

Was this article helpful?

Connect and Contribute

Project Hub Product Compliance


GitHub Repository Help Center
Forum Trademarks & Licensing

© 2024 Arduino Terms Of Service Privacy Policy Security Cookie Settings

You might also like