Advertisement
pan7nikt

433_relay_fixed_time

Mar 17th, 2023
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. /*
  2.   Simple example for receiving
  3.  
  4.   https://github.com/sui77/rc-switch/
  5. */
  6.  
  7. #include <RCSwitch.h>
  8.  
  9. #define relayPin D6
  10. #define receiverPin D5
  11.  
  12. bool switchState = false;
  13.  
  14. RCSwitch mySwitch = RCSwitch();
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   pinMode(relayPin,OUTPUT);
  19.   mySwitch.enableReceive(receiverPin);  // Receiver on interrupt 0 => that is pin #2
  20. }
  21.  
  22. void loop() {
  23.   if (mySwitch.available()) {
  24.    
  25.     Serial.print("Received ");
  26.     Serial.print( mySwitch.getReceivedValue() );
  27.     Serial.print(" / ");
  28.     Serial.print( mySwitch.getReceivedBitlength() );
  29.     Serial.print("bit ");
  30.     Serial.print("Protocol: ");
  31.     Serial.println( mySwitch.getReceivedProtocol() );
  32.  
  33.     if(mySwitch.getReceivedValue() == 5852072)
  34.     {
  35.       digitalWrite(relayPin,HIGH);
  36.       Serial.println("Setting relay");
  37.       delay(300);
  38.       digitalWrite(relayPin,LOW);
  39.     }
  40.     delay(500);
  41.     mySwitch.resetAvailable();
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement