2021-05-03 20:40:50 +02:00
|
|
|
#include <RCSwitch.h>
|
|
|
|
|
|
|
|
RCSwitch mySwitch = RCSwitch();
|
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
// defining used pins
|
2021-05-03 20:40:50 +02:00
|
|
|
int wind = 8;
|
|
|
|
int receiver = 9;
|
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
int relay1 = 7;
|
|
|
|
int relay2 = 6;
|
|
|
|
int relay3 = 5;
|
|
|
|
int relay4 = 4;
|
2021-05-03 20:40:50 +02:00
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
// codes from remote controller
|
|
|
|
const int recRelay4 = 16736114;
|
|
|
|
const int recRelay3 = 16736120;
|
|
|
|
const int recRelay2 = 3696136;
|
|
|
|
const int recRelay1 = 16736113;
|
2021-05-03 20:40:50 +02:00
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
int delayTime = 2000;
|
2021-05-03 20:40:50 +02:00
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
void setup()
|
|
|
|
{
|
2021-05-03 20:40:50 +02:00
|
|
|
Serial.begin(9600);
|
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
pinMode(relay1, OUTPUT);
|
|
|
|
pinMode(relay2, OUTPUT);
|
|
|
|
pinMode(relay3, OUTPUT);
|
|
|
|
pinMode(relay4, OUTPUT);
|
|
|
|
pinMode(wind, INPUT);
|
2021-05-03 20:40:50 +02:00
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
|
2021-05-03 20:40:50 +02:00
|
|
|
}
|
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
void relayOn(int pin)
|
2021-05-03 20:40:50 +02:00
|
|
|
{
|
2021-05-22 15:06:38 +02:00
|
|
|
Serial.println("realy " + pin);
|
|
|
|
|
2021-05-03 20:40:50 +02:00
|
|
|
digitalWrite(pin, HIGH);
|
|
|
|
delay(delayTime);
|
|
|
|
digitalWrite(pin, LOW);
|
2021-05-22 15:06:38 +02:00
|
|
|
|
|
|
|
delay(delayTime);
|
2021-05-03 20:40:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2021-05-22 15:06:38 +02:00
|
|
|
// wind actions
|
|
|
|
if (digitalRead(wind) == HIGH)
|
2021-05-03 20:40:50 +02:00
|
|
|
{
|
2021-05-22 15:06:38 +02:00
|
|
|
digitalWrite(relay1, HIGH);
|
2021-05-03 20:40:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-22 15:06:38 +02:00
|
|
|
digitalWrite(relay1, LOW);
|
2021-05-03 20:40:50 +02:00
|
|
|
}
|
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
// remote controller actions
|
2021-05-03 20:40:50 +02:00
|
|
|
if (mySwitch.available())
|
|
|
|
{
|
2021-05-22 15:06:38 +02:00
|
|
|
int received = mySwitch.getReceivedValue();
|
|
|
|
Serial.println("Received " + received);
|
2021-05-03 20:40:50 +02:00
|
|
|
|
2021-05-22 15:06:38 +02:00
|
|
|
if (received == recRelay1)
|
|
|
|
{
|
|
|
|
relayOn(relay1);
|
|
|
|
}
|
|
|
|
if (received == recRelay2)
|
2021-05-03 20:40:50 +02:00
|
|
|
{
|
2021-05-22 15:06:38 +02:00
|
|
|
relayOn(relay2);
|
|
|
|
}
|
|
|
|
if (received == recRelay3)
|
|
|
|
{
|
|
|
|
relayOn(relay3);
|
|
|
|
}
|
|
|
|
if (received == recRelay4)
|
|
|
|
{
|
|
|
|
relayOn(relay4);
|
2021-05-03 20:40:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mySwitch.resetAvailable();
|
|
|
|
}
|
2021-05-22 15:06:38 +02:00
|
|
|
}
|