Serial pwm control help!!!

I am trying to control a servo directly from a serial connection this is my code right now.

#include <Servo.h>
Servo myservo;

int pos = 0;

void setup()


void loop()


if ( Serial.available()) {

pos =;




The values of pos range from 0 to 255 but it only works the first time you send a value then it won’t work anymore. Could you guys revise my code to make it better? I am revlatively new to arduino so any help would be greatly appreciated! I have gotten the sweep code to work so its not the arduino its the code errrr…

try the example code on this page: