HC-05, really long delay and can't set any baud rate

Hi there! Recently I bought two HC-05 Bluetooth modules, and, when I connected them to my project (Arduino Bluetooth car) and tried to send commands from my phone, the delay for any command was really long (3-10 sec.) Need to say that the commands were arriving to the Arduino correctly (in echo in serial port are the same characters that i send, but with a long delay). Tried to change baud rate(from 9600) in both code and serial monitor, but, it still only works only on 9600 baud, on others it just arrives some strange characters.

So, I established AT commands mode and tried to discover what's going on. At commands were working properly on standard, 38400 baud. But, when I send AT+UART? It returns me... 4800,0,0. Really strange, as I read in forums, no one gets 4800 baud as a standard. And also, so why is it working on 9600 baud?! Anyways, I tried to change that with AT+UART=9600,0,0 it says ok, and when I ask another time AT+UART? I says 9600,0,0. Ok, problem solved? Nope, when I restart the whole system, and ask AT+UART? It says 4800,0,0. I can't change it to any baud rate (38400, 9600, 115200...). Has anyone got a similar problem? Should I just return the modules and buy some hc-06? And also, what can I do with the "delay" that's the only problem, if I fix that, I will no longer touch anything and just leave it working.

here is the code:

char t;
#define A1 2
#define A2 3
#define B1 4
#define B2 5

void setup() {
pinMode(A1,OUTPUT);   //left motors forward
pinMode(B1,OUTPUT);   //left motors reverse
pinMode(A2,OUTPUT);   //right motors forward
pinMode(B2,OUTPUT);   //right motors reverse

Serial.begin(4800);
 
}
 
void loop() {
if(Serial.available()){
  t = Serial.read();
  Serial.println(t);
}
 
if(t == 'F'){            //move forward(all motors rotate in forward direction)
  digitalWrite(A1,HIGH);
  digitalWrite(B1,HIGH);
}
 
else if(t == 'B'){      //move reverse (all motors rotate in reverse direction)
  digitalWrite(B2,HIGH);
  digitalWrite(A2,HIGH);
}
 
else if(t == 'L'){      //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
  digitalWrite(B1,HIGH);
}
 
else if(t == 'R'){      //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
  digitalWrite(A1,HIGH);
}


 
else if(t == 'S'){      //STOP (all motors stop)
  digitalWrite(A1,LOW);
  digitalWrite(B2,LOW);
  digitalWrite(B1,LOW);
  digitalWrite(A2,LOW);
}
delay(100);
}

Thanks for any help)!

I'm going to guess this is a timeout issue.

But, in the absence of code (big hint there), that really is just a guess.

Yes, it is, I will add the code right now

Or, you could've saved a post and just posted the code.

Done

Using 4800 baud between the module and the Arduino can not explain a several second delay.

tried to send commands from my phone

How are you doing this? How are you distinguishing between the two receiving modules? Why do you need two modules?

I tried to send from an app called Bluetooth Rc controller(worked fine with other modules in other projects) and after that, from a normal Bluetooth terminal, same problem everywhere.

No, I didn't connect two modules at once, I just wanted to say that I bought two modules and they both have the same problem. I was expecting to use modules in different projects.

I'm happy to work through this with you, but I would like you to do a few things to make trouble shooting easier.

First, for the phone app I want you to use Kai Morich's Serial Bluetooth Terminal. It is rock solid and has many good features.

Try this code. With the data from the BT terminal on the phone, it will help separate out the receive and response times

char t;
#define A1 2
#define A2 3
#define B1 4
#define B2 5

void setup() {
  pinMode(A1, OUTPUT);  //left motors forward
  pinMode(B1, OUTPUT);  //left motors reverse
  pinMode(A2, OUTPUT);  //right motors forward
  pinMode(B2, OUTPUT);  //right motors reverse

  Serial.begin(4800);
  //Serial.begin(9600);

}

