HC-05 bluetooth module - High latency

Hi,
I'm trying to communicate via bluetooth between Android and Mega2560 with HC-05. I read that it's possible to achieve latency under 500ms but even though I try to change baudrate of bluetooth module I still can't get under 1.5 sec. :frowning:

Is it possible that this latency cause Android app?

Code of my Arduino:

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(53, 52);

void setup()
{
  pinMode(40, OUTPUT);
  bluetooth.begin(115200);
}

void loop() 
{
  if(bluetooth.available())
  {
    int value = bluetooth.readString().toInt(); 
    if(value == 1)
    {
      digitalWrite(40, HIGH);
    }
    else if(value == 0)
    {
      digitalWrite(40, LOW);
    }
  }
}

I hesitate to answer this because

  1. I have no idea what latency is
  2. This

Is it possible that this latency cause Android app?

is incoherent, and what Android app?
But I would point out that this  bluetooth.begin(115200);is a really bad idea, and may even be the cause of your problem, whatever that might be. It is particularly dumb when you aren't using hardware serial at all. If you must use such a high speed, put bluetooth on pins 0,1 and do it with hardware serial, otherwise stay with software serial and change the baud rate to a maximum 38400.

Hi Nick,
Thanks for your response and sorry for my English :slight_smile:

With latency I mean delay between sending command from smartphone to writing HIGH/LOW to digital pin on Arduino. I don't need to transfer big data all I want is to have the lowest possible delay between these two actions.

To sending data from smartphone I use some of bluetooth terminal apps like this: https://play.google.com/store/apps/details?id=project.bluetoothterminal

About 115200 baudrate, I also try to change it to 4800, 9600 and 38400, but I didn't notice any change.
As well there wasn't any progress after changing SoftwareSerial(53,52) to Serial1 on pins 18,19.

Maybe it can´t be helped, after all it's very cheap module.

OK, 1.5 sec seems a long time to do anything. I'm surprised to hear that you can get a delay that long. I have never noticed anything like that - maybe because I have never looked. It appears that you are only sending a single character for data, so I guess any change in speed would be un-noticable. It may also be the reason why you appear to get a result using software serial at that speed. If that is indeed the case, don't expect to get a result when you send anything more than that. That speed is the kiss of death with software serial.

I also now understand that you are using software serial in a Mega, which is about the dumbest thing you can do in the Arduino world. I bet you haven't got a good reason to do that in the face of four hardware serial ports being available to you, and it is definitely not the sort of thing to show to your mother.

I suppose it is possible that the problem is at the Android end but, again, I have never noticed. There is one Android terminal that cannot log data. If the writer couldn't get that right, I imagine he would be the one that gives you high latency too, and it would be a good idea to replace it.