Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Naman Chauhan
Published © GPL3+

Arduino: Switching ON/OFF Appliances Using IR Remote

Press 'Power' to switch everything ON/OFF. Press '1' for the fan and '2' for the lights.

BeginnerShowcase (no instructions)2.5 hours33,838
Arduino: Switching ON/OFF Appliances Using IR Remote

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
IR receiver (generic)
×1
IR Remote Control
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Resistor 221 ohm
Resistor 221 ohm
×1
SPDT 5V Relay
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Schematics

Autodesk 123 Circuits Schematics

https://circuits.io/circuits/5252611-arduino-switching-on-off-appliances-using-ir-remote/edit#breadboard

Code

Arduino | Switching ON/OFF appliances using IR Remote

C/C++
#include <IRremote.h>      //including infrared remote header file
#include <LiquidCrystal.h>    //including LCD header file

#define code1  16582903   // code received from button 1
#define code2  16615543   // code received from button 2
#define code3  16580863   // code received from "power button"

LiquidCrystal lcd(12,10,7,6,5,4);

int RECV_PIN = 11;        // the pin where you connect the output pin of IR sensor 
IRrecv irrecv(RECV_PIN);
decode_results results;

int app1 = 3;         //fan pin
int app2 = 2;         //bulb pin
int status[] = {0,0,0,0};
/* the initial state of appliances is OFF (zero) 
the first zero must remain zero but you can 
change the others to 1's if you want a certain
appliance to be ON when the board is powered */
 
void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);          // Start the LCD
  irrecv.enableIRIn();        // Start the IR receiver
  
  pinMode(app1, OUTPUT);
  pinMode(app2, OUTPUT);
  
  lcd.setCursor(0,0);     
  lcd.print("Made by Naman");   // Made by Naman Chauhan
  lcd.setCursor(0,1);
  lcd.print("Chauhan");
  delay(1500);
  lcd.clear();
  
  lcd.setCursor(3,0);
  lcd.print("Arduino IR");      //Arduino IR Switch Board
  lcd.setCursor(2,1);
  lcd.print("Switch Board");
  delay(1500);
  lcd.clear();
  
  lcd.setCursor(0,0);
  lcd.print("(1) Fan : OFF");     //Showing intial status on LCD
  lcd.setCursor(0,1);
  lcd.print("(2) Bulb : OFF");
  
}
 
void loop() 
{
  if (irrecv.decode(&results)) {
    unsigned int value = results.value;
    switch(value) {
      
       case code1:
         if(status[1] == 1) {           // if first app is ON then
            digitalWrite(app1, LOW);      // turn it off when button is pressed
            status[1] = 0;              // and set its state as off
            lcd.setCursor(10,0);      //printing status on LCD
            lcd.print("OFF");
          }
      
        else {                          // else if first app is OFF then
              digitalWrite(app1, HIGH);   // turn it on when the button is pressed
              status[1] = 1;            // and set its state as ON
              lcd.setCursor(10,0);    //printing status on LCD
              lcd.print("ON ");
           }
              break;
      
      
       case code2:
         if(status[2] == 1) {
            digitalWrite(app2, LOW);
            status[2] = 0;
            lcd.setCursor(11,1);      //printing status on LCD
            lcd.print("OFF");
         } 
      
        else {
              digitalWrite(app2, HIGH);
              status[2] = 1;
              lcd.setCursor(11,1);      //printing status on LCD
              lcd.print("ON ");
           }
              break;
              
       case code3:
         if(status[1] == 1 && status[2] == 1) {
            digitalWrite(app1, LOW);      
            status[1] = 0;              
            lcd.setCursor(10,0);      
            lcd.print("OFF");

            digitalWrite(app2, LOW);
            status[2] = 0;
            lcd.setCursor(11,1);      
            lcd.print("OFF");
           }

         else {
               digitalWrite(app1, HIGH);   
               status[1] = 1;            
               lcd.setCursor(10,0);    
               lcd.print("ON ");

               digitalWrite(app2, HIGH);
               status[2] = 1;
               lcd.setCursor(11,1);      
               lcd.print("ON ");
         }
      
    }
    Serial.println(value);      
    irrecv.resume();       // Receive the next value
  }
}

Credits

Naman Chauhan
2 projects • 59 followers
Doing B.Tech. in Computer Science and Engineering.Have a good hold on C,C++ & Arduino. We have 30+ people group on Hackster!

Comments