Help needed in adding speed to my project(4WD RC Car)

Hi Guys,
I recently made a RC Car using Arduino Nano + HC-05.
I want help on adding a control of managing speed, can someone tell me how to add it.

My code-

int led = 13;        //led
int outPin1 = 5;     //motor1
int outPin2 = 6;    //motor1
int outPin4 = 9;   //motor2
int outPin3 = 10;   //motor2
int frontled = 3; //front lights
int backled = 4;  //back lights
int buzzer = 7;   //buzzer

char bt = 0;       //BT 


void setup()
{
  Serial.begin(9600);
  
  pinMode(outPin1,OUTPUT);
  pinMode(outPin2,OUTPUT);
  pinMode(outPin3,OUTPUT);
  pinMode(outPin4,OUTPUT);
  pinMode(frontled,OUTPUT);
  pinMode(backled,OUTPUT);
  pinMode(buzzer,OUTPUT);
    
  pinMode(led,OUTPUT);
}
void loop()
{
  if (Serial.available() > 0)
  {
    bt = Serial.read();
    digitalWrite(led, 1);

        
        
        
         
    if(bt == 'F')        //move forwards
    {
      digitalWrite(outPin1,HIGH);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,HIGH);
      digitalWrite(outPin4,LOW); 
      
digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'B')       //move backwards
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,HIGH);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,HIGH);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'S')     //stop!!
    {   
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'R')    //right
    {
      digitalWrite(outPin1,HIGH);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'L')     //left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,HIGH);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'I')    //forward right
    {
      digitalWrite(outPin1,HIGH);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,HIGH);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'G')    //forward left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,HIGH);
      digitalWrite(outPin3,HIGH);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'W') //front led on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,HIGH);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
    else if (bt == 'U') //back led on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,HIGH);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'w') //front led off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
 
        
    else if (bt == 'u')//back led off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
    else if (bt == 'V') //buzzer on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,HIGH);
    }
 
    else if (bt == 'v') //buzzer off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
                
  }
  
  }

I am using the app - 'Bluetooth RC Controller' by Andi.Co
And it is having a function to control speed via slider, can anyone please tell me how can I add the speed control in my code.

Regards,
TechDroidROOT

arduino_code.ino (4.42 KB)

you will map the slider value to 0-255 and use the analogWrite() function.

It will also depend on your motor driving circuit. As long as the driver circuit is a mosfet/h-bridge type driver the above will work. If it is just a relay, you will have to make some kind of hardware change.

I am using all PWM pins and L298N Motor Driver Board, can you give me an example from my script....

It's not clear how you want the speed to be controlled. You want to have a "slider" on the side of your bluetooth app which sets the speed that forwards/backwards uses when you press those buttons? Changing the slider will send a new command which the Arduino then remembers the speed was set by that command?

That can be done fairly simply with your current program. The main limitation is that you're only taking a single character as input, so sending a command like "set speed to 123" will take a minimum of 3 characters if you abbreviate "set speed to " to one character.

So, without totally re-writing to take multi-character speed commands, what about setting the speed in the range 0-9 by just sending the numeric characters? 10 steps should be enough. I don't know the app you're using, but do you think you can make the "slider" (or maybe a row of 10 buttons) send that single character?

Then the Arduino needs a variable to store as "speed". You could call it "speed". That should be a 0-255 PWM value, so that each of the direction commands can use it without doing any conversion. So when you receive the characters 0-9, your code should store a different value into the speed variable. Speeds below 50 will not move the car, so you can skip everything below that. Experiment with different values.

When writing a speed and direction to each motor, you only need to set one side of the motor LOW and then the other should be analgoWrite(outputPin2, speed); (Or whichever pin is supposed to be HIGH.)

Is that enough of a clue for you to go ahead and modify your code?

Sorry, but I am still not able to understand, I am new at all this and still 15 in class 9th. Please just give me an example for forward movement.
The app slider is on top left, in pic 1 and setting for slider in 2nd screenshot.

I want to add value like 40 on 0, 60 on 2, 90 one etc. till 10.

See the Image Guide

The above images make it look like you are well on your way to solving the problem.

    if(bt == 'F')        //move forwards
    {
      analogWrite(outPin1,speed);
      digitalWrite(outPin2,LOW);
      analogWrite(outPin3,speed);
      digitalWrite(outPin4,LOW);

I have made a new script, can you please check and correct it.

int outPin1 = 5;     //motor1
int outPin2 = 6;    //motor1
int outPin4 = 9;   //motor2
int outPin3 = 10;   //motor2
int frontled = 3; //front lights
int backled = 4;  //back lights
int buzzer = 7;   //buzzer
char bt = 0;       //BT 
int vSpeed = 180; //speed
int i=0;
int j=0;
int state;
const int BTState = 2;

void setup()
{
  Serial.begin(9600);
  
  pinMode(outPin1,OUTPUT);
  pinMode(outPin2,OUTPUT);
  pinMode(outPin3,OUTPUT);
  pinMode(outPin4,OUTPUT);
  pinMode(frontled,OUTPUT);
  pinMode(backled,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(led,OUTPUT);
  pinMode(BTState, INPUT);
    
}
void loop()
{
 
if(Serial.available() > 0)
    {     
      state = Serial.read();   
    }
        
        
        if (state == '0'){
      vSpeed=0;}
    else if (state == '1'){
      vSpeed=100;}
    else if (state == '2'){
      vSpeed=180;}
    else if (state == '3'){
      vSpeed=200;}
    else if (state == '4'){
      vSpeed=255;}

              
         
    if(bt == 'F')        //move forwards
    {
      digitalWrite(outPin1,vSpeed);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,vSpeed);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'B')       //move backwards
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,vSpeed);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,vSpeed);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'S')     //stop!!
    {   
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'R')    //right
    {
      digitalWrite(outPin1,vSpeed);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'L')     //left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,vSpeed);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'I')    //forward right
    {
      digitalWrite(outPin1,vSpeed);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,vSpeed);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'G')    //forward left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,vSpeed);
      digitalWrite(outPin3,vSpeed);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'W') //front led on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,HIGH);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
    else if (bt == 'U') //back led on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,HIGH);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'w') //front led off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
 
        
    else if (bt == 'u')//back led off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
    else if (bt == 'V') //buzzer on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,HIGH);
    }
 
    else if (bt == 'v') //buzzer off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
                
  }

Can you please correct it and tell me what is wrong.
Thanks in advance...

Does it work? It doesn't even compile for me.

How do you expect any value to get into the variable "bt"?

Steve

slipstick:
Does it work? It doesn't even compile for me.

How do you expect any value to get into the variable "bt"?

Steve

It compiles on my Laptop by selecting Arduino Nano Atmega 328P.

Modified script-

int led = 13;        //led
int outPin1 = 5;     //motor1
int outPin2 = 6;    //motor1
int outPin4 = 9;   //motor2
int outPin3 = 10;   //motor2
int frontled = 3; //front lights
int backled = 4;  //back lights
int buzzer = 7;   //buzzer
char bt = 0;       //BT 
int vSpeed = 180; //speed
int i=0;
int j=0;
int state;
const int BTState = 2;

