Hello everyone! I am currently working on a project where I have to communicate wireless wherein the Arduino Nano and Arduino Mega can send as well as receive at the same time (Both is in Master & Slave Mode).
I connected two(2) HC-05 Bluetooth modules in my Arduino Nano and two(2) HC-05 Bluetooth modules in Arduino Mega. I did this to so that I can communicate in two-way, however, even if I bound the Bluetooth:
Bluetooth module A(Master) > Bluetooth module B(Slave)
Bluetooth module C (Slave)>Bluetooth module D (Master)
they do not seem to communicate in two-way. If I only use one pair of bluetooth modules I can transmit/ receive data, however, when I use two pairs they do not communicate.
I would like to ask for help.
Thanks!
This is not exactly the code, but it operates like this:
For Nano:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial1(A0,A1);
SoftwareSerial BTSerial1(A2,A3);
int state = 0;
void setup() {
Serial.begin(9600);
BTSerial1.begin(38400);
BTSerial2.begin(38400);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (BTSerial1.available() > 0) {
state = BTSerial1.read();
}
if (state == '1') {
digitalWrite(LED_BUILTIN, HIGH);
BTSerial2.write('1');
Serial.println(state);
state = 0;
}
else if (state == '2'){
digitalWrite(LED_BUILTIN, LOW);
BTSerial2.write('0');
Serial.println(state);
state = 0;
}
}
For Mega:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial1(10,11);
SoftwareSerial BTSerial1(12,13);
int state2 = 0;
void setup() {
Serial.begin(9600);
BTSerial1.begin(38400);
BTSerial2.begin(38400);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (BTSerial2.available() > 0) {
state2 = BTSerial2.read();
}
BTSerial.write('1');
if (state2 == '1') {
digitalWrite(LED_BUILTIN, HIGH);
state2 = 0;
}
delay(2000);
BTSerial.write('2');
if (state2 == '0') {
digitalWrite(LED_BUILTIN, LOW);
state = 0;
}
delay(2000);
}