I have come up with this but the relay will only switch on. I need to somehow store the value or something of the relay pin which is an output.
All I want to do is press the button and have it toggle the relay either on or off depending on it's current state!
#include <RCSwitch.h>
#define RELAY1 5
int val = 0;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
pinMode(RELAY1, OUTPUT);
mySwitch.enableReceive(0);
}
void loop() {
if (mySwitch.available()) {
unsigned long value = mySwitch.getReceivedValue();
if (value == 5592323UL) {
digitalRead(RELAY1);
if (val == LOW) {
digitalWrite(RELAY1, HIGH);
}else{
digitalRead(RELAY1);
if (val == HIGH) {
digitalWrite(RELAY1, LOW);
}
mySwitch.resetAvailable();
}
}
}
}