bluetooth modul doesn't receive data

hey evrybody,
can you help me understand why my Arduino with attacked the bluetooth module don't receive the data for turn on and off the led, however, the mobile app gets the data "LED: OFF" , but when i send the data to turn it on it doesn't respond.

Maybe it's your sketch.
Dare to share.

int ledPin = 13;
int state = 0;
int flag=0;

void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}

void loop() {
if(Serial.available()>0){
state = Serial.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;
}
}
}

here is the sketch ... how can i do?!

Always use code tags, so that your code looks like this:

state = Serial.read();

...
   
if (state == 0 ){

State will be an ASCII character, not the number 0 or 1. To check for the character corresponding to the "1" key on the keyboard (serial monitor),

char state;
state = Serial.read();
...

if (state == '1' ){

int ledPin = 13;
int state = 0;
int flag=0;

void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}

void loop() {
if(Serial.available()>0){
char state;
state = Serial.read();
flag=0;
}
if (state == 1 ){
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;
}
}
}

this is the new sketch and it still not working :frowning: !! ... also on the app on my phone gives me a lot of errors...

this is the new sketch and it still not working

... because you did not use code tags.

With this sketch, sending a 'U' toggles the pin 13 LED ─

#include <SoftwareSerial.h>

SoftwareSerial btdata(10,11);  // rx tx
byte incoming;
byte Lpin = 13;
boolean stateLpin;

void setup ()
{
  Serial.begin(9600);
  btdata.begin(9600);
  pinMode(Lpin,OUTPUT);
  
  stateLpin = false;
  digitalWrite(Lpin,LOW);
}


void loop ()
{
  if (btdata.available() > 0)
  {
    incoming = btdata.read();
    if(incoming == 85)   // ascii for 'U'
    {
      if (stateLpin == false)
      {
        btdata.println("ON");
        digitalWrite(Lpin, HIGH);
        stateLpin = true;
      }
      else
      {
        btdata.println("Off");
        digitalWrite(Lpin, LOW);
        stateLpin = false;
      }
    }
  }
}

The Arduino sends back the state of the pin13 LED.

Thank youuu !!