Connect two HC-05 modules to controll DC Motors with joysticks

Hi, I have 2 HC-05 modules and decided to have one in a controller with 2 joysticks and the other one in a circuit with 4 DC-Motors. Once they are connected and I try to move the joysticks, nothing happends. This is my code:
Controller:

#include <SoftwareSerial.h>

SoftwareSerial MANDO (10, 11);

int yPin = A0;
int yVal;

int yPin2 = A2;
int yVal2;

int xPin = A1;
int xVal;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  Serial.println ("Listo");
  MANDO.begin (38400);

  pinMode(yPin, INPUT);
  pinMode(yPin2, INPUT);
  pinMode(xPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  yVal = analogRead(yPin);
  //Serial.println(yVal);
  yVal2 = analogRead(yPin2);
  //Serial.println(yVal2);
  xVal = analogRead(xPin);
  //Serial.println(xVal);
  
  if (MANDO.available())
  {
    //Serial.write(MANDO.read());
    Serial.write(yVal);
    Serial.write(yVal2);
    Serial.write(xVal);
  }
 
}

The cicuit with the 4 DC Motors:

#include <SoftwareSerial.h>

SoftwareSerial SUBMARINO (2, 3);

int speedPin = 9;
int dirPin1 = 8;
int dirPin2 = 7;
int speedMotor;
int yVal;

//motor izquierdo
int speedPin2 = 6;
int dirPin4 = 5;
int dirPin3 = 4;
int speedMotor2;
int yVal2;
int xVal;

//motor derecho
int speedPin3 = 10;
int dirPin5 = 11;
int dirPin6 = 12;
int speedMotor3;

int state = 20;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  Serial.println ("Listo");
  SUBMARINO.begin (38400);

  pinMode(speedPin, OUTPUT);
  pinMode(dirPin1, OUTPUT);
  pinMode(dirPin2, OUTPUT);

  pinMode(speedPin2, OUTPUT);
  pinMode(speedPin2, OUTPUT);
  pinMode(dirPin3, OUTPUT);
  pinMode(dirPin4, OUTPUT);

  pinMode(speedPin3, OUTPUT);
  pinMode(dirPin5, OUTPUT);
  pinMode(dirPin6, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(dirPin1, 0);
  digitalWrite(dirPin2, 0);

  digitalWrite(dirPin3, 0);
  digitalWrite(dirPin4, 0);

  digitalWrite(dirPin5, 0);
  digitalWrite(dirPin6, 0);
  
 if (SUBMARINO.available())
 {
  //Serial.write(SUBMARINO.read());
  yVal = Serial.read();
  Serial.write(yVal);
  yVal2 = Serial.read();
  Serial.write(yVal2);
  xVal = Serial.read();
  Serial.write(xVal);

  if (yVal > 600) {
    speedMotor = map(yVal,600,1023,0,255);
    digitalWrite(dirPin1, 0);
    digitalWrite(dirPin2, 1);
    analogWrite(speedPin, speedMotor);
  }
  if (yVal <= 400) {
    speedMotor = map(yVal,400,0,0,255);
    digitalWrite(dirPin1, 1);
    digitalWrite(dirPin2, 0);
    analogWrite(speedPin, speedMotor);
  }

  if (yVal > 400 && yVal < 600) {
    speedMotor = map(yVal,400,0,0,255);
    digitalWrite(dirPin1, 0);
    digitalWrite(dirPin2, 0);
    analogWrite(speedPin, speedMotor);
  }
  
  if (yVal2 > 400 && yVal2 < 600)
  {
    speedMotor2 = map(yVal,400,0,0,255);
    speedMotor3 = map(yVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }


  if (yVal2 > 600) {
    speedMotor2 = map(yVal2,600,1023,0,255);
    speedMotor3 = map(yVal2,600,1023,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 1);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 1);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }
  if (yVal2 < 400) {
    speedMotor2 = map(yVal2,400,0,0,255);
    speedMotor3 = map(yVal2,400,0,0,255);
    digitalWrite(dirPin3, 1);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 1);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }

  if (xVal > 400 && xVal < 600)
  {
    speedMotor2 = map(xVal,400,0,0,255);
    speedMotor3 = map(xVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }

  if (xVal > 600) {
    speedMotor2 = map(xVal,600,1023,0,255);
    speedMotor3 = map(xVal,600,1023,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 1);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }
  if (xVal < 400) {
    speedMotor2 = map(xVal,400,0,0,255);
    speedMotor3 = map(xVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 1);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }
 }
 
}

