Problem of remote car control by bluetooth module HC-05

Hi.
I have a problem in my project which involves controlling a car remotely by HC-05 Bluetooth module.
the components:
-Arduino Uno
-l298n
-2 DC motors
-HC-05 -
-12V battery
power supply:
12 V (battery) -> 12 (l298n)
and -> Vin(Arduino)
Gnd (battery) -> Gnd (l298n)
and -> Gnd(Arduino)
5V (Arduino) -> Vcc (HC-05)
Gnd (Arduino) -> Gnd (HC-05)
When sending the code the Bluetooth LED, it lights up, but the two motors do not work.
I have already tested both motors and they work perfectly, so there are no problems with either motor.
Please help me as I don't know where the error is.




#include <SoftwareSerial.h>
int ER=5;
int R1=6;
int R2=7;
int EL=3;
int L1=2;
int L2=4;
int bluetoothTx= 10;
int bluetoothRx= 11;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
pinMode(ER,OUTPUT);
pinMode(R1,OUTPUT);
pinMode(R2,OUTPUT);
pinMode(EL,OUTPUT);
pinMode(L1,OUTPUT);
pinMode(L2,OUTPUT);
bluetooth.begin(9600);
Serial.begin(9600);
}
void loop() {
 if(bluetooth.available()){
  char command = bluetooth.read();
  Serial.println(command);
  if(command=='F'){
  digitalWrite(R1,LOW);
  digitalWrite(R2,HIGH);
  digitalWrite(L1,LOW);
  digitalWrite(L2,HIGH);
  analogWrite(ER,255);
  analogWrite(EL,255);
  }
  else if(command=='B'){
  digitalWrite(R1,HIGH);
  digitalWrite(R2,LOW);
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  analogWrite(ER,255);
  analogWrite(EL,255);
  }
  else if(command=='R'){
  digitalWrite(R1,HIGH);
  digitalWrite(R2,LOW);
  digitalWrite(L1,LOW);
  digitalWrite(L2,HIGH);
  analogWrite(ER,255);
  analogWrite(EL,255);
  }
  else if(command=='L'){
  digitalWrite(R1,LOW);
  digitalWrite(R2,HIGH);
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  analogWrite(ER,255);
  analogWrite(EL,255);
  }
  else if(command=='S'){
  digitalWrite(R1,LOW);
  digitalWrite(R2,LOW);
  digitalWrite(L1,LOW);
  digitalWrite(L2,LOW);
  analogWrite(ER,0);
  analogWrite(EL,0);
  }
 }
}

No, you have that backward
it should be --
SoftwareSerial bluetooth(bluetoothRx, bluetoothTx);

Here's a process to identify your problem

  1. Forget about bluetooth to begin with, and get code responding as you want to serial input from the monitor. No line ending will be the right setting.

  2. If the code works with input from the monitor, then after loading the code connect the BT module to the hardware serial pins 0/1 of the Uno. Remember to cross connect the module Tx to the Arduino Rx and the module Rx to the Arduino Tx. Using Kai Morich's Serial Bluetooth Terminal app confirm that the code can run with bluetooth input.

  3. It's not clear to me if you will need input from the monitor in your final program, but if you do, you can move the bluetooth to software serial. If you do not need input from the monitor and only input from the phone, and can disconnect the module when loading code, then I would leave the module on hardware serial. As @anon85221860 notes the software serial constructor is from the point of view of the Arduino.

  4. If the code works with the Terminal app and software serial, then you know the issue is with your MIT App inventor code.

It's working now, but there's still an issue: it moves at its maximum speed.

You might have DIO (HIGH/LOW, ON/OFF) pins connected where PWM (variable speed) pins should be.

This is why... 255 = maximum speed

Yes, l noticed that and corrected the code, now it works well.