IR Remote Controlled Home Automation System





Code:-



#include <IRremote.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 7, 6, 5, 4, 3);

int RECV_PIN = 2;



IRrecv irrecv(RECV_PIN);



decode_results results;

const int Relay1=13;

const int Relay2=12;

const int Relay3=11;

const int Relay4=10;

void setup()

{

  lcd.begin(16, 2);

  lcd.print("L1  L2  L3  L4 ");

  lcd.setCursor(0, 1);

    lcd.print("OFF OFF OFF OFF ");

  Serial.begin(9600);

  Serial.println("Enabling IRin");

  irrecv.enableIRIn(); 

  Serial.println("Enabled IRin");

  pinMode(Relay1,OUTPUT);

  pinMode(Relay2,OUTPUT);

  pinMode(Relay3,OUTPUT);

  pinMode(Relay4,OUTPUT); 

  digitalWrite(Relay1,LOW);

  digitalWrite(Relay2,LOW);

  digitalWrite(Relay3,LOW);

  digitalWrite(Relay4,LOW);

}



void loop() {

  if (irrecv.decode(&results)) {

    Serial.println(results.value, HEX);

    irrecv.resume(); 

  }

  delay(100);

  switch(results.value)

  {

    case 0x1FE50AF:

    digitalWrite(Relay1,HIGH);

    lcd.setCursor(0, 1);

    lcd.print("ON ");

    break;

    case 0x1FED827:

    digitalWrite(Relay1,LOW);

    lcd.setCursor(0, 1);

    lcd.print("OFF");

    break;

    case 0x1FEF807:

    digitalWrite(Relay2,HIGH);

    lcd.setCursor(4, 1);

    lcd.print("ON ");

    break;

    case 0x1FE30CF:

    digitalWrite(Relay2,LOW);

    lcd.setCursor(4, 1);

    lcd.print("OFF");

    break;

    case 0x1FEB04F:

    digitalWrite(Relay3,HIGH);

    lcd.setCursor(8, 1);

    lcd.print("ON ");

    break;

    case 0x1FE708F:

    digitalWrite(Relay3,LOW);

    lcd.setCursor(8, 1);

    lcd.print("OFF");

    break;

    case 0x1FEF00F:

    digitalWrite(Relay4,HIGH);

    lcd.setCursor(12, 1);

    lcd.print("ON ");

    break;

    case 0x1FE9867:

    digitalWrite(Relay4,LOW);

    lcd.setCursor(12, 1);

    lcd.print("OFF");

    break;

  }

}


Comments