The servo code we are going to use is included in Arduino (just like CIRC001) under: File > Examples > Servo > Sweep.

After loading the sketch, compile and upload it to your metro and watch the servo move!

Sweep

If you're having trouble loading Sweep from Arduino's included examples, the full source code is below to copy/paste into the Arduino editor. 

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Not Working? 

Servo Not Twisting?

Even with colored wires it is still shockingly easy to plug a servo in backwards. This might be the case. Check the connection table if you need help.

Twitching and a flashing LED on your metro?

If the servo begins moving then twitches, and there's a flashing light on your METRO board, the power supply you are using is not quite up to the challenge. Using a fresh battery instead of USB should solve this problem.

My servo is not moving at all

A mistake we made a time or two was simply forgetting to connect the power (red and brown wires) to +5 volts and ground. Check your connections again for faults.

This guide was first published on Aug 18, 2017. It was last updated on Aug 18, 2017.
This page (Code) was last updated on Oct 19, 2020.