Programming a servo.

Hello, I'm working on a project for my science fair and I need to get a pair of servo's to run. I'm not exactly sure where to begin with the programming and don't have much of an idea where to start :sweat_smile: . I'v checked the two scripts in the "servo" section under the "examples" section and they weren't much help. Can anyone point me in the wright direction? Like directing me to a web site that may be helpful or by leaving an example of a servo script in the reply's. Thanks a lot in advance! :)

Very simple servo code you can use to test your servo.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded

void loop() {
  while (Serial.available()) {
    char c =;  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
      Serial.print("writing Microseconds: ");
      Serial.print("writing Angle: ");

    readString=""; //empty for next input

Can anyone point me in the wright direction?

Not with the little information you provided. Making a servo move is trivial. Simply create an instance of the Servo class, attach that instance to a pin (the same one that you connect the control wire to works best), and call the write() method for the instance. If the value that you specify is different from the current position, the servo will move.

Now, making the servo move the way you want it to is a bigger challenge. However, you haven't defined how/when/why you want the servo to move, so we can't even be sure that a servo IS the right choice for you.

PS. Pay more attention in your spelling class.


Can anyone point me in the wright direction?

PS. Pay more attention in your spelling class.

Obviously he's dropping subtle hints he's building an airplane

oh "Wright" and "right". whoops well everyone makes mistakes, no need to be an ass about it.

no need to be an ass about it.

Well, it is easy, and for some types it is just what they do best. :)