Greetings,
I have two Arduino Nano's, two HC05 Bluetooth modules, a button, reed switch, and two breadboards. I have both breadboards set up as follows;
Arduino >> HC-05
GND >> GND
5V >> VCC
D3 >> TX
D2 >> RX
Note: The connection for both of the HC-05 modules is the same.
The Button / Reed Switch
GND >> First pin of the Button
D4 >> Second pin of the Button
Note: The connection for both the button and the reed switch is the same.
Arduino >> LED
GND >> Short Leg
D5 >> Long Leg
Note: The connection for both of the LEDs is the same.
Bidirectional communication is working but when I press the button on the master, or separate the magnets on the slave, the LED's only flicker. The serial monitor shows A's & B's and the LED's seem to flicker at the same rate that the serial monitor is populated.
I'm not very good at coding so I suspect that my code may have something to do with it. I downloaded it from the internet and modified it to suite my needs. I've attached the code below, thanks in advance for your help.
MASTER
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
#define Button 4
#define blueLed 5
#define greenLed 6
#define redLed 7
void setup() {
Serial.begin(38400);
mySerial.begin(38400);
pinMode(Button, INPUT_PULLUP);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}
void loop() {
// Sending
int button = digitalRead(Button);
if(button == HIGH)
{
mySerial.println("a");
}
// Receiving
if (mySerial.available())
Serial.write(mySerial.read());
if (mySerial.read() == 'b')
{
digitalWrite(greenLed, HIGH);
}
else
{
digitalWrite(greenLed, LOW);
}
}
SLAVE
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
#define Button 4
#define blueLed 5
#define greenLed 6
#define redLed 7
void setup()
{
Serial.begin(38400);
mySerial.begin(38400);
pinMode(Button, INPUT_PULLUP);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}
void loop()
{
// Receiving
if (mySerial.available())
Serial.write(mySerial.read());
if (mySerial.read() == 'a')
{
digitalWrite(blueLed, HIGH);
}
else
{
digitalWrite(blueLed, LOW);
}
// Sending
int button = digitalRead(Button);
if (button == LOW)
{
mySerial.println("b");
}
}



