Skip to content

Instantly share code, notes, and snippets.

@hassaananjum
Created February 13, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassaananjum/4c84f1207e3bd5cff36a89d039cdefc9 to your computer and use it in GitHub Desktop.
Save hassaananjum/4c84f1207e3bd5cff36a89d039cdefc9 to your computer and use it in GitHub Desktop.
RF Control Code Arduino
#include <RCSwitch.h>
#include <stdlib.h>
#include <stdio.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Setup");
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
mySwitch.enableReceive(0);
digitalWrite(4,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(12,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(11,HIGH);
if (mySwitch.available()) {
Serial.println("available");
int value = mySwitch.getReceivedValue();
Serial.print(value);
if (value == 0) {
Serial.print("Unknown encoding");
} else {
if(value == 110){
Serial.print("Received off");
digitalWrite(4,HIGH);
blinkLight(13,1);
}
else if(value == 111){
Serial.print("Received on");
digitalWrite(4,LOW);
blinkLight(13,3);
}
else if(value == 120){
Serial.print("Received off");
digitalWrite(7,HIGH);
blinkLight(13,1);
}
else if(value == 121){
Serial.print("Received on");
digitalWrite(7,LOW);
blinkLight(13,3);
}
else if(value == 130){
Serial.print("Received off");
digitalWrite(8,HIGH);
blinkLight(13,1);
}
else if(value == 131){
Serial.print("Received on");
digitalWrite(8,LOW);
blinkLight(13,3);
}
else if(value == 140){
Serial.print("Received off");
digitalWrite(12,HIGH);
blinkLight(13,1);
}
else if(value == 141){
Serial.print("Received on");
digitalWrite(12,LOW);
blinkLight(13,3);
}
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
mySwitch.resetAvailable();
}
else{
//Serial.println("no signal");
}
}
void blinkLight(int pin, int t){
for(int i = 0; i < t; i++){
digitalWrite(pin,HIGH);
delay(50);
digitalWrite(pin,LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment