Subhajit
Published © GPL3+

Arduino Home Automation with IR Remote & Bluetooth

Control home appliances from IR remote and Bluetooth with Arduino Home Automation with code and circuit.

IntermediateFull instructions provided24 hours3,196
Arduino Home Automation with IR Remote & Bluetooth

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

Arduino_code_for_Bluetooth_IR_controlled_Relay_Module.ino

Arduino
// modified by TechStudyCell
//Arduino code for Bluetooth IR controlled Relay Module
#include <IRremote.h>
//Define PIN constant
const int switch_1 = 12;
const int switch_2 = 11;
const int switch_3 = 10;
const int switch_4 = 9;
const int smode = 7;
const int irled = 6;
const int btled = 5;

int RECV_PIN = 8;

int toggleState_1 = 0; //Define integer to remember the toggle state for switch 1
int toggleState_2 = 0; //Define integer to remember the toggle state for switch 2
int toggleState_3 = 0; //Define integer to remember the toggle state for switch 3
int toggleState_4 = 0; //Define integer to remember the toggle state for switch 4
int ModeFlag = 0;


//Define IR receiver and Result Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Enable the IR receiver
   pinMode(switch_1, OUTPUT);
   pinMode(switch_2, OUTPUT);
   pinMode(switch_3, OUTPUT);
   pinMode(switch_4, OUTPUT);
   pinMode(irled, OUTPUT);
   pinMode(btled, OUTPUT);
   pinMode(smode, INPUT);

}

void loop() {

if (digitalRead(smode) == HIGH){
  
  if (ModeFlag == 0){
    ModeFlag = 1;
    digitalWrite(irled, HIGH); // turn on IRLED
    digitalWrite(btled, LOW);
    delay(200);
  }
  else if (ModeFlag == 1) {
    ModeFlag = 0;
    digitalWrite(btled, HIGH);
    digitalWrite(irled, LOW); // turn on IRLED
    delay(200);
  }
  //delay(1000);
}
  
if (ModeFlag == 0) {
  
if(Serial.available()>0)
   {     
      char data= Serial.read(); // reading the data received from the bluetooth module
      switch(data)
      {
        case 'Z': digitalWrite(switch_1, HIGH);break; // when Z is pressed on the app Turn on Pin 12
        case 'z': digitalWrite(switch_1, LOW);break; // when z is pressed on the app Turn off Pin 12
        case 'Y': digitalWrite(switch_2, HIGH);break; // when Y is pressed on the app Turn on Pin 11
        case 'y': digitalWrite(switch_2, LOW);break; // when y is pressed on the app Turn off Pin 11
        case 'W': digitalWrite(switch_3, HIGH);break; // when W is pressed on the app Turn on Pin 10
        case 'w': digitalWrite(switch_3, LOW);break; // when w is pressed on the app Turn off Pin 10
        case 'V': digitalWrite(switch_4, HIGH);break; // when V is pressed on the app Turn on Pin 9
        case 'v': digitalWrite(switch_4, LOW);break; // when v is pressed on the app Turn off Pin 9
        default : break;
      }
      Serial.println(data);
   }
   delay(100);
}


else if (ModeFlag == 1) {
  if (irrecv.decode(&results)) {

    switch(results.value){
      case 0x10EFA956: 
                if(toggleState_1 == 0){
                  digitalWrite(switch_1, HIGH); // turn on switch 1
                  toggleState_1 = 1;
                  }
                else{
                  digitalWrite(switch_1, LOW); // turn off switch 1
                  toggleState_1 = 0;
                  }
                  delay(100);
      break;
      case 0x10EF9966: 
                if(toggleState_2 == 0){
                  digitalWrite(switch_2, HIGH); // turn on switch 2
                  toggleState_2 = 1;
                  }
                else{
                  digitalWrite(switch_2, LOW); // turn off switch 2
                  toggleState_2 = 0;
                  }
                  delay(100);
      break;
      case 0x10EFB946: 
                if(toggleState_3 == 0){
                  digitalWrite(switch_3, HIGH); // turn on switch 3
                  toggleState_3 = 1;
                  }
                else{
                  digitalWrite(switch_3, LOW); // turn off switch 3
                  toggleState_3 = 0;
                  }
                  delay(100);
      break;
      case 0x10EF6B94: 
                if(toggleState_4 == 0){
                  digitalWrite(switch_4, HIGH); // turn on switch 4
                  toggleState_4 = 1;
                  }
                else{
                  digitalWrite(switch_4, LOW); // turn off switch 4
                  toggleState_4 = 0;
                  }
                  delay(100);
      break;
      default : break;      
      }
    
    irrecv.resume(); // Receive the next value
  }
}
}

Credits

Subhajit

Subhajit

1 project • 2 followers
Love to make different DIY projects on home automation, IoT, basic electronics

Comments