Does anyone know were the problem is?
Thanks.

Did you pair and connect the HC05s?

How To Configure and Pair Two HC-05 Bluetooth Modules as Master and Slave | AT Commands

How to put HC05 into AT mode.

Hi!

On this part of your code, you´re not reading what is coming from the HC-05... shouldn´t it be instead:

if (SUBMARINO.available())
 {
  //Serial.write(SUBMARINO.read());
  yVal = SUBMARINO.read();
  Serial.write(yVal);
  yVal2 = SUBMARINO.read();
  Serial.write(yVal2);
  xVal = SUBMARINO.read();
  Serial.write(xVal);

Yes I have.

I just tried this and it still does not work.

if (MANDO.available())
  {
    //Serial.write(MANDO.read());
    Serial.write(yVal);
    Serial.write(yVal2);
    Serial.write(xVal);
  }

You are not sending the joystick readings with this code.
First, it should not be in conditional block based on received characters in the software serial buffer.

I would put both the analog readings and the sending on a millis() timer and send values every 500 ms or whatever is an appropriate interval

I think code should be more like this

if (its time to send data to the other board)
{
    yVal = analogRead(yPin);
    yVal2 = analogRead(yPin2);
   xVal = analogRead(xPin);
  
   MANDO.write(yVal);
    MANDO.write(yVal2);
    MANDO.write(xVal);

}

It still does not work. This is my new code for the controller:

#include <SoftwareSerial.h>

SoftwareSerial MANDO (10, 11);

int yPin = A0;
int yVal;

int yPin2 = A2;
int yVal2;

int xPin = A1;
int xVal;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  Serial.println ("Listo");
  MANDO.begin (38400);

  pinMode(yPin, INPUT);
  pinMode(yPin2, INPUT);
  pinMode(xPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  if (yVal > 600 || yVal <= 400) {
      yVal = analogRead(yPin);
      //Serial.println(yVal);
      Serial.write(yVal);
  }

  if (yVal2 > 600 || yVal2 < 400) {
    yVal2 = analogRead(yPin2);
    //Serial.println(yVal2);
    Serial.write(yVal2);
  }

  if (xVal > 600 || xVal < 400) {
    xVal = analogRead(xPin);
    //Serial.println(xVal);
    Serial.write(xVal);
  }
  
}

Well, it seems that you have just ignored the tips that @cattledog provided you in post #6.

Serial.write() will not send anything to the HC-05 module. It will send data to the Serial Monitor only. If you called your SoftwareSerial interface MANDO, then you must MANDO.write() anything that you want it to send.

There are other details like this one:

You´re trying to use yVal, yVal2 and xVal before reading them.

I suggest you to separate your project into smaller goals, forgetting the bluetooth part at the beggining.

  1. read correctly the values that your sticks provide and print them to the Serial Monitor;
  2. make the motors move according to what you tell them to;
  3. send data from stick to cell phone and see if it goes ok;
  4. send data from cell phone to motors and see if they operate as you command;
  5. Only then you mix everything.

It would also be interesting if you provide some more info on your setup. What boards are you using? UNOs? Nanos? How are you powering the circuits?

You are right! I didn't notice that @cattledog used MANDO instead of Serial and that I was using the joystick variables before reading them. After making those changes, it finally sends the data to the other board, but know comes what I was expecting when I first did the code, the board does not distinguish between the 3 variables and every light in the l298 module light up (I am currently not connecting the DC motors just in case something like this would happend).

I am using 2 arduino UNO boards that are beeing currently power by my computer using the usb cable, the first one has a sensor shield 5.0 with the 2 joysticks and the HC-05 module connected to it.
The second board has two l298 modules connected to them, these modules have lights that indicate if the INs are being acivated or not. The motors are powered by 12V.

That´s a good progress! :slightly_smiling_face:

So it´s time to do one of these things:

a) identify the data that you´re sending in order to know what you´re receiving. For example, defining yVal as 1, then sending (1,value of yVal) . Doing the same for yVal2 and xVal using, of course, different numbers to identify them; or

b) instead of sending separated values, send all of them in a row (yVal, yVal2, xVal).

How could I define the variables as numbers? Using #define? Beacuse when I do this:

#define yVal 0
#define yVal2 1
#define xVal 2

