Hi all
I actually had requested help for my project in which I am using an RF433 remote to control extension and retraction of a lineer actuator through a relay. Unfortunately not quite a bit came out of it. Anyway
So here is my much simplified version of this set up. There are two buttons on my remote: A & B. A is used to move the actuator (both extend & retract) and B is used in urgent moments to stop the actuator. So there is no time limit, no states, whatsoever.
But somehow the relay does not respond to the remote. When I upload the code; the lights of respective lines are switched correctly. Thus no problem about initialization I guess. But I could not figure it out why it doesnt respond. Any help is highly appreciated. Below is my code:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int moveCommand = -7647; // Command value for opening the door
int stopCommand = -7646; // Command value for stopping the door
const int relayOpenPin = 8; // Relay to open the door
const int relayClosePin = 10; // Relay to close the door
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
pinMode(relayOpenPin, OUTPUT);
pinMode(relayClosePin, OUTPUT);
digitalWrite(relayOpenPin,LOW);
digitalWrite(relayClosePin,HIGH);
}
void loop()
{
if (mySwitch.available())
{
int receivedData = mySwitch.getReceivedValue();
mySwitch.resetAvailable();
Serial.println(receivedData);
if (receivedData==moveCommand && relayOpenPin==LOW && relayClosePin==HIGH){
// opening
digitalWrite(relayClosePin,LOW);
digitalWrite(relayOpenPin,HIGH);
}
else if (receivedData==stopCommand && relayOpenPin==HIGH && relayClosePin==LOW) {
// Interrupted opening
digitalWrite(relayOpenPin, HIGH);
digitalWrite(relayClosePin, HIGH);
}
else if (receivedData==moveCommand && relayOpenPin==HIGH && relayClosePin==HIGH) {
// Restart opening
digitalWrite(relayClosePin,LOW);
}
else if (receivedData==moveCommand && relayOpenPin==HIGH && relayClosePin==LOW) {
// Closing
digitalWrite(relayOpenPin,LOW);
digitalWrite(relayClosePin,HIGH);
}
else if (receivedData==stopCommand && relayOpenPin==LOW && relayClosePin==HIGH) {
// Interrupted closing
digitalWrite(relayOpenPin, LOW);
digitalWrite(relayClosePin, LOW);
}
else if (receivedData==moveCommand && relayOpenPin==LOW && relayClosePin==LOW) {
// Restart closing
digitalWrite(relayClosePin, HIGH);
}
}
}