HC-05 not receiving while led is blinking

Hello,

I have come across a problem. I am trying to control some motors using bluetooth, but seem to be unable to receive data while the led on my bluetooth module is blinking. When it is off, all seems well.

What I am using:

  • Arduino uno
  • Adafruit motorshield v1
  • HC-05 BT module
  • 'Arduino Joystick' app on android.

I have connected the RX and TX of the HC-05 to pins 14 and 15 (instead of 0 and 1) since those are available on the shield and it makes programming over usb more convenient. I tested the same setup on pins 0 and 1 with hardware serial, but got the same results.

The app seems to connect. I get 2 longish blinks on the HC-05 led in one second then one second of no blinks. When I send commands in the app I see them coming in instantly if the HC-05 led is off. If the led is blinking, no command comes in, until the 2 blinks are over, after which I receive some delayed data. I am new to using bluetooth in a project, so I am not sure where the problem is. The barebones code I used to test my setup is below.

Thank you

#include <AFMotor.h>
#include <SoftwareSerial.h>

String command = "0";

const int RXpin = 14;
const int TXpin = 15;
SoftwareSerial BTserial(RXpin, TXpin); // RX | TX

//define motors on adafruit motor board
AF_DCMotor motorLB(1, MOTOR12_1KHZ);
AF_DCMotor motorRB(2, MOTOR12_1KHZ);
AF_DCMotor motorLF(4, MOTOR12_1KHZ);
AF_DCMotor motorRF(3, MOTOR12_1KHZ);


void setup() {
  motorLB.setSpeed(200);
  motorLF.setSpeed(200);
  motorRB.setSpeed(200);
  motorRF.setSpeed(200);
  Serial.begin(9600);
  BTserial.begin(9600);
}

void loop() {

        if(BTserial.available()>0){
          command = BTserial.readStringUntil('#');  //App sends: AAASSSN# where A is angle, S is strength and N is button
          Serial.println(command);
          if(command.length()==7){
            
           int angle = command.substring(0,3).toInt();
           int strength = command.substring(3,6).toInt()*2.5;
           int button = command.substring(6,8).toInt();
           Serial.print(angle);
           Serial.print("\t");
           Serial.println(strength);
          


           if((angle < 180) && (strength > 100)){
             StartForward(strength);
           }
           if(strength < 100){
            Stop();
           }
           
           BTserial.flush();
           command="";           
          }      
          
        }//end BTserial

  }// end void loop



void StartForward(int spd){
  motorLB.setSpeed(spd);
  motorLF.setSpeed(spd);
  motorRB.setSpeed(spd);
  motorRF.setSpeed(spd);  
  motorLB.run(FORWARD);     
  motorLF.run(FORWARD);
  motorRB.run(FORWARD);
  motorRF.run(FORWARD);
}

There was a previous thread about a delayed response with an HC05 and it was determined that the module was defective.

https://forum.arduino.cc/t/bluetooth-hc-05-command-delay/916823

Thanks for your response. I need to learn how to use the forum's search function better...
I ordered two modules from the same supplier, both showing the same behaviour. They look exactly the same as the module in the thread you found. Either this supplier is sending out bad modules, or I am breaking them. I have the arduino's 5 V and ground directly on Vcc and GND. TXD goes to RXpin (14) and RXD to TXpin (15).
I will order one from another supplier, see if that solves the problem.

Kind regards.

Hi.
Typical behavior of the HC-05 LED is continuous rapid blinking (edited) when not connected, and two rapid blinks every 5 seconds (edited) when connected. They don't have a LED to indicate data being received or sent.

I haven't come across any info suggesting the LED behavior is somehow connected to or controlling the data transmission, which would not be helpful. It simply indicates that the device is connected to another BT device.

Have you tried using a BT Serial Terminal app to test the comms? Very useful to have on hand when developing a BT based project.

Good luck.

1. There is no visible Pin-14 and Pin-15 on the UNO Board. Are they A0 and A1 respectfully?

2. Check if your BT connection with UNO is similar with the connection scheme of the following diagram.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.