void setup()
{
  Serial.begin(9600);
  
  pinMode(outPin1,OUTPUT);
  pinMode(outPin2,OUTPUT);
  pinMode(outPin3,OUTPUT);
  pinMode(outPin4,OUTPUT);
  pinMode(frontled,OUTPUT);
  pinMode(backled,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(led,OUTPUT);
  pinMode(BTState, INPUT);
    
}
void loop()
{
 
if(Serial.available() > 0)
    {     
      state = Serial.read();   
    }
        
        
        if (state == '0'){
      vSpeed=0;}
    else if (state == '1'){
      vSpeed=45;}
    else if (state == '2'){
      vSpeed=55;}
    else if (state == '3'){
      vSpeed=75;}
    else if (state == '4'){
      vSpeed=100;}
    else if (state == '5'){
      vSpeed=130;}
    else if (state == '6'){
      vSpeed=145;}
    else if (state == '7'){
      vSpeed=180;}
    else if (state == '8'){
      vSpeed=200;}
    else if (state == '9'){
      vSpeed=225;}
    else if (state == 'q'){
      vSpeed=255;}
              
         
    if(bt == 'F')        //move forwards
    {
      digitalWrite(outPin1,vSpeed);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,vSpeed);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'B')       //move backwards
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,vSpeed);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,vSpeed);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'S')     //stop!!
    {   
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'R')    //right
    {
      digitalWrite(outPin1,vSpeed);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'L')     //left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,vSpeed);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'I')    //forward right
    {
      digitalWrite(outPin1,vSpeed);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,vSpeed);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'G')    //forward left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,vSpeed);
      digitalWrite(outPin3,vSpeed);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'W') //front led on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,HIGH);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
    else if (bt == 'U') //back led on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,HIGH);
      digitalWrite(buzzer,LOW);
    }
    else if (bt == 'w') //front led off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
 
        
    else if (bt == 'u')//back led off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
    else if (bt == 'V') //buzzer on
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,HIGH);
    }
 
    else if (bt == 'v') //buzzer off
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      digitalWrite(frontled,LOW);
      digitalWrite(backled,LOW);
      digitalWrite(buzzer,LOW);
    }
 
                
  }

You mean it compiles AFTER you add in a definition for the variable that you then never use. It might have been easier to take the pinMode out instead.

But I still don't see how you expect any value to get into "bt". And what is BTState that you declare as an input on pin 2 then never use again?

Steve

slipstick:
You mean it compiles AFTER you add in a definition for the variable that you then never use. It might have been easier to take the pinMode out instead.

But I still don't see how you expect any value to get into "bt". And what is BTState that you declare as an input on pin 2 then never use again?

Steve

Can you correct it and post please, it will help a lot.

No. The way things work is that we help with advice, you take note of the advice then YOU correct your code, try to compile and test it and then re-post it.

If that's not what you want and instead you just want the code written for you without you doing any work then you're in the wrong place.

Steve

The thing with reading from Serial is you don't know what you're going to read until you read it. If you knew in advance "hey, the next character transmitted is going to be a speed command" then you could just decode speed commands.

The decoding for 0,1,2... should have been done as part of the big if-else chain which decodes everything. It should use the same variable (originally bt) so that you read in one character and compare it to all possible characters that you are expecting.

Made a new code-
Can you check please.

int led = 13;        //Led to show BT connection, will light up if connection active, low on connection not active
int outPin1 = 5;     //IN1 of L298N
int outPin2 = 6;    //IN2 of L298N
int outPin3 = 9;   //IN3 of L298N
int outPin4 = 10; //IN4 of L298N
char state = 0;       //BT 
int vSpeed=180; //Default Speed
int fled = 2; //Front Leds
int bled = 3; //Back Leds
int horn = 4; //Horn

/*-----------------------------------------------------------------------------------------------------*/

void setup()
{
  Serial.begin(9600);
  
  pinMode(outPin1,OUTPUT);
  pinMode(outPin2,OUTPUT);
  pinMode(outPin3,OUTPUT);
  pinMode(outPin4,OUTPUT);
  pinMode(led,OUTPUT);
  pinMode(fled,OUTPUT);
  pinMode(bled,OUTPUT);
  pinMode(horn,OUTPUT);
  }




