Arduino Servo Code?

Hello, I am trying to control 1 servo with Arduino Uno (I'm a beginner).

I found this example Arduino code: http://playground.arduino.cc/Learning/SingleServoExample

I am unsure what all of the case "w", case "d", case "a", etc. are...

They are characters sent via the serial interface

When you input one of those characters from the Serial Monitor it makes the servo move differently depending on which character is used..

Look up switch/case in the Reference section

...R

I am just trying to write code that allows me to manually control the arduino based on separate conditions. How do I just write commands to rotate the servo a certain distance/direction?

joeyswit: I am just trying to write code that allows me to manually control the arduino based on separate conditions. How do I just write commands to rotate the servo a certain distance/direction?

Isn't that what the playground example does? Have you tried it?

To move a servo to an angle (say 90 deg) you do servo.write(90);

If that does not meet your requirement try to write your own code and then post it here so we can help you with it.

...R

Very simple servo test code you can try where you can send the position commands to the servo.

// zoomkat 7-30-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// 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() {
  Serial.begin(9600);
  myservo.attach(9);
}

void loop() {

  while (Serial.available()) {

    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
      delay(3);
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);
    int n = readString.toInt();
    Serial.println(n);
    myservo.writeMicroseconds(n);
    //myservo.write(n);
    readString="";
  } 
}

@zoomkat, you clearly have several very useful servo examples and your nice wiring diagram.

Have you considered creating a Thread and putting them all into it ? Then you (and others) could link to it when advice was required. Suggested title “Zoomkat’s servo examples”

…R

I may make a code place if I find another simple free web hosting site. I had one for years from my ISP, but they quit the free customer web hosting a couple years back.

zoomkat: if I find another simple free web hosting site.

I was just thinking of a Thread in this Forum - free and easily accessible to other Forum users. Create a Thread and add several empty (or nearly empty) posts to grab some real-estate. Then go back and edit them at your leisure.

...R