MAJOR LAUNCH: HUSKYLENS 2 6 TOPS LLM MCP AI Vision Sensor is now available. Buy Now →
Everyone wants a remote to control all the appliances in your home. Some companies are introducing wireless controllers for various appliances but they are costly and you have to upgrade the existing for additional cost. So, what about making your own home automation system to control up to 4 appliances.
 
Hardware componens:
Specifications
 
4 Channel Relay Shield
 

 
IR Kit for Arduino
 
High Voltage VS Low Voltage
 
We all know that the appliances work on 110 V (USA) and 220 V (Asia) depending upon the region. But, the Arduino we are using is working on just 5 V. If we connect it directly to the mains supply to control the appliances just like controlling the LEDs, the board or the microcontroller will get burned. So, we use 5 V relay which works as an interface between the two voltage supplies. A signal is sent to relay by Arduino and relay switches on the circuit of the appliance.
Wireless Transmission of Data
We know that how will we switch the supply on but we need to send the signal from an IR remote to the receiver with Arduino. So, we can use any generic IR remote controller available in market. But, every remote controller comes with different codes for their buttons which they send it through IR LED. So, we need to find those codes for a random IR remote controller we are using.
For that, please click here for another project of mine on Hackster.io.
Hook-up the Circuit: IR receiver and relay connections
1.Just stack the relay shield on the Arduino board. On the shield, there are male headers for digital I/O pins. 
2.Connect the connector cable for IR module in the PIN 11 of the board. 
3.Keep in mind the colors on the wires matching with each other.
 
Testing it up!
Remember to install the IRremote.h library in the Arduino IDE. Download the ZIP File.
1. Upload the code attached in the end of project.
2. Wait for the system to initialize.
3. press the POWER button to switch ON/OFF all the appliances.
4. Press each corresponding button (like 1 for fan, 2 for light and so on) to switch ON/OFF them.


 
Schematics for the project

 
 
Relay connections to the appliance

 
 
CODE
/*************************************************************************************
   Pin            Pin State:HIGH                      Pin State:LOW
   Digital 2      NC1 is disconnected with COM1       NC1 is connected with COM1 
                  NO1 is connected with COM1          NO1 is disconnected with COM1
   Digital 7      NC2 is disconnected with COM2       NC2 is connected with COM2
                  NO2 is connected with COM2          NO2 is disconnected with COM2
   Digital 8      NC3 is disconnected with COM3       NC3 is connected with COM3
                  NO3 is connected with COM3          NO3 is disconnected with COM3
   Digital 10     NC4 is disconnected with COM4       NC4 is connected with COM4
                  NO4 is connected with COM4          NO4 is disconnected with COM4
   -----------------------------------------------------------------------------------               
   
   IR Remote Codes :
   
   POWER :          16580863
   VOL+ :           16613503
   FUNC/STOP :      16597183
   PLAY BACKWARDS : 16589023
   PAUSE/STOP :     16621663
   PLAY FORWARD :   16605343
   ARROW DOWN :     16584943
   VOL- :           16617583
   ARROW UP :       16601263
   0 :              16593103
   EQ :             16625743
   ST/REPT :        16609423
   1 :              16582903
   2 :              16615543
   3 :              16599223
   4 :              16591063
   5 :              16623703
   6 :              16607383
   7 :              16586983
   8 :              16619623
   9 :              16603303
   -----------------------------------------------------------------------------------
   Download the IRremote library : https://dfimg.dfrobot.com/enshop/image/data/DFR0107/IRremote.zip
   Made by Techduino (2017)
 */
#include<IRremote.h>      //including infrared remote header file
#define power 16580863            //code for power button
#define button_1 16582903         //code for button 1
#define button_2 16615543         //code for button 2
#define button_3 16599223         //code for button 3
#define button_4 16591063         //code for button 4
int RECV_PIN = 11;        //IR reciever pin
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned int value;
int relay1 = 2;
int relay2 = 7;
int relay3 = 8;
int relay4 = 10;
unsigned int relay_state[] = {0, 0, 0, 0, 0};
void setup()  {
  Serial.begin(9600);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  irrecv.enableIRIn();    //Start the IR reciever
}
void loop() {
  
  if (irrecv.decode(&results))  {
    Serial.println("code recieved");
    value = results.value;
    switch(value) {
      case power:   if (relay_state[1] == 1 && relay_state[2] == 1 && 
                    relay_state[3] == 1 && relay_state[4] == 1)  {                 
                    digitalWrite(relay1, LOW);                // turn it off when button is pressed
                    relay_state[1] = 0;                       // and set its state as off
                    digitalWrite(relay2, LOW);
                    relay_state[2] = 0;
                    
                    digitalWrite(relay3, LOW);
                    relay_state[3] = 0;
                    
                    digitalWrite(relay4, LOW);
                    relay_state[4] = 0;
                    }
                    
                    if (relay_state[1] == 0 && relay_state[2] == 0 && 
                       relay_state[3] == 0 && relay_state[4] == 0) {
                       digitalWrite(relay1, HIGH);               // turn it on when the button is pressed
                       relay_state[1] = 1;                       // and set its state as ON
        
                       digitalWrite(relay2, HIGH);  
                       relay_state[2] = 1;
                       
                       digitalWrite(relay3, HIGH);  
                       relay_state[3] = 1;
                       
                       digitalWrite(relay4, HIGH);  
                       relay_state[4] = 1;
                    }
                    break;
      case button_1:  if (relay_state[1] == 1)  {                 // if first app is ON then
                      digitalWrite(relay1, LOW);                // turn it off when button is pressed
                      relay_state[1] = 0;                       // and set its state as off
                      }
                      
                      if (relay_state[1] == 0) {
                        digitalWrite(relay1, HIGH);               // turn it on when the button is pressed
                        relay_state[1] = 1;                       // and set its state as ON
                      }
                      break;
                  
      case button_2:  if (relay_state[2] == 1)  {                 // if first app is ON then
                        digitalWrite(relay2, LOW);                // turn it off when button is pressed
                        relay_state[2] = 0;                       // and set its state as off
                      }
                      
                      if (relay_state[2] == 0) {
                        digitalWrite(relay2, HIGH);               // turn it on when the button is pressed
                        relay_state[2] = 1;                       // and set its state as ON
                      }
                      break;
      
      case button_3:  if (relay_state[3] == 1)  {                 // if first app is ON then
                      digitalWrite(relay3, LOW);                // turn it off when button is pressed
                      relay_state[3] = 0;                       // and set its state as off
                      }
                      
                      if (relay_state[3] == 0) {
                        digitalWrite(relay3, HIGH);               // turn it on when the button is pressed
                        relay_state[3] = 1;                       // and set its state as ON
                      }
                      break;
      
      case button_4:  if (relay_state[4] == 1)  {                 // if first app is ON then
                      digitalWrite(relay4, LOW);                // turn it off when button is pressed
                      relay_state[4] = 0;                       // and set its state as off
                      }
                      
                      if (relay_state[4] == 0) {
                      digitalWrite(relay4, HIGH);               // turn it on when the button is pressed
                      relay_state[4] = 1;                       // and set its state as ON
                      }
                      break;
       default: {
                  Serial.print("Key ");
                  Serial.print(value);
                  Serial.println(" not programmed");
                }
                break;
    }
    Serial.println(value);      
    irrecv.resume();
    Serial.println("Resumed the IR reciever");   
  }
}
CREDITS
 
This project is made by Naman Chauhan, a very talent electronic engineer, the original post here.