Passer au contenu

Lesson 10: A servo motor

English

Turn to an angle

  • A servo is a motor that turns to an angle from 0° to 180° and stays there.
  • It is in robots, model planes and doors that open by themselves.
  • Arduino's Servo library does the hard work. #include <Servo.h> loads it.
#include <Servo.h>

Servo arm;

void setup() {
  arm.attach(9);      // the servo's signal wire is on pin 9
  arm.write(0);
  delay(1000);
  arm.write(180);
}

void loop() {
}
  • Servo arm; makes a servo object called arm. arm.write(90); turns it to 90°.
  • The servo needs about half a second to move.

Se connecter ou créer un compte

IGCSE, A-Level & AP