Servo motor interfacing

it looks like the sketch above relies on a delay to determine the end of the serial message. The tester below checks for a character that is not a digit to terminate the message.

You can set the Serial Monitor line ending dropdown to NewLine to automatically terminate a message with a NewLine character when the send button is pressed.

// Serial Servo Tester
// Use the Serial Monitor to write a value from 0 to 180
// Set Serial Monitor line ending to Newline
// for writeMicroseconds, use values from  544 to 2400

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
String inString;

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);  //the pin for the servo control 
  Serial.println("Enter angle between 0 and 180 (values from 544 written as Microseconds)");  
}

void loop() {

  while (Serial.available()> 0) {
    int inChar = Serial.read();
    if (isDigit(inChar)) 
    {
      // if the incoming character is a digit, add it to the string
      inString += (char)inChar; 
    }
    else
    {
      // here on the first character that is not a digit   
      int value = inString.toInt(); 
      if(value >= 544)
      {
        Serial.print("writing Microseconds: ");
        Serial.println(value);
        myservo.writeMicroseconds(value);
      }
      else
      {   
        Serial.print("writing Angle: ");
        Serial.println(value);
        myservo.write(value);
      }
      // clear the string for new input:
      inString = "";   
    }
  }
}

edit: fixed a typo in a comment