//By NMD Weerasinghe @ COTMD

#define LED1Pin 2

String serialCommand ="";
const String command1 ="on";
const String command2 ="off";

void setup() {
  pinMode(LED1Pin, OUTPUT);
  Serial.begin(9600);
  Serial.println(" Enter the command !");

}

void loop() {


if(Serial.available()>0)
{
    serialCommand = Serial.readString();
    Serial.println(serialCommand);
    //Serial.flush();
}

//Serial.println(serialCommand.indexOf(command1));

if(serialCommand.indexOf(command1) >= 0 ) 
{
  serialCommand ="";
  digitalWrite(LED1Pin,true);
  
}

if(serialCommand.indexOf(command2) >= 0 )
{
  serialCommand ="";
  digitalWrite(LED1Pin,false);
}

}