0
votes

I've been trying to connect two HC-05 bluetooth modules together as master and slave devices. I know that to do this i need to establish one as a slave device and one as a master using the AT command mode. I am using an arduino nano with each of the modules and the circuit i have used is shown:

Vcc -----> 5V

GND ----> GND

Rx ------> Rx

Tx ------> Tx

I followed various online tutorials and have used this code:

include SoftwareSerial.h

SoftwareSerial BTSerial(0, 1); // RX | TX

    void setup()
    {
    
      Serial.begin(9600);
    
      BTSerial.begin(9600);  // HC-05 default speed in AT command more
    
      Serial.println("Enter AT commands:");
    
    }
    
    void loop()
    {
     
      // Keep reading from HC-05 and send to Arduino Serial Monitor
      if (BTSerial.available()){
    
        Serial.write(BTSerial.read());
    
      }
    
      // Keep reading from Arduino Serial Monitor and send to HC-05
    
      if (Serial.available()){
    
        BTSerial.write(Serial.read());
    
      }
    
    } 

Using the button on the module or by setting the EN pin high, i am able to put the module into AT mode as displayed by the LED blinking every 2 seconds. However, i receive no response after sending commands to the module using the serial monitor when i should receive a confirmation of my command.

Any ideas where i'm going wrong?

1
UART connection 101: Tx --> Rx, Rx --> Tx.hcheung
I have tried the wires both ways round and using various different sets of pins with no success. ThanksShawn Poile

1 Answers

0
votes

Here's the solution that eventually worked for me: I used this circuit with a voltage divider:

  • Vcc -----> 5V
  • GND ----> GND
  • D2 ------> Tx
  • D3 ------> Rx

I ended up having to buy an Uno for this to work, I'm assuming then that my Nano's were faulty in some way. I then used the following code:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2, 3); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
  Serial.println("Enter AT commands:");
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available()){
    Serial.write(BTSerial.read());
  }

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available()){
    BTSerial.write(Serial.read());
  }
}

This allowed me to enter the AT mode and also receive responses.

One of the issues was that I was using the Tx and Rx pins which are also used to communicate with the computer so cannot be used with the HC-05 at the same time.

Another issue was the baudrate: I alternated between 9600 and 38400 for each communication until I found a combination that worked, and adjusted the speed in the Serial monitor so that it made sense.

Then I was able to use the command mode normally.