An error while compiling says: expected unqualified-id before numeric constant

Post the whole code. The error is not in those 3 lines.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Arduino: 1.8.16 (Windows 10), Board: "Arduino Uno"

BluetoothPrueba:2:14: error: expected unqualified-id before numeric constant

 #define yVal 0

              ^

C:\Users\aleja\Desktop\BluetoothPrueba\BluetoothPrueba.ino:9:5: note: in expansion of macro 'yVal'

 int yVal;

     ^~~~

BluetoothPrueba:3:15: error: expected unqualified-id before numeric constant

 #define yVal2 1

               ^

C:\Users\aleja\Desktop\BluetoothPrueba\BluetoothPrueba.ino:12:5: note: in expansion of macro 'yVal2'

 int yVal2;

     ^~~~~

BluetoothPrueba:4:14: error: expected unqualified-id before numeric constant

 #define xVal 2

              ^

C:\Users\aleja\Desktop\BluetoothPrueba\BluetoothPrueba.ino:15:5: note: in expansion of macro 'xVal'

 int xVal;

     ^~~~

C:\Users\aleja\Desktop\BluetoothPrueba\BluetoothPrueba.ino: In function 'void loop()':

BluetoothPrueba:30:25: error: lvalue required as left operand of assignment

   yVal = analogRead(yPin);

                         ^

BluetoothPrueba:32:27: error: lvalue required as left operand of assignment

   yVal2 = analogRead(yPin2);

                           ^

BluetoothPrueba:34:25: error: lvalue required as left operand of assignment

   xVal = analogRead(xPin);

                         ^

BluetoothPrueba:46:20: error: call of overloaded 'write(int)' is ambiguous

       MANDO.write(0);

                    ^

In file included from C:\Users\aleja\Desktop\BluetoothPrueba\BluetoothPrueba.ino:1:0:

C:\Users\aleja\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial\src/SoftwareSerial.h:102:18: note: candidate: virtual size_t SoftwareSerial::write(uint8_t)

   virtual size_t write(uint8_t byte);

                  ^~~~~

In file included from C:\Users\aleja\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/Stream.h:26:0,

                 from C:\Users\aleja\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/HardwareSerial.h:29,

                 from C:\Users\aleja\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/Arduino.h:233,

                 from sketch\BluetoothPrueba.ino.cpp:1:

C:\Users\aleja\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/Print.h:52:12: note: candidate: size_t Print::write(const char*)

     size_t write(const char *str) {

            ^~~~~

exit status 1

expected unqualified-id before numeric constant



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is the code:

#include <SoftwareSerial.h>
#define yVal 0
#define yVal2 1
#define xVal 2

SoftwareSerial MANDO (10, 11);

int yPin = A0;
int yVal;

int yPin2 = A1;
int yVal2;

int xPin = A2;
int xVal;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  Serial.println ("Listo");
  MANDO.begin (38400);

  pinMode(yPin, INPUT);
  pinMode(yPin2, INPUT);
  pinMode(xPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  yVal = analogRead(yPin);
  //Serial.println(yVal);
  yVal2 = analogRead(yPin2);
  //Serial.println(yVal2);
  xVal = analogRead(xPin);
  //Serial.println(xVal);
  

  if (yVal > 600 || yVal <= 400) {
      MANDO.write(0);
  }

  if (yVal2 > 600 || yVal2 < 400) {
    MANDO.write(1);
  }

  if (xVal > 600 || xVal < 400) {
    MANDO.write(2);
  }
  
}

Nope, forget the #defines. I was suggesting something like this:

void loop() {
  // put your main code here, to run repeatedly:
  yVal = analogRead(yPin);
  //Serial.println(yVal);
  yVal2 = analogRead(yPin2);
  //Serial.println(yVal2);
  xVal = analogRead(xPin);
  //Serial.println(xVal);
  

  if (yVal > 600 || yVal <= 400) {
      MANDO.write(1);
      MANDO.write(",");
      MANDO.write(yVal);
  }

  if (yVal2 > 600 || yVal2 < 400) {
      MANDO.write(2);
      MANDO.write(",");
      MANDO.write(yVal2);
  }

  if (xVal > 600 || xVal < 400) {
      MANDO.write(3);
      MANDO.write(",");
      MANDO.write(xVal);
  }
}

And then you have to adapt your receiver code to "understand" that if you´re receiving "1" before the value, you´re talking about yVal. If you´re receiving "2" you´re talking about yVal2. And if you´re receiving "3", you´re talking about xVal.

This is only a suggestion. The funny thing on developing things is exactly the challenge to find solutions to your problems. :wink:

The Serial Input Basics tutorial with show you several methods to arrange, send, and receive the data.

Ok, I changed the one of the scripts to this:

#include <SoftwareSerial.h>


SoftwareSerial SUBMARINO (2, 3);

int speedPin = 9;
int dirPin1 = 8;
int dirPin2 = 7;
int speedMotor;
int yVal;

//motor izquierdo
int speedPin2 = 6;
int dirPin4 = 5;
int dirPin3 = 4;
int speedMotor2;
int yVal2;
int xVal;

//motor derecho
int speedPin3 = 10;
int dirPin5 = 11;
int dirPin6 = 12;
int speedMotor3;

char bt = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  Serial.println ("Listo");
  SUBMARINO.begin (38400);

  pinMode(speedPin, OUTPUT);
  pinMode(dirPin1, OUTPUT);
  pinMode(dirPin2, OUTPUT);

  pinMode(speedPin2, OUTPUT);
  pinMode(speedPin2, OUTPUT);
  pinMode(dirPin3, OUTPUT);
  pinMode(dirPin4, OUTPUT);

  pinMode(speedPin3, OUTPUT);
  pinMode(dirPin5, OUTPUT);
  pinMode(dirPin6, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(dirPin1, 0);
  digitalWrite(dirPin2, 0);

  digitalWrite(dirPin3, 0);
  digitalWrite(dirPin4, 0);

  digitalWrite(dirPin5, 0);
  digitalWrite(dirPin6, 0);
  
 if (SUBMARINO.available())
 {
  bt = SUBMARINO.read();
  
  //Serial.write(SUBMARINO.read());
  yVal = SUBMARINO.read();
  Serial.write(yVal);
  yVal2 = SUBMARINO.read();
  Serial.write(yVal2);
  xVal = SUBMARINO.read();
  Serial.write(xVal);


  if (yVal > 600 && bt == 1) {
    speedMotor = map(yVal,600,1023,0,255);
    digitalWrite(dirPin1, 0);
    digitalWrite(dirPin2, 1);
    analogWrite(speedPin, speedMotor);
  }
  if (yVal <= 400 && bt == 1) {
    speedMotor = map(yVal,400,0,0,255);
    digitalWrite(dirPin1, 1);
    digitalWrite(dirPin2, 0);
    analogWrite(speedPin, speedMotor);
  }

  if (yVal > 400 && yVal < 600 && bt == 1) {
    speedMotor = map(yVal,400,0,0,255);
    digitalWrite(dirPin1, 0);
    digitalWrite(dirPin2, 0);
    analogWrite(speedPin, speedMotor);
  }
  
  if (yVal2 > 400 && yVal2 < 600 && bt == 2)
  {
    speedMotor2 = map(yVal,400,0,0,255);
    speedMotor3 = map(yVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }


  if (yVal2 > 600 && bt == 2) {
    speedMotor2 = map(yVal2,600,1023,0,255);
    speedMotor3 = map(yVal2,600,1023,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 1);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 1);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }
  if (yVal2 < 400 && bt == 2) {
    speedMotor2 = map(yVal2,400,0,0,255);
    speedMotor3 = map(yVal2,400,0,0,255);
    digitalWrite(dirPin3, 1);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 1);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }

  if (xVal > 400 && xVal < 600 && bt == 3)
  {
    speedMotor2 = map(xVal,400,0,0,255);
    speedMotor3 = map(xVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }

  if (xVal > 600 && bt == 3) {
    speedMotor2 = map(xVal,600,1023,0,255);
    speedMotor3 = map(xVal,600,1023,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 1);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }
  if (xVal < 400 && bt == 3) {
    speedMotor2 = map(xVal,400,0,0,255);
    speedMotor3 = map(xVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 1);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }
 }
  

  /*if (Serial.available())
  SUBMARINO.write(Serial.read());
  yVal = SUBMARINO.read();
  SUBMARINO.write(yVal);
  yVal2 = SUBMARINO.read();
  SUBMARINO.write(yVal2);
  xVal = SUBMARINO.read();
  SUBMARINO.write(xVal);*/
  



  
}

And this is the code of the controller:

#include <SoftwareSerial.h>

SoftwareSerial MANDO (10, 11);

int yPin = A0;
int yVal;

int yPin2 = A1;
int yVal2;

int xPin = A2;
int xVal;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  Serial.println ("Listo");
  MANDO.begin (38400);

  pinMode(yPin, INPUT);
  pinMode(yPin2, INPUT);
  pinMode(xPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  yVal = analogRead(yPin);
  //Serial.println(yVal);
  yVal2 = analogRead(yPin2);
  //Serial.println(yVal2);
  xVal = analogRead(xPin);
  //Serial.println(xVal);
  

  if (yVal > 600 || yVal <= 400) {
      MANDO.write(1);
      MANDO.write(",");
      MANDO.write(yVal);
  }

  if (yVal2 > 600 || yVal2 < 400) {
      MANDO.write(2);
      MANDO.write(",");
      MANDO.write(yVal2);
  }

  if (xVal > 600 || xVal < 400) {
      MANDO.write(3);
      MANDO.write(",");
      MANDO.write(xVal);
  }
  
} 

It know distinguishes between the 3 values, but it has two problems:

  1. It only works one way, it doesn's matter which way I move the joysticks, the motors move the same way.
  2. The motors move like if they were blinking, they move very slowly and , and the lights of the l298 modules are, in fact, blinking.

Some comments:

a) the controller is only sending values that are more than 600 or less than 400. There´s no chance of the receiver to get values between 400 and 600. So, these parts of the receiver code are actually doing nothing:

