//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() {


while(Serial.available()>0)
{
  serialCommand += char(Serial.read());
  //Serial.print(serialCommand);
}

/*
if(serialCommand != "")
{
  Serial.println(serialCommand);

}
*/

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

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

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

}