Delay with hc-05 communication

Hi i not and expert i just started making small robots an i have a problem. I want to make a bluetooth controlled car using an arduino UNO booard , a L298N motor driver an HC-05 bluetooth modul. All was excellent until i tried to controll my car and noticed that it has very big delay while send information. What i mean is that HC-05 connect to my phone and must blink two times in order to receive information .

That is my code:

int ENA = 6;
int ENB = 5;
int IN1 = 8;
int IN2 = 9;
int IN3 = 10;
int IN4 = 11;
char val;


void setup()
{
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  Serial.begin(9600);
  
}

void loop()
{
  while (Serial.available() > 0)
  {
  val = Serial.read();
  Serial.println(val);
  }
if(val == 'F')
{
 digitalWrite(IN1,HIGH);
 digitalWrite(IN2,LOW);
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW);
 analogWrite(ENA,255);
 analogWrite(ENB,255);
}
else if(val == 'B')
{
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH);
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,HIGH);
 analogWrite(ENA,255);
 analogWrite(ENB,255);
}
else if(val == 'R')
{
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,LOW);
  analogWrite(ENA,255);
  analogWrite(ENB,0);
}
else if(val == 'L')
{
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  analogWrite(ENA,0);
  analogWrite(ENB,255);
}
 else if(val == 'S') //Stop
    {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    analogWrite(ENA,0);
    analogWrite(ENB,0);
    }
  else if(val == 'I') //Forward Right
    {
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    analogWrite(ENA,255);
    analogWrite(ENB,0);
    }
  else if(val == 'J') //Backward Right
    {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    analogWrite(ENA,255);
    analogWrite(ENB,0);
    }
   else if(val == 'G') //Forward Left
    {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    analogWrite(ENA,0);
    analogWrite(ENB,255);
    }
  else if(val == 'H') //Backward Left
    {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    analogWrite(ENA,0);
    analogWrite(ENB,255);
    }
}

PLEASE HELP ME !!

what do you mean by

What i mean is that HC-05 connect to my phone and must blink two times in order to receive information

also describe how you connect to your HC-05 from your phone

First of all i haven't used forum again and i don't know how to use it so if you could help me by publishing it i would appreciate it.

I mean that the Bluetooth-module's red led blink two times and then start again to print information to the serial monitor . As a result i cant control my car immediately any time . Do you want to sent you a video or you understood ;

Finally if i understand correctly i used an app called : Bluetooth RC Controller

Sorry for my English:)

dionisis05:
First of all i haven't used forum again and i don't know how to use it so if you could help me by publishing it i would appreciate it.

there are a few stickies post at the top of the forum exactly for this - titled conveniently as

  • New General Guidance and How to use the Forum
  • Useful links - check here for reference posts / tutorials
  • Read this before posting a programming question ...

would suggest to start there :slight_smile:

describing your connection means taking a piece of paper and drawing things the way they are actually wired, taking a picture and posting it in your post. a link to the actual components you use would be good too

there are plenty of information here on HC-05, worth reading


The LED changes to two quick-flashed every couple of seconds upon successful Bluetooth connection, so I would not worry too much about that LED

in your code, when you do this, where is that printed?  Serial.println(val);are you sending that back as an echo to your phone?

is your phone set to send CR/LF after the text?

You could try with the Bluetooth Terminal HC-05 to see if the issue comes from your application connecting and disconnecting

are you sure the baud rate is 9600 ? often it's 38400 by default. Did you play with that?

dionisis05:
I mean that the Bluetooth-module's red led blink two times and then start again to print information to the serial monitor .

No it doesn't. Bluetooth passes the message as soon as it is received. The blinking red LED is simply telling you it is connected and has no bearing on the print speed.

If you get any action at all, your baud rate is sure to be correct. Just to on the safe side, you could send a longer plain etxt message from Android, which your existing code should print it to monitor.The default rate is rarely, if ever, 38400. The app you are using only deals with communication between phone and Bluetooth. I imagine there are instructions about exactly how the data should be sent, and your problem could be there.

Your Arduino code looks kosher and should not slow things down. I rather suspect using the "case" procedure would be more elegant, but I don't know if it makes any difference to the speed.

Passing the data to monitor should not slow things down but it will ultimately be redundant, and you might as well comment that line out now.

Nick_Pyner:
The default rate is rarely, if ever, 38400

I would not say "if ever" but you are right they actually usually default to 9600.

I did not check and had a quick look at my archived (spec of an HC-05) I bought a while back

Nick_Pyner:
Your Arduino code looks kosher and should not slow things down. I rather suspect using the "case" procedure would be more elegant, but I don't know if it makes any difference to the speed.

I would argue that OP should not empty the incoming buffer and only handle the last character, that's why I was asking if the terminal application is sending also \r or \n after the character --> in which case depending at the speed that data comes in, the while loop would empty the buffer somewhat randomly (don't second guess timing of a asynchronous protocol...) and only from time to time would get the command. I would suggest to have the sequence of if/else within the while loop, or just get rid of the while loop all together since the loop() does that for you

J-M-L:
my archived spec of an HC-05 I bought a while back

Far more important is the actual default rate of the device when it came out of the box, which you don't mention but might check, if possible. There has been a case before where the advised default was not the real default - just something written by a salesman, I guess. Perhaps it was your guy. The required (not default) rate for AT mode is indeed correct - 38400 - and it wouldn't be the first time the two have been confused.

Pardon the hijack

Are you sure your expectations are correct for HC-05? I would try a loopback test, with a serial console on the phone, and see how long it takes for a character to round-trip. I suspect that bluetooth serial may just be too slow for a real-time control application.

Nick_Pyner:
Far more important is the actual default rate of the device when it came out of the box, which you don't mention but might check, if possible. There has been a case before where the advised default was not the real default - just something written by a salesman, I guess. Perhaps it was your guy. The required (not default) rate for AT mode is indeed correct - 38400 - and it wouldn't be the first time the two have been confused.

Yeah - agree to never trust blindly marketing blurbs but in that case my module was actually at 38400 when I got it.

Anyway - not the issue at hand. Would need OP to chime in

J-M-L:
my module was actually at 38400 when I got it.

Thanks. I have published a note on Bluetooth. I will edit it accordingly.

Hello all,

I have been using HC05 modules for at least 5 years. I've bought literally thousands of them for my hexapod project. And I can confirm that there is now a batch of "new" HC05 modules floating around on aliexpress that have this issue. These "new" modules can be identified because the two big chips on the module are not the same width (on prior modules, the two large chips on the front are roughly the same width).

In any case, yes these "new" modules do have a roughly 2 full second time delay when receiving information. (I am not sure whether the delay is happening on the send or the receive).

I asked the vendor for a spec sheet, just in case there's some new magic AT command that needs to be configured to stop this behavior.

I have scoped out some time tomorrow to do experiments with a terminal emulator to see what firmware version these are and see if I can figure it out. Otherwise, I'm going to dispute the order.

So, be careful out there. The new modules are a little cheaper which is why I tried them out. But it's just been a hassle.

-Steve Pendergrast
Vorpal Robotics, LLC
vorpalrobotics.com

It will be interesting to see how you fare with this. I believe this involves both HC-05 and HC-06 which are identified as V3, and this has been going on since 2017. One has to wonder if these have been released onto the marked specifically to cause havoc, and force people to give up and buy BLE devices. I think the goal in any examination would be to figure out how to avoid them, as I believe they re more trouble than they can possibly be worth. If I had to buy another HC-05, I think I would look for one on a JY-MCU board, thereby having some hope that they are old stock.