The last code you posted won't work because you don't wait for 5 chars, so you get the first char then overwrite the array with 0s.
Also, my example did something similar because I had the
inData[i] = '\0';
in the wrong place. Try this.
NewSoftSerial gpsSerial(2,3);
char inData[5];
TinyGPS gps;
PWMServo servo; //have to use the servo library from 0016 otherwise NewSoftSerial messes up the servo
void setup() {
servo.attach(10);
servo.write(90);
Serial.begin(57600);
gpsSerial.begin(4800); //this seems to be causing the problem
Serial.print("Hello there!");
}
void loop() {
if(Serial.available() >=5) { //every command I send is 5 characters long
for(int i=0; i < 5; i++) {
inData[i] = Serial.read();
}
inData[i] = '\0'; // terminate the string
if(strcmp(inData, "right")==0) { //right
servo.write(135);
}
else if(strcmp(inData, "lleft")==0) { //left
servo.write(40);
}
if(strcmp(inData, "strai")==0) { //straight
servo.write(90);
}
}
}
Plus I've moved the servo stuff into the "if(Serial.available() >=5)" code block, there's no point running it until there are 5 chars to test.
Rob