Automation using IR Remote
* Code *
#include <IRremote.h>
#define irPin 9
IRrecv irrecv(irPin);
decode_results results;
#define r1 13
int relay1 = LOW;
#define r2 12
int relay2 = LOW;
#define r3 11
int relay3 = LOW;
#define r4 10
int relay4 = LOW;
#define r5 8
int relay5 = LOW;
void setup()
{
irrecv.enableIRIn();
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(r4, OUTPUT);
pinMode(r5, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
switch (results.value) {
case 16580863:
digitalWrite(r1,0);
digitalWrite(r2,0); //all off
digitalWrite(r3,0);
digitalWrite(r4,0);
digitalWrite(r5,0);
delay(250);
break;
case 16582903:
relay1 = ~ relay1;
digitalWrite(r1,relay1);
delay(250);
break;
case 16615543 :
relay2 = ~ relay2;
digitalWrite(r2,relay2);
delay(250);
break;
case 16599223 :
relay3 = ~ relay3;
digitalWrite(r3,relay3);
delay(250);
break;
case 16591063:
relay4 = ~ relay4;
digitalWrite(r4,relay4);
delay(250);
break;
case 16623703:
relay5 = ~ relay5;
digitalWrite(r5,relay5);
delay(250);
break;
}
irrecv.resume();
}
}
Comments
Post a Comment