Created
March 18, 2016 11:21
-
-
Save embed0/a5f501193dc9d108f51e to your computer and use it in GitHub Desktop.
arduino reciver relay code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
RF_Sniffer | |
Hacked from http://code.google.com/p/rc-switch/ | |
by @justy to provide a handy RF code sniffer | |
*/ | |
#include "RCSwitch.h" | |
#include <stdlib.h> | |
#include <stdio.h> | |
RCSwitch mySwitch = RCSwitch(); | |
int msg; | |
int relayPin = 5; | |
void setup() { | |
Serial.begin(9600); | |
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2 | |
} | |
void loop() { | |
if (mySwitch.available()) | |
{ | |
int value = mySwitch.getReceivedValue(); | |
if (value == 0) { | |
Serial.print("Unknown encoding"); | |
} | |
else | |
{ | |
msg = mySwitch.getReceivedValue(); | |
Serial.println( msg ); | |
if( msg == 1111) | |
{ | |
digitalWrite(relayPin, LOW); | |
} | |
if( msg == 1000) | |
{ | |
digitalWrite(relayPin, HIGH); | |
} | |
msg = 0; | |
} | |
mySwitch.resetAvailable(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment