HC-05 issues with connection

Hi all! Every time i set the role, it reverts back. As you can tell in the terminal output. I have two HC-05 modules, and both of them do this, i've tried on 3 separate micro controllers. Nano, Nano and Uno R3. Also, my address changes for my slave device, when im trying to "AT+BIND" on the master module. as you can see in the terminal output as well. Did i happen to get 2 faulty modules? Of what am i doing wrong? Thanks to anybody who can give me a hand with this!
I have the HC-05 ZS-040,
Here is also my Code

PINS:
RX>RX(3)
TX>TX(2)
Gr > GR (With 1K and 2.2K Resistor between ground and RX)
Vcc>5V

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX

const long baudRate = 38400;
char c = ' ';
boolean NL = true;

void setup()
{
   Serial.begin(38400);
   Serial.print("Sketch:   ");   Serial.println(__FILE__);
   Serial.print("Uploaded: ");   Serial.println(__DATE__);
   Serial.println(" ");

   BTserial.begin(baudRate);
   Serial.print("BTserial started at "); 
   Serial.println(baudRate);
   //BTserial.print("BTserial started at "); 
   //BTserial.println(baudRate);
   Serial.println(" ");
}

void loop()
{
   // Read from the Bluetooth module and send to the Arduino Serial Monitor
   if (BTserial.available())
   {
      c = BTserial.read();
      Serial.write(c);
   }

   // Read from the Serial Monitor and send to the Bluetooth module
   if (Serial.available())
   {
      c = Serial.read();
      BTserial.write(c);

      // Echo the user input to the main window. The ">" character indicates the user entered text.
      if (NL)
      {
         Serial.print(">");
         NL = false;
      }
      Serial.write(c);
      if (c == 10)
      {
         NL = true;
      }
   }
}
BTserial started at 38400
 
>AT
OK
>AT
OK
>AT+UART?
+UART=9600,0,0
OK
>AT+UART=38400,0,0
OK
>AT+UART?
+UART=38400,0,0
OK
>AT+ROLE?
+ROLE:0
OK
>AT+ROLE=1
OK
>AT+CMODE=0
OK
>AT+ROLE?
OK
+ROLE: 0        /// Supposed to be ROLE: 1
OK
>AT+BIND=****,**,020e06
OK
>AT+BIND?
+BIND:****:**:020e26  /// 0 changes to a 2
OK

Re you trying to do Master-Slave operation? Can you do the data exchange? What is your exact problem?

Yes, master slave - operation. I cant set my "Master" as master, as in When i set At+ROLE=1 (Master) it reverts back to ROLE: 0 (Slave) after i type in AT+ROLE?
As you can see here (The Terminal)

>AT+ROLE?
+ROLE:0
OK
>AT+ROLE=1
OK
>AT+CMODE=0
OK
>AT+ROLE?
OK
+ROLE: 0

1. Which Arduino you are using with Master-BT and which one with Slave-BT?
2. You may try the following Tutorial.


Figure-1: Hardware setup for Master/Slave operation of Bluetooth Modules

(1) Check that your hardware setup agrees with the setup of Fig-1.
(2) Configure your Slave-BT of UNO-2 by carrying out the following steps:
(a) Bring Slave-BT into AT Mode.
(b) Upload following sketch into Slave-UNO-2 of Fig-1. Save sketch as E1232.


#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX at UNO = 10, STX = 11

void setup()
{
  Serial.begin(9600);
  SUART.begin(38400);   //AT command Baud Rate
}

void loop()
{
  if (SUART.available())
  {
    char x = SUART.read();
    Serial.print(x);
  }

  if (Serial.available())
  {
    char c = Serial.read();
    SUART.print(c);
  }
}

(c) Open Serial Monitor (SM) of UNO-2 with BD = 9600 along with "Both NL & CR" option for the Line ending Tab.

(d) Enter AT+RMAAD? (To clear any paired devices) in the InputBox of SM and then click on Send Button. The BT will respond with OK message.

(e) Send AT+ROLE=0 (To set it as Slave) command to BT. The respond should be OK.

(f) Send AT+ADDR? (To get the address of Slave-BT. Note down that this address will be used during Master’s Configuration). For my BT, it is: 21:13:A36B as is shown below. (It will be entered as: 21,11,A36B during Master configuration; where, the colons are replaced by comma.)

+ADDR:21:13:A36B
OK

(g) Send AT+PSWD? Command to Slave-BT to know PIN/Password of Slave which must be same as Master; otherwise no pairing will occur.

(h) Send AT+CMODE=1 (Slave connect mode) command to Slave-BT.

(3) Configure your Master-BT of UNO-1 by carrying out the following steps
(a) Bring Master-BT into AT Command Mode.
(b) Upload the following sketch into UNO-1. Save the Sketch as E1233.


#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX at UNO = 10, STX = 11

void setup()
{
  Serial.begin(9600);
  SUART.begin(38400);   //AT command Baud Rate
}

void loop()
{
  if (SUART.available())
  {
    char x = SUART.read();
    Serial.print(x);
  }

  if (Serial.available())
  {
    char c = Serial.read();
    SUART.print(c);
  }
}

(b) Send AT+RMAAD? Command to Master-BT
(c) Send AT+ROLE=1 (To set it as Master) command to Master-BT.
(d) Send AT+PSWD=1234 command to Master-BT (should be same as Slave).
(e) Send AT+CMODE=0 (Master connect mode).
(f) Send AT+BIND=21,11,A36B command to Master-BT (the Slave address found in Section-2(f)); the colons (: ) are replaced by commas (,)).

(4) Remove 3.3V and 5V connections from both Master-BT and Slave-BT.
(5) Connect the 5V supplies to both BTs.
(6) Check that the BTs have been paired. The Red LEDs of both BTs blink once a while.
(7) Checking communication between UNO-1 and UNO-2 via BTs
(a) Upload the following Sketch in UNO-1. Save the sketch as E1237a.


#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX at UNO = 10, STX = 11
#define Ledbut 3

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
  pinMode(Ledbut, INPUT_PULLUP);
}

void loop()
{
  if (digitalRead(Ledbut) == LOW)
  {
    SUART.print('L');
  }
  delay(500);
}

(b) Upload the following sketch in UNO-2. Save the sketch as E1237b.

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX at UNO = 10, STX = 11
#define blueLed 13
void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
  pinMode(blueLed, OUTPUT);

}

void loop()
{
  if (SUART.available())
  {
    char x = SUART.read();
    if (x == 'L')
    {
      digitalWrite(blueLed, HIGH);
      delay(200);
      digitalWrite(blueLed, LOW);
      delay(200);
      Serial.println("Message received from Master.");
    }
  }
}

(c) Open SM of UNO-2 with Bd = 9600.
(d) Press and release Ledbut switch at Master side.
(e) Check that the blueLed at Slave/UNO-2 side just flashes once.
(f) Check that the SM of UNO-2 shows the following message.

Message received from Master.

I was using Nano for master, and Uno for slave. I switched them around and tried that way. Same thing. I also switched the HC-05 modules around, same thing. Its not allowing me to to set one as master

I have given you a tested Tutorial in post #4 which you may try. Please, follow every step as outlined and marked checked when done.

My bad. Didnt see that for some reason. Will give it ago now. Thanks you

The fact that you can confirm the baud rate suggests that your code and wiring are OK but the HC-05s could be suss. There are dud ones around that work just fine until you start configuring them. There is a faint possibility that that can be fixed by putting 3.3v on pin 34, rather than just relying on the button. Check the Martyn Currey website.

Tried, there still not connecting, imma just go ahead and buy 2 new HC-05 Modules, i've been trying to get these working for 4 days to long now lol Thanks for your help.

Im suspecting there duds, i've tried every single tutorial out there, and nothing has worked haha

Just apply power to a BT-05 and check that it is paired with the BT of your Android Phone.

It pairs with my phone properly, it doesn't pair up with the other bluetooth module though unfortunately.

There are standard Trouble Shooting Guide whose all steps are to be completed in sequence and only then the faulty part/component could be detected, isolated, and corrected.
1. Is your BT-1 paired with Android Phone. If yes, then it is a Slave.
2. Can you exchange data between this Slave BT-1 and Android Phone?
3. If Step-2 is true, then configure BT-1 as Master using AT-command. Check that it not paired with Android Phone. Get its Serial/Pin Number using AT-Command.

4. Please, report your above findings.

It connected to my Android PHone, i downloaded a BlueTooth terminal app, so i can send messages between my module(Arduino Serial monitor) and my phone(Vice versa as well) Unfortunately, im not receiving the messages i get though. And i cant get the Bluetooth to be set as Master. My address gets mixed up as well, and my ROLE Does not save.
It reverts back to ROLE: 0

BTserial started at 38400
 
>AT
OK
>AT
OK
>AT+UART?
+UART=9600,0,0
OK
>AT+UART=38400,0,0
OK
>AT+UART?
+UART=38400,0,0
OK
>AT+ROLE?
+ROLE:0
OK
>AT+ROLE=1
OK
>AT+CMODE=0
OK
>AT+ROLE?
OK
+ROLE: 0        /// Supposed to be ROLE: 1
OK
>AT+BIND=****,**,020e06
OK
>AT+BIND?
+BIND:****:**:020e26  /// 0 changes to a 2
OK

Gibberish

Reconcile SoftwareSerial with your description / explanation.

R goes to T on the other side
T goes to R on the other side

Tried that already, about couple days ago. I've switched the rx & tx, reset the modules, i've connected everything about 10 times now, added the resistor between ground and RX, i've tried different code. I've adjusted the code. Turned em' off & now, still can't get them to connect to eachother. So im kinda lost now with it lol

Get two new BT-05 and try the Tutorial of post #4.

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