I see a few problems.
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 sent
while (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 case
if (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.