Two Arduino HC-05 over Software Serial communication not working

I am currently working with 1. Master Hc-05 on Arduino Mega and 2. Slave Hc-05 on Arduino Nano where the Nano is sending integer to the Mega.

I have already configured the AT command such that for the Master HC-05:

AT+ROLE=1
AT+CMODE=0
AT+ADDR= (was set to the address of the slave HC-05) 
AT+UART=38400,0,0

The AT configuration for Slave HC-05:

AT+Role=0
AT+UART=38400,0,0

I am following the schematic here:

Except I have the pin connections as:

RX of mega to digital pin 3 (soft TX) TX of mega to digital pin 2 (soft RX)

and RX of nano to digital pin 3 (soft TX) TX of nano to digital pin 2 (soft RX)

What I am trying to do is send an integer from Nano(slave) to Mega(master) that is parsed through the serial monitor connected to the Nano, and then print the same integer received on the end of Mega's serial monitor. (I have connected Nano to laptop 1 and Mega to another laptop2)

However, the integer parsed in thorugh laptop connected to Nano's serial monitor is printing but none is printing on the Mega side.

It seems like the two Hc-05 are paired and connected as the two are blinking twice every 2 seconds at the same rate, but they are not receiving any messages on Bluetooth serial?

The code for Nano (Slave / Transmitter):

#include<SoftwareSerial.h>
#define softrx 2
#define softtx3
SoftwareSerial BTSerial(softrx, softtx);

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

void loop(){
  while(Serial.available()){
     int data = Serial.parseInt();  //reads the data sent through serial monitor 
     BTSerial.write(data);  //send the number to the Master Hc-05
     Serial.println(); // print the number sent through the serial monitor 
   }
}

The code for Mega (Master / Receiver)

#include <SoftwareSerial.h>

#define softrx 2
#define softtx 3
SoftwareSerial BTSerial(softrx, softtx); // RX | TX

void setup() {
  
  BTSerial.begin(38400);
  Serial.begin(9600);

}

void loop() {
  if (BTSerial.available()>0)
  {
    char data = BTSerial.read();
    Serial.println(data);
  }
}

These are just my setup and ultimately I want to connect flex sensors on Nano which sends integer based on sensor data to activate LED connected to mega.

But this simple thing is not even working and I want to know what I am doing wrong here.

Tried connecting tx of the microcontroller to tx of HC-05 but did not work either.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

Communicating @ 38400 under software serial is as risky as it is pointless. It may be OK but, in the light of your current lack of success, it would be smart to revert to 9600. There is nothing in your code that suggests you need the (ahem!) speed, indeed quite the opposite.

It looks like you are following Martyn Currey's notes, so you should be fine if you do so rigorously. That would not include connecting tx of the microcontroller to tx of HC-05.

Hi, thank you for the response. I tried setting the AT+UART to 9600 and running at that baud rate but still no success :frowning:

  1. Make sure you have the comms wiring correct Rx-Tx and Tx-Rx.

  2. Also try the Nano with an Android device - just to isolate any problem.

I used the instructions from this page to get my 2 HC05 modules to connect >> https://howtomechatronics.com/tutorials/arduino/how-to-configure-pair-two-hc-05-bluetooth-module-master-slave-commands/

It may be a distraction, but why are you using software serial on a Mega? It has four hardware serial ports.
Software serial is a necessary evil with a Nano or Uno, granted.

so i can use serial monitor and also bluetooth serial.
if i dont use software ssrial how do I send stuff on serial monitor?

thats what i used too :frowning:

and when i declare rx and tx in the code i declare the software serial (rx tx) which is rx connected to tx of bluetooth and vice versa right? if so the wiring is correct

The monitor is on "serial" in the usual manner. Bluetooth is on Serial1, pins 18 19 as clearly marked. Change all your software serial commands accordingly.

Your post #10 reads right.

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