Connecting 2 arduino nano with two HC-05

Hi all,

before getting started, I have to say that I have been checking on the forum for guides and some took me nowhere (link, did not get any reply from AT command) and some were more successful (link, could get into the whole AT configuration, yet seems I could get no connection between modules).

Moreover, I have been checking my cables 1000 times, therefore I am confident when I say my cables are all in the right place :smiley: (hope so)

RXD --> 11
TXD --> 10
GND --> GND
5v

So, let's get to the problem.

I would like to check the connection between two arduino nano over Bluetooth (2x HC-05 modules); using the second guide posted above, I manged to get all the AT command in place and setup the connection between master and slave. I used the following sketch to get this part done:

 //  by Brandon Plumbo AKA Riftliger
//  original version from Martyn Currey http://www.martyncurrey.com/
//  HC-05 universal test sketch to enter AT-commands
//  Uses hardware serial to talk to the host computer and software serial for communication with the bluetooth module
//
//  Pins
//  BT VCC to Arduino 5V out.
//  BT GND to GND
//  Arduino D11 to BT RX
//  Arduino D10 BT TX
//
//  When a command is entered in the serial monitor on the computer
//  the Arduino will relay it to the bluetooth module and display the result.
//
//  The HC-05 modules require both CR and NL

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); //  TX,RX

char c = ' ';
boolean NL = true;

void setup()
{

  Serial.begin(9600);
  Serial.println("Sketch HC-05");
  Serial.println("Arduino with HC-05 is ready");
  Serial.println("Make sure Both NL & CR are set");
  Serial.println("");

  //Set to HC-05 default baud rate, found using AT+UART.  It is usually 38400.
  BTSerial.begin(38400);
  Serial.println("BTserial started at 38400");
  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;
    }
  }
}

The master should send a "1" to the slave, and the slave prints "data ok" when it receive the 1.
However, it seems there is no connection between modules; for the slave module I wrote this code:

#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11);

int state = 0;

void setup() {
  Serial.begin(9600);
  BTserial.begin(38400);
}

void loop() {
    
  if (BTserial.available() > 0) { // Checks whether data is comming from the serial port
    state = BTserial.read(); // Reads the data from the serial port
  }
  
  if (state == '1') {
    Serial.print("data ok"); 
    state = 0;
  }
 
}

For the master, I got this one:

#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); //txd 10, rxd 11
const byte statepin = 2; //checking connection via state pin

void setup() {
 
  pinMode(statepin, INPUT);
  Serial.begin(9600);
  BTserial.begin(38400);
}

void loop() { 
    if (digitalRead(statepin) == HIGH) {Serial.println("OK");}; // check connection
   
     
    BTserial.write('1');  //sends a 1 through the bluetooth serial link
    delay (1000);
}

The problem is that the two modules do not speak to each others.
Therefore, my question is: how I could fix this? Or, more precisely, what am I doing wrong?

Thank you for your help,
CronosVirus00

Ok,

it seems I fixed it.

On the slave module, I gave AT+CMODE= 0 to set it as a slave and now the two modules talks to each others.

Hi i am also trying to connect HC-05 with Arduino nano+HC05(master) and mega+HC05(slave) i am not getting output ,where as when i connected to uno and mega its working fine. I don't know why its happening. Checked loop back test also in nano works fine. Please anyone suggest?