void loop() {
  if (Serial.available()) {
    t = Serial.read();
    Serial.println(t);
  }

  if (t == 'F') {          //move forward(all motors rotate in forward direction)
    digitalWrite(A1, HIGH);
    digitalWrite(B1, HIGH);
    Serial.println('F');
  }

  else if (t == 'B') {    //move reverse (all motors rotate in reverse direction)
    digitalWrite(B2, HIGH);
    digitalWrite(A2, HIGH);
    Serial.println('B');
  }

  else if (t == 'L') {    //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
    digitalWrite(B1, HIGH);
    Serial.println('L');
  }

  else if (t == 'R') {    //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
    digitalWrite(A1, HIGH);
    Serial.println('R');
  }

  else if (t == 'S') {    //STOP (all motors stop)
    digitalWrite(A1, LOW);
    digitalWrite(B2, LOW);
    digitalWrite(B1, LOW);
    digitalWrite(A2, LOW);
    Serial.println('S');
  }
  delay(100);
}

The information on the phone screen should look like this

Won't that confuse things?

I wasn't planning to use analog pins, if you mean that, but yes, you're right at some point

You maybe right. There are compiler warnings. Which I didn't notice at first.

C:\Users\RICHAR~1\AppData\Local\Temp\arduino_modified_sketch_264734\sketch_jul30a.ino:4:0: warning: "B1" redefined
 #define B1 4
 
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:32:0,
                 from C:\Users\RICHAR~1\AppData\Local\Temp\arduino_build_975958\sketch\sketch_jul30a.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/binary.h:31:0: note: this is the location of the previous definition
 #define B1 1

I thought they would be about the analog pins but they were about B1. The BT part of the sketch runs as expected, and Serial output on pin1 doesn't appear disturbed, but I didn't really test the actual motor pin outputs.

Renaming the variables can't hurt.

Oh, thank you so much, really)

Ok, so, I uploaded the sketch, downloaded the app, and, the timeout between send and receive is randomized(?) Yeah, I've written something strange, it's not between 3 and 10 sec., It could be only with that car controller app, but with Kai Morich bluetooth terminal, the timeout is between 1 and 3 seconds, and also I'm getting some artefacts on echo.


Yes, and here, any ideas of what is this ^M and why there are empty receipts?

In the terminal settings under Receive set the line ending to Newline CR+LF.

Also under the settings for Send, Clear Input on send should be on to help prevent repeats. Also confirm that no delays are set.

Can you try without the motors connected to see if you replicate my findings. I have not configured my HC05 to 4800 baud, but will do that if the pure code is not responding the same way.

It's already on CR+LF

Actually, just now I've done that with no motors

No, there is no need, on 4800 it's not working at all, I changed(uncommented) 9600 baud rate

I'm confused. Earlier you said that the HC05 baud rate was fixed at 4800 and you couldn't change it. Are you now saying it is indeed 9600, and it communicates with the Arduino with that setting?

It's already on CR+LF

This is what produces the ^M. The Arduino .println() adds CR+LF. The phone program needs to be set for that.

Let's complain things about baud rate.

AT commands show that baud rate for the module is 4800, and it can't change.

The module works with Arduino (sends and receives correct characters only on 9600)

AT commands work on 38400, as all the normal modules

Good news.

Let's see if you can get clean readings on the phone. You may want to attach the Receive and Send settings so I can confirm we are the same.

Can you get the ^M's to go away?

I think we live in different time zones...

Actually, not really, now I'm getting sometimes 3 echos in a row and sometimes, i get spaces received in the same millisecond. But, I don't know how, not the ^M and ^J went out (I already had CR+LF)

I attach some screenshots:




I am using your settings and do not see this.
It's a little hard to be sure of the colors in the screen posting, buth when sending the character I see blue (echo of the send) and two green repeats (one from the receive block) and one from the digitalWrite block. Then a gap of two spaces for the CR/LF.

I can somewhat reproduce your results when hitting reset on the Arduino at the right time during a cycle. So I would focus your attention on resets of the Arduino. Insufficient power is likely the main cause.

What do you see with the motors disconnected? In reply #14 you said

Does this mean that with no motors, the results are correct?

I assume the motors are separately powered from the Arduino and are driven by relays. Is this correct?

How is the HC05 powered? How is the Arduino powered? Separating the HC05 from the Arduino power would be a good first trouble shooting step.

I don't really understand you, with a normal module, the send/receive has pretty any timeout, but in my case, it is about 3 sec.

Pretty much, the motors are driven from drivers, powered separately from a power supply

Arduino and the module are actually powered from the USB port of my laptop, the module is powered through 5v pin on the Arduino.

Ok, maybe I also should to try to power the Arduino from a 9v power supply on pin Vin