Curriculum
Course: Dustbin Project
Login
Text lesson

Servo Functions

Servo Fuction

The Servo library has a few main functions, but students usually need only attach() and write() for most projects.

Here are the important ones:

Function Purpose Example
attach(pin) Connect servo to a pin lid.attach(9);
write(angle) Move servo to an angle (0–180°) lid.write(90);
read() Read the current angle angle = lid.read();
detach() Disconnect the servo lid.detach();
attached() Check if servo is attached lid.attached();
writeMicroseconds(us) Control servo using pulse width lid.writeMicroseconds(1500);
attach(pin, min, max) Attach with custom pulse limits lid.attach(9, 500, 2400);
×
×

Cart