void loop()
{
  if (Serial.available() > 0)
  {
    state = Serial.read();
    digitalWrite(led, HIGH);
    }
    
    
 if (state == '0'){
      vSpeed=0;}
    else if (state == '1'){
      vSpeed=45;}
    else if (state == '2'){
      vSpeed=60;}
    else if (state == '3'){
      vSpeed=75;}
    else if (state == '4'){
      vSpeed=100;}
    else if (state == '5'){
      vSpeed=125;}
    else if (state == '6'){
      vSpeed=150;}
    else if (state == '7'){
      vSpeed=175;}
    else if (state == '8'){
      vSpeed=200;}
    else if (state == '9'){
      vSpeed=225;}
    else if (state == 'q'){
      vSpeed=255;}
  
    /*_________________________________________________________________________________________________*/
    
    if(state == 'F')        //move forwards
    {
      analogWrite(outPin1,vSpeed);
      analogWrite(outPin2,0);
      analogWrite(outPin3,vSpeed);
      analogWrite(outPin4,0);
    }
    
else if (state == 'B')       //move backwards
    {
      analogWrite(outPin1,0);
      analogWrite(outPin2,vSpeed);
      analogWrite(outPin3,0);
      analogWrite(outPin4,vSpeed);
    }
    else if (state == 'S')     //stop!!
    {   
      analogWrite(outPin1,0);
      analogWrite(outPin2,0);
      analogWrite(outPin3,0);
      analogWrite(outPin4,0);
    }
    else if (state == 'R')    //right
    {
      analogWrite(outPin1,vSpeed);
      analogWrite(outPin2,0);
      analogWrite(outPin3,0);
      analogWrite(outPin4,0);
    }
    else if (state == 'L')     //left
    {
      analogWrite(outPin1,0);
      analogWrite(outPin2,0);
      analogWrite(outPin3,vSpeed);
      analogWrite(outPin4,0);
    }
    else if (state == 'I')    //forward right
    {
      analogWrite(outPin1,vSpeed);
      analogWrite(outPin2,0);
      analogWrite(outPin3,0);
      analogWrite(outPin4,vSpeed);
    }
    else if (state == 'G')    //forward left
    {
      analogWrite(outPin1,0);
      analogWrite(outPin2,vSpeed);
      analogWrite(outPin3,vSpeed);
      analogWrite(outPin4,0);
    }
    
    
    
    
    if (state == 'W')    //front light
    {
      digitalWrite(fled,HIGH);
    }
    
    else if (state == 'w')    //front light off
    {
      digitalWrite(fled,LOW);
    }
    
    
    
    
    
    if (state == 'U')    //back light on
    {
      digitalWrite(bled,HIGH);
      }
    
   else if (state == 'u')    //back light off
    {
      digitalWrite(bled,LOW);
      }
        
    
    
    
    
    if (state == 'V')    //Horn
    {
      digitalWrite(horn,HIGH);
    }
    
    else if (state == 'v')    //Horn off
    {
      digitalWrite(horn,LOW);
    }
    }
  
  
  /*---------------- END -----------------------------------------------------------------------*/

Please check the code if there are any errors.
Regards,
TechDroidROOT

    digitalWrite(led, HIGH);

You never turn the LED off. Is this what you want? It comes on the first time anything is received from Serial and never goes off after that? I would record the time that the character was received and then turn off the LED half a second later. You could also use the timer to turn off the motors too - maybe each press of a button only allows it to run forwards for 5 seconds or only turn for 0.5 seconds.

      vSpeed=0;}

Don't do that. Closing braces ALWAYS go on their own line by themselves. They are so important to the structure of your program that they must always be visible as the only thing on a line. Try the auto-format feature in Arduino. It's very good at cleaning up this kind of stuff for you.

The code is starting to look messy. You have used else if and if interchangeably. Since the variable state can only be one thing then it actually doesn't matter which one you used but it should be consistent. You could also consider changing to the switch() construct, to make it more consistent.

Can you check this one as I have added ENA & ENB for speed.

/*Arduino BT Car */
/*Youtube Channel - TechDroidROOT*/
/*More info - techdroidroot.blogspot.in*/

int led = 13;        //Led to show BT connection, will light up if connection active, low on connection not active
int outPin1 = 7;     //IN1 of L298N
int outPin2 = 8;    //IN2 of L298N
int outPin3 = 9;   //IN3 of L298N
int outPin4 = 10; //IN4 of L298N
char state = 0;       //BT 
int vSpeed=180; //Default Speed
int fled = 2; //Front Leds
int bled = 3; //Back Leds
int horn = 4; //Horn
int ena = 5;  //ENA on L298N
int enb = 6;  //ENB on L298N

