1

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: enter image description 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.

thetaisnew
  • 23
  • 4

0 Answers0