Good Morning All !!
So I'm getting a little closer, I did what @runaway_pancake said and broke the sketch down to bare basics. The communications part of it seems to work fine, however, I can't get the relay to close with a button push from the other side. Let me elaborate.
On the SLAVE device there is a push button. When I press the button I see the "a" populate on the serial monitor of the MASTER device. So it's communicating. When I separate the reed switch on the MASTER device, I see "b" in the serial monitor of the SLAVE device. Everything works except when the MASTER sees the "a" it doesn't close the relay. It's just a 5 volt relay soldered to the PCB.
I tested the relay and it works. If I manually set it to LOW in the sketch it closes just fine. I thought I had it set correctly but apparently I don't. Please take a look at my bare bones sketch as well as the pictures demonstrating communication. Thanks again.
strong textMASTER CODE
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
int Relay = 5;
int GarSwitch = 4;
void setup() {
Serial.begin(115200);
mySerial.begin(38400);
pinMode(GarSwitch, INPUT_PULLUP);
pinMode(Relay, OUTPUT);
}
void loop()
{
// Receiving
if (mySerial.available())
Serial.write(mySerial.read());
if (mySerial.read() == 'a')
{
digitalWrite(Relay, LOW);
}
else
{
digitalWrite(Relay, HIGH);
}
// Sending
int button = digitalRead(GarSwitch);
if (button == HIGH)
{
mySerial.print("b");
}
}
SLAVE CODE
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
#define redLed 7
#define greenLed 6
#define blueLed 5
#define Button 4
#define pwrLed A0
void setup() {
Serial.begin(115200);
mySerial.begin(38400);
pinMode(Button, INPUT_PULLUP);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(pwrLed, OUTPUT);
}
void loop() {
// Sending
int button = digitalRead(Button);
if(button == LOW)
{
mySerial.print('a');
Serial.println('a');
digitalWrite(blueLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
delay(1);
}
else {
digitalWrite(blueLed, LOW);
}
// Receiving
if (mySerial.available())
Serial.write(mySerial.read());
if (mySerial.read() == 'b')
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
delay(25);
}
else
{
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
}
}

