Here is the final code for the slave module, in case anyone is interested. The circuits are as shown in the most recent picture.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
const int button = 8;
int buttonState = 0;
int prevState = 0;
void setup()
{
pinMode(button, INPUT_PULLUP);
// Set data rate for the serial monitor:
Serial.begin(9600);
delay(5);
// set the data rate for the SoftwareSerial port to match the UART baud on HC05
mySerial.begin(38400);
delay(5);
}
void loop()
{
// Reading the button
buttonState = digitalRead(button);// becomes LOW when button is pushed
delay(10);
if (buttonState != prevState) // if button has been pushed or released
{
if(buttonState == LOW)
{
mySerial.write('1'); // Sends '1' to the master to turn on LED
prevState = LOW;
delay(5);
}
else if (buttonState == HIGH)
{
mySerial.write('0');
prevState = HIGH;
delay(5);
}
}
}