Slow response of Bluetooth module

Thread Starter

Bamerni

Joined Jun 26, 2016
51
Hello everyone

I am trying to connect a simple project of LED blinking using Hiletgo HC-05 wireless Bluetooth module with Arduino Uno

everything is ok, but the response of the LED to the button in my smartphone application sometimes is very slow

what is the reason for this slowness and how can I increase the response

does the application I used affect the speed

below is my code

Code:
#include <SoftwareSerial.h>
SoftwareSerial MyBlue(2, 3); // RX | TX
int flag = 0;
int LED = 8;
void setup()
{  
Serial.begin(9600);
MyBlue.begin(9600);
pinMode(LED, OUTPUT);
Serial.println("Ready to connect\nDefualt password is 1234 or 000");
}
void loop()
{
if (MyBlue.available())
   flag = MyBlue.read();
if (flag == 1)
{
   digitalWrite(LED, HIGH);
   Serial.println("LED On");
}
else if (flag == 0)
{
   digitalWrite(LED, HIGH);
   Serial.println("LED Off");
}
}
and this is my circuit

Untitled.png
 
Last edited:

ericgibbs

Joined Jan 29, 2010
10,018
hi B,
Do you have a laptop that has Bluetooth option, if yes, download the free BT Terminal program into the laptop and then compare the operation of the LED by using the laptop keyboard.
E
 

Attachments

ci139

Joined Jul 11, 2016
1,451
you might include the - say - theState and isDone flags in your code
or just theState one

if your input is HIGH and the theState is low or the inp is LOW and the theState is high you need to alter the LED
otherwise you don't

hovever for proper initialization the isDone is also required if your led is undetermined at initalization e.g. you don't force it high or low ... and thus don't know the status before first BlueTooth input

. . . /!\ the serial print may take time - you either should include it as an buffered/stacked (FIFO) callable software interrupt with special status check and separate service routine ... right now it may stall your system /!\
 
Last edited:
Top