#include <SoftwareSerial.h>
SoftwareSerial BT(PB1,PB2);
String state;// string to store incoming message from bluetooth

void setup() {

  BT.begin(9600);
 // Serial.begin(9600); // serial communication started
  pinMode(PB3, OUTPUT); // LED connected to 13th pin


}
//-----------------------------------------------------------------------//  
void loop() {
 
   while (BT.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable 
  char c = BT.read(); //Conduct a serial read
  state += c; //build the string- either "On" or "off"
  }  
  if (BT.available() > 0) {
   
    
  if(state == 1) 
  {
    digitalWrite(PB3, HIGH);
     BT.write(" ON");
    
      } 
  
  else if(state == 0) 
  {
    digitalWrite(PB3, LOW);
     BT.write("OFF");
    
  }     }

//state =""; //Reset the variable
}
