String message; // Store incomming data
int LED = 13 ;
 
void setup() {
 Serial.begin(9600);
 pinMode(LED,OUTPUT);
 digitalWrite(LED,LOW);
}

void loop() {
while (Serial.available() ) {  // while there is data
 delay(50); // 10
 char c = Serial.read();       
 message = message + c;    //Command such as "on"        
 } 
 
  if (message.length() > 0) {
   Serial.println(message) ; 
   if (message == "on")  {
   digitalWrite(LED, HIGH) ;  
   } 
    if (message == "off") {
   digitalWrite(LED, LOW) ;             
   }
  } 
  message = "" ; // clear the memory 
 }