I am trying to make a project with a master and slave HC-05 module. Right now I'm just trying to make sure that it works and is connected properly. I have written this code for the master module:
#include <SoftwareSerial.h>
SoftwareSerial serial(2,3);
void setup() {
// put your setup code here, to run once:
serial.begin(38400);
}
void loop() {
// put your main code here, to run repeatedly:
serial.write('1');
delay(1000);
serial.write('0');
delay(1000);
}
and this for the slave module:
#include <SoftwareSerial.h>
SoftwareSerial serial(2,3);
int led = 8;
int data;
void setup() {
// put your setup code here, to run once:
serial.begin(38400);
pinMode(led, OUTPUT);
}
void loop() {
if (serial.available() > 0) {
data = serial.read();
}
if (data == "1") {
digitalWrite(led, HIGH);
}
else if (data == "0") {
digitalWrite(led, LOW);
}
}
I have been reading the SerialSoftware documentation, and I believe that the master code should simply send a 1, wait a second, send a 0, and then wait a second. And the slave should be receiving this data, turning on the LED, waiting a second, then turning it off. I see the synchronized blinking lights so I believe that my HC-05s are connected, and I paired the successfully. It may be something I did wrong with the wiring? On both of them, RX of the HC-05 is connected to pin 2 and TX is connected to pin 3. And on the slave I simply have pin 8 connected to an led. When I plug in both arduinos and upload the sketches, the LED doesn't do anything. Is there a way I can make sure data is being transmitted? Did I do something wrong in my code to make it not work? Thanks for any help!