int relay = 12;
String command="";

void setup() {                
  pinMode(relay, OUTPUT); 
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  Serial.begin(115200);
}

void loop() {
  while (Serial.available()) {
    command += (char)Serial.read();
    if (command.indexOf("Ron")>=0){
      digitalWrite(relay, HIGH);
      Serial.println("Relay engaged");
      command="";
    }
    if (command.indexOf("Roff")>=0){
      digitalWrite(relay, LOW);
      Serial.println("Relay disengaged");
      command="";
    }
    // keep length small
    if (command.length()>5){
       command=command.substring(1);
    }
  }
}


