Monday, 26 December 2016

Home automation using Bluetooth

Hello friends,today we will be posting details on how to control home appliances like lamps and fans with your mobile phone .The components required are given as follows :

1. 12V relay


2. Arduino UNO:


3.hc-05 Bluetooth module:



The minor components required for this project are wires,LED,lamps,android phone with Bluetooth,electrical tape and wire strippers.It is strongly recommended to try the project with led before going with 230v lamps.


The given project will be divided into three phases as follows:

1. PHASE 1:

Phase 1 is the relay test to find out if the relay is switching or not.The connections are given as per the circuit diagram:


  Wire up the relay as shown in the diagram, make sure that the JD-VCC and VCC pins are bridged if you are powering the relay from your arduino. If they are not bridged you will see the LED turning on and off every 2 seconds but there will not be the clicking sound of the relay switching.After giving the connection, your circuit will be as follows:



Code:

#define relay 2    //attaches the relay to pin 2

void setup()
{
  pinMode(relay, OUTPUT);    //sets the relay as an output
}
void loop()
{
  digitalWrite(relay, HIGH);    //relay open
  delay(2000);                  //wait 2 seconds
  digitalWrite(relay, LOW);     //relay closed
  delay(2000);                  //wait 2 seconds
}

PHASE 2:

The phase 2 of our project will be Bluetooth testing to check if the hc05 module is transmitting and receiving properly.The connections are given as follows:


After giving the connections,your project will look as follows:



The TXD pin on the Bluetooth module is connected to the RXD pin on the arduino (pin 0), and the RXD pin on the Bluetooth module is connected to the TXD pin on the arduino (pin 1). The Bluetooth Module will run off 3.3v but the relay needs 5v to work, hence 5 volts is used in the arduino.

Code:

String voice;
#define relay1 2    //Connect relay1 to pin 2
#define relay2 3    //Connect relay2 to pin 3
void setup()
{
  Serial.begin(9600);            //Set rate for communicating with phone
  pinMode(relay1, OUTPUT);       //Set relay1 as an output
  pinMode(relay2, OUTPUT);       //Set relay2 as an output
  digitalWrite(relay1, LOW);     //Switch relay1 off
  digitalWrite(relay2, LOW);     //Swtich relay2 off
}
void loop()
{
  while(Serial.available())    //Check if there are available bytes to read
  {
    delay(10);                 //Delay to make it stable
    char c = Serial.read();    //Conduct a serial read
    if (c == '#'){
      break;                   //Stop the loop once # is detected after a word
    }
    voice += c;                //Means voice = voice + c
  }
    if (voice.length() >0)
    {
      Serial.println(voice);
      if(voice == "*switch on"){
        switchon();
      }               //Initiate function switchon if voice is switch on
      else if(voice == "*switch off"){
        switchoff();
      }               //Initiate function switchoff if voice is switch off
      else if(voice == "*lamp on"){   
//You can replace 'lamp on' with anything you want...same applies to others
        digitalWrite(relay1, HIGH);
      }
      else if(voice == "*lamp off"){
        digitalWrite(relay1, LOW);
      }
      else if(voice == "*kettle on"){
        digitalWrite(relay2, HIGH);
      }
      else if(voice == "*kettle off"){
        digitalWrite(relay2, LOW);
      }
      voice="";
    }
}
void switchon()               //Function for turning on relays
{
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
}
void switchoff()              //Function for turning on relays
{
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
}

/*

When you upload the code to your Arduino, make sure you unplug pins 0 and 1 otherwise you will probably get this error:
avrdude: stk500_getsync(): not in sync: resp=0x00

After uploading it,connect the lamp and kettle to the relay port 1 and 2 and control it using the sympos voice app.

No comments:

Post a Comment