Bluetooth Arduino Home Automation

November 2, 2015     noteshunt    

Picture of Arduino Home Automation (Bluetooth)

53bd29149d29c9cc650004bf.jpg

Hello All!

Now I don’t know about you, but to me it seems an awful lot of effort to get up and flick a switch on an appliance. Let’s say a lamp. Wouldn’t it be marvellous, I ask myself, if I could just speak to my phone……YES IT WOULD.

So in this ‘Instructable’ I will attempt to show how to connect an Arduino to your android phone via Bluetooth and then use voice commands to control high voltage devices using relays.

Electricity is dangerous so please be careful!!!!

So without further ado let’s charge in!

Step 1: Things you will need!

Picture of Things you will need!
53bd26509d29c9250c000109.jpg
53bd25d09d29c9250c000105.jpg
53bd25fd9d29c9cc650004b3.jpg
53bd26659d29c992700002dc.jpg

Step 2: Relay Test

Picture of Relay Test

IMG_20140709_130347536 (1).jpg

So first of all we want to check if the relay is switching.

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.

Code:

#define relay 2    

void setup()
{
  pinMode(relay, OUTPUT);    
}
void loop()
{
  digitalWrite(relay, HIGH);    
  delay(2000);                  
  digitalWrite(relay, LOW);     
  delay(2000);                  
}

Step 3: Bluetooth Test

Picture of Bluetooth Test
IMG_20140709_174621497.jpg
IMG_20140709_181228355.jpg
IMG_20140709_181312570.jpg
IMG_20140709_181322249.jpg

First off wire up the circuit as shown above. I have used a breadboard and made one rail positive and one negative. Annoyingly I found that the TXD and RXD pins on the Bluetooth module don’t work when connected to the same pins on the arduino itself. The TXD pin on the Bluetooth module I have 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 I have used 5 volts on the arduino.

Here is the code I have written for this 2 switch relay. As an example I have it controlling a kettle and lamp.

String voice;
#define relay1 2    
#define relay2 3    
void setup()
{
  Serial.begin(9600);            
  pinMode(relay1, OUTPUT);       
  pinMode(relay2, OUTPUT);       
  digitalWrite(relay1, LOW);     
  digitalWrite(relay2, LOW);     
}
void loop()
{
  while(Serial.available())    
  {
    delay(10);                 
    char c = Serial.read();    
    if (c == '#'){
      break;                   
    }
    voice += c;                
  }
    if (voice.length() >0)
    {
      Serial.println(voice);
      if(voice == "*switch on"){
        switchon();
      }               
      else if(voice == "*switch off"){
        switchoff();
      }               
      else if(voice == "*lamp on"){   

        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()               
{
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
}
void switchoff()              
{
  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

Now on your android phone download this brilliant app by SimpleLabs!

https://play.google.com/store/apps/details?id=robotspace.simplelabs.amr_voice&hl=en

Connect to the Bluetooth module it will probably be called something like ‘HC-06’

The first time it will ask you for a password which is usually 1234.

Once you have connected say the commands you have chosen in the code and hopefully the relay will switch on and off!

Step 4: Adding the Appliances

Picture of Adding the Appliances

IMG_20140709_205504921.jpg
IMG_20140709_210045667.jpg
IMG_20140709_221304422.jpg
IMG_20140709_221841930.jpg

To quote Brick from Anchorman ‘I love Lamp!’

So the first thing to do is find and old lamp or other appliance as we are going to be cutting the lead.

Now remove the outer rubber sleeving making sure not to cut the sleeving of the wires inside, we don’t want any live wire showing! Next cut the positive wire (the red one) and remove a few millimetres of sleeving on each end. Insert the exposed wire in the correct ports of the relay as shown in the diagram and pictures above. MAKE SURE THERE IS NO WIRE VISIBLE! For safety wrap the wires in electrical tape, and cover any of the places that could be live on the relay, such as the screws.

I am not responsible for your safety, do this at your own risk!

Once this is done we are ready to power on the lamp and test the system. XD

Step 5: Conclusion

Hope that was informative and you were successful.

Electricity is dangerous so please be careful!!!!

The possibilities for this I feel are endless you can add loads of devices and then create functions in order to control several at once.

Here is a video of the lamp working:

Thank You :

Categories: Arduino, Projects