Bluetooth controlled car can controlled once then i cant control the carnolonger

Hello,
My car doesnt respond to my command from bluetooh terminal after i have once controlled the car. How can i fix this. The baudrate of the bluetooth module is 115200 and i set my serial monitor to 115200. You can find my code in the attachment.

ControllingCarWithBluetooth.ino (692 Bytes)

Why is it so very hard to simply post the code? >:(

int cw = D1;
int ccw = D2;
int ENA = D3;




void setup() {
Serial.begin(115200);
pinMode(cw,OUTPUT);
pinMode(ccw,OUTPUT);
pinMode(ENA,OUTPUT);
digitalWrite(ENA,HIGH);
}

void loop() {
  while(Serial.available() == 0);
  char val = Serial.read() ;//reads the signal
  Serial.print(val);

  /*********For Forward motion*********/
  
  if (val == 'F')
  {
    Serial.println("FORWARD");
   digitalWrite(ccw,HIGH);  
   digitalWrite(cw,LOW);    
  
  }
  else if(val == 'B')
  {
  Serial.println("BACK");
  digitalWrite(cw,HIGH); 
  digitalWrite(ccw,LOW); 
       
      
  }
  else{
      Serial.println("Invalid!!!");
digitalWrite(ccw,LOW); 
      digitalWrite(cw,LOW);  
      
    }
 
  
}

Why is it so hard to use Tools + Auto Format before posting piss-poorly indented code?

Why is it so hard to tell us what the code ACTUALLY does, where the data is coming from, and how what the code does differs from what you want?

marc1200:
My car doesnt respond to my command from bluetooh terminal after i have once controlled the car. How can i fix this.

You need to tell us more.

What actually happens - give as much detail as you can.

You have lots of Serial.print() statements (which is good) - what do they say?

Does the program work if you connect it to a PC with a regular USB cable and send commands from the Arduino Serial Monitor?

...R

int cw = D1;
int ccw = D2;
int ENA = D3;

void setup() {
//Serial monitor begins at 115200 baud
Serial.begin(115200);
//clockwise turning of motor:
pinMode(cw,OUTPUT);
//counter clockwise turning motor:
pinMode(ccw,OUTPUT);
//enables L298d(h-bridge) a-pins:
pinMode(ENA,OUTPUT);

digitalWrite(ENA,HIGH);
}

void loop() {
  while(Serial.available() == 0);
  char val = Serial.read() ;//reads the signal from hc-05 bluetooth module
  Serial.print(val); //Print recieved var in serial monitor

  /*********For Forward motion*********/
  
  if (val == 'F')
  {
    //car goes forward
    Serial.println("FORWARD");
    //counter clockwise is HIGH:
   digitalWrite(ccw,HIGH);  
   //clockwise is LOW:
   digitalWrite(cw,LOW);    
  
  }
  else if(val == 'B')
  {
    //car goes backwards
  Serial.println("BACK");
  //clockwise is HIGH:
  digitalWrite(cw,HIGH);
  //counter clockwise is LOW
  digitalWrite(ccw,LOW); 
  }

 
  
}

Here is the code with explainations. The program doesnt work at both pc and with an external battery

marc1200:
Here is the code with explainations.

Please also answer the questions in Reply #3

...R

The program both doesnt work at pc or with external battery. What i want : i want to control my car from my smartphone first from a bluetooth terminal app for testing. If i send a letter F then the car goes forward, if i send the letter B then the car goes Backwards. i have my esp8266 connect to a l298d h-bridge.
the h-bridge has an 12v input and ground and i have connected one ground to the esp8266 en one ground to the 12volt battery and the 12volt input also to the 12-volt battery. the h-bridge has also an input 1 and input 2: that is for clockwise turn and counter clockwise turn. next to the input 1 and 2 there is an enable pin that for enabling the l298d h-bridge. i have one motor connected to the h-bridge. i use an hc-05 bluetooth module tx to rx and rx to tx connected so the summary:
i want to controlling the car with bluetooh to go forward en backward and stop with the letter S.
here the code:

int cw = D1;
int ccw = D2;
int ENA = D3;

void setup() {
//Serial monitor begins at 115200 baud
Serial.begin(115200);
//clockwise turning:
pinMode(cw,OUTPUT);
//counter clockwise turning:
pinMode(ccw,OUTPUT);
//enables L298d pins:
pinMode(ENA,OUTPUT);

digitalWrite(ENA,HIGH);
}

void loop() {
  while(Serial.available() == 0);
  char val = Serial.read() ;//reads the signal from hc-05 bluetooth module
  Serial.print(val); //Print recieved var in serial monitor

  /*********For Forward motion*********/
  
  if (val == 'F')
  {
    //car goes forward
   
    //counter clockwise is HIGH:
   digitalWrite(ccw,HIGH);  
   //clockwise is LOW:
   digitalWrite(cw,LOW);    
  
  }
  
  else if(val == 'B')
  {
    //car goes backwards

  //clockwise is HIGH:
  digitalWrite(cw,HIGH);
  //counter clockwise is LOW
  digitalWrite(ccw,LOW); 
  }
   else if(val == 'S')
  {
    //car stops

  //clockwise is LOW:
  digitalWrite(cw,LOW);
  //counter clockwise is LOW
  digitalWrite(ccw,LOW); 
  }

If you won't answer my questions I don't see how I can help. I can't see your project so I can only rely on what you tell me.

And a diagram (a photo of a simple pencil drawing) showing all the connections will be much easier to understand than a verbal description. See this Simple Image Guide

...R

So you've said what you want it to do. But you still haven't said exactly what it is doing now or what results you get from all those Serial.printlns. If you won't provide any useful information we can't help.

Steve

i doesnt work now if i send the letters nothing happens

What does "now" mean? Did it ever work? If it did what exactly happened between it working and not working?

Once more, do you get ANYTHING from all your Serial.printlns? What?

Steve