1) You should initialize val to something. I would suggest something other than w, s, d, or a.

2) You did not put in a delay for movements associated with a w, a, or d.

3) Once your arduino is sent "val" the servos will continuously move in the direction specified. The reason is that once "val" is received "val" will not change until a new "val" is sent. This means that the servo will move an additional 5 degrees every 16ms (specified by your delays). The way I would solve this would be

//create an endless loop so that nothing happens until serial data is sentwhile (true){//this if statement will only be executed when data is sent to the arduino if (Serial.available() > 0) { val = Serial.read();//after val is set get out of the loop break; }}//example caseif (val == 's' && uppos > 0){ uppos = uppos - 5;//could also be written uppos-=5 ;) upservo.write(uppos); delay(15); //this is where you should change val to something other than w, s, a, or d //however this is not nessicary with the above while loop. }4) A servo will only rotate a fixed amount of degrees. Your program will attempt to move the servo beyond those limits. example for when val = 's':

instead of the if statement if( val == 's' ) use if( val == 's' && uppos > 0 ). This prevents uppos from becoming a negative number. There should also be an upper limit that prevents uppos from becoming larger than the amount of degrees your servo can move.

Well for number 4 the Servo library in Arduino will automatically compensate for negative numbers or numbers above 180. But it is still good programming practice to not let the value get under or over.

Well for number 4 the Servo library in Arduino will automatically compensate for negative numbers or numbers above 180. But it is still good programming practice to not let the value get under or over.

Thats not the problem. The variable will go negative.

example: if you press s when uppos is 0 nothing happens as far as the servo is concerned, but the variable uppos is now -5. This causes a prblem when you press w. W will have to be pressed enough times to make uppos 0 before the servo will move. That is a problem.