if (yVal > 400 && yVal < 600 && bt == 1) {
    speedMotor = map(yVal,400,0,0,255);
    digitalWrite(dirPin1, 0);
    digitalWrite(dirPin2, 0);
    analogWrite(speedPin, speedMotor);
  }
  
  if (yVal2 > 400 && yVal2 < 600 && bt == 2)
  {
    speedMotor2 = map(yVal,400,0,0,255);
    speedMotor3 = map(yVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }

if (xVal > 400 && xVal < 600 && bt == 3)
  {
    speedMotor2 = map(xVal,400,0,0,255);
    speedMotor3 = map(xVal,400,0,0,255);
    digitalWrite(dirPin3, 0);
    digitalWrite(dirPin4, 0);
    digitalWrite(dirPin5, 0);
    digitalWrite(dirPin6, 0);
    analogWrite(speedPin2, speedMotor2);
    analogWrite(speedPin3, speedMotor3);
  }

b) by the way, shouldn´t be better to write this:
if (xVal > 400 && xVal < 600 && bt == 3)

like this:
if (400 < xVal < 600 && bt == 3) ?

c) if (yVal <= 400 && bt == 1) { speedMotor = map(yVal,400,0,0,255);

this is doing an inverting map (the less yVal becomes when lower than 400, the higher motor speed gets). I believe that this the desired effect, right?

d)

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(dirPin1, 0);
  digitalWrite(dirPin2, 0);

  digitalWrite(dirPin3, 0);
  digitalWrite(dirPin4, 0);

  digitalWrite(dirPin5, 0);
  digitalWrite(dirPin6, 0);

This part of the loop is turning off the motors at each iteraction of the code and can be the cause of what you describe in (2). Shouldn´t it be on the setup?

Didn't thought about what you say on d), because it worked perfectly before using blueooth, I didn't thought about that being the problem. I will try that as soon as I can.

Also what you say on c) is right, I want the motor to increase its velocity the less the joysitkcs values is lower 400, the higher the motor gets, but I want that when the jostick value is higher than 600, it spins in the opposite direction.

You are making things difficult by not following the methods of the previously linked Serial Input Basics.

For example on the sending code, MANDO.write() will only send a byte value and not an integer. You will only send the low byte value of the numbers between 400 and 600.

if (yVal > 600 || yVal <= 400) {
      MANDO.write(1);
      MANDO.write(",");
      MANDO.write(yVal);
  }

As well, this receiving code makes no sense for the number of bytes being sent.

if (SUBMARINO.available())
 {
  bt = SUBMARINO.read();
  
  //Serial.write(SUBMARINO.read());
  yVal = SUBMARINO.read();
  Serial.write(yVal);
  yVal2 = SUBMARINO.read();
  Serial.write(yVal2);
  xVal = SUBMARINO.read();
  Serial.write(xVal);

I have been reading the Serial Input Basics and i think that I should send the values as binery data, the problem is that I don't know how to do that and I do not understand the examples that they show.