IR remote controlled home automation using arduino | IR remote decoder u...







code:-



#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <IRremote.h>

int RECV_PIN = 7;

IRrecv irrecv(RECV_PIN);

decode_results results;

LiquidCrystal_I2C lcd(0x27, 16, 2);

String ON="ON ";

String OFF="OFF";

int i=0,j=0,k=0,l=0;

char LD1=0;char LD2=0;char LD3=0;char LD4=0;

void setup()

{

  pinMode(10,OUTPUT);

  pinMode(11,OUTPUT);

  pinMode(12,OUTPUT);

  pinMode(13,OUTPUT);

  digitalWrite(10,LOW);

  digitalWrite(11,LOW);

  digitalWrite(12,LOW);

  digitalWrite(13,LOW);

  lcd.begin();

  lcd.backlight();

  lcd.setCursor(0, 0);

  lcd.print("IR Remote BaSeD");

  lcd.setCursor(0, 1);

  lcd.print("HoMe AuToMaTiOn ");

  delay(2000);

  lcd.clear();

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

  Serial.begin(9600);

  irrecv.enableIRIn();

}



void loop()

{

  if (irrecv.decode(&results)) {

    Serial.println(results.value, HEX);

    automation(results.value);

    irrecv.resume(); 

  }

  delay(100);

}

void automation(unsigned long int val)

{

  switch(val)

  {



  case 0x4FB12ED :

  lcd.setCursor(0,1);

  digitalWrite(13,LD1=!LD1);

  i=i+1;

  i=i%2;

  if(i==1)

  lcd.print(ON);

  else

  lcd.print(OFF);

  break;case 0x4FBF00F :

  lcd.setCursor(4,1);

  digitalWrite(12,LD2=!LD2);

  j=j+1;

  j=j%2;

  if(j==1)

  lcd.print(ON);

  else

  lcd.print(OFF);

  break;

  case 0x4FB22DD :

  lcd.setCursor(8,1);

  digitalWrite(11,LD3=!LD3);

  k=k+1;

  k=k%2;

  if(k==1)

  lcd.print(ON);

  else

  lcd.print(OFF);

  break;

  case 0x4FBD02F :

  lcd.setCursor(12,1);

  digitalWrite(10,LD4=!LD4);

  l=l+1;

  l=l%2;

  if(l==1)

  lcd.print(ON);

  else

  lcd.print(OFF);

  break;

  case 0x4FB32CD :

  lcd.setCursor(0,1);

  digitalWrite(10,LOW);

  digitalWrite(11,LOW);

  digitalWrite(12,LOW);

  digitalWrite(13,LOW);

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

  break;

  }

}

Comments