Arduino Playground

Servo

This is a simple demo of a servo controlled by Arduino.

The servo is connected to Arduino pin number 9. Click on Run Code to start the simulation:


Have questions? Feedback? Please share with us below:

sketch.ino

#include <Servo.h>

Servo myservo;

void setup() {
  myservo.attach(9);
}

void loop() {
  for (int pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15);
  }
  for (int pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }
}