/*-----------------------------------------------------------------------------------------------------*/

void setup()
{
  Serial.begin(9600);
  
  pinMode(outPin1,OUTPUT);
  pinMode(outPin2,OUTPUT);
  pinMode(outPin3,OUTPUT);
  pinMode(outPin4,OUTPUT);
  pinMode(led,OUTPUT);
  pinMode(fled,OUTPUT);
  pinMode(bled,OUTPUT);
  pinMode(horn,OUTPUT);
  pinMode(ena,OUTPUT);
  pinMode(enb,OUTPUT);
  }




void loop()
{
  if (Serial.available() > 0)
  {
    state = Serial.read();
    digitalWrite(led,HIGH);
    delay(1000);
    digitalWrite(led,LOW);
    }
    
    
 if (state == '0'){
      vSpeed=0;}
    else if (state == '1'){
      vSpeed=45;}
    else if (state == '2'){
      vSpeed=60;}
    else if (state == '3'){
      vSpeed=75;}
    else if (state == '4'){
      vSpeed=100;}
    else if (state == '5'){
      vSpeed=125;}
    else if (state == '6'){
      vSpeed=150;}
    else if (state == '7'){
      vSpeed=175;}
    else if (state == '8'){
      vSpeed=200;}
    else if (state == '9'){
      vSpeed=225;}
    else if (state == 'q'){
      vSpeed=255;}
 	  
    /*_________________________________________________________________________________________________*/
    
    if(state == 'F')        //move forwards
    {
      digitalWrite(outPin1,HIGH);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,HIGH);
      digitalWrite(outPin4,LOW);
      analogWrite(ena,vSpeed);
      analogWrite(enb,vSpeed);
    }
    
else if (state == 'B')       //move backwards
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,HIGH);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,HIGH);
      analogWrite(ena,vSpeed);
      analogWrite(enb,vSpeed);
    }
    else if (state == 'S')     //stop!!
    {   
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
    }
    else if (state == 'R')    //right
    {
      digitalWrite(outPin1,HIGH);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,LOW);
      analogWrite(ena,vSpeed);
    }
    else if (state == 'L')     //left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,HIGH);
      digitalWrite(outPin4,LOW);
      analogWrite(enb,vSpeed);
    }
    else if (state == 'I')    //forward right
    {
      digitalWrite(outPin1,HIGH);
      digitalWrite(outPin2,LOW);
      digitalWrite(outPin3,LOW);
      digitalWrite(outPin4,HIGH);
      analogWrite(ena,vSpeed);
      analogWrite(enb,vSpeed);
    }
    else if (state == 'G')    //forward left
    {
      digitalWrite(outPin1,LOW);
      digitalWrite(outPin2,HIGH);
      digitalWrite(outPin3,HIGH);
      digitalWrite(outPin4,LOW);
      analogWrite(ena,vSpeed);
      analogWrite(enb,vSpeed);
    }
    
    
    
    
    if (state == 'W')    //front light
    {
      digitalWrite(fled,HIGH);
    }
    
    else if (state == 'w')    //front light off
    {
      digitalWrite(fled,LOW);
    }
    
    
    
    
    
    if (state == 'U')    //back light on
    {
      digitalWrite(bled,HIGH);
      }
    
   else if (state == 'u')    //back light off
    {
      digitalWrite(bled,LOW);
      }
        
    
    
    
    
    if (state == 'V')    //Horn
    {
      digitalWrite(horn,HIGH);
    }
    
    else if (state == 'v')    //Horn off
    {
      digitalWrite(horn,LOW);
    }
    }
  
  
  /*---------------- END -----------------------------------------------------------------------*/

Is this OK?

Well, now it waits 1 second while the light is on and doesn't do anything else during that time. This may be useful for this phase while you're debugging it but that's going to be a problem in the future.

You need to tell us if it's OK. Did it work? Does changing the speed setting get received properly by the Arduino and does it change the motor speed?

Just for fun, this datasheet was last updated in "Jenuary 2000". That must be a very old chip then!