int ledPin = 13; int state = 0; int flag = 0; #include SoftwareSerial BTSerial(11,10); void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); Serial.begin(9600); BTSerial.begin(9600); while(!BTSerial); Serial.println("AT commands:okay"); } void loop() { if(BTSerial.available() > 0){ state = BTSerial.read(); flag=0; } if (state == '0') { digitalWrite(ledPin, LOW); if(flag == 0){ Serial.println("LED: off"); flag = 1; } } else if (state == '1') { digitalWrite(ledPin, HIGH); if(flag == 0){ Serial.println("LED: on"); flag = 1; } } }