Sunday, October 21, 2018

Simple Home Automation Using Bluetooth Module

Simple Home Automation Using Bluetooth, Android and Arduino

Take control of your home in your smart-phone with the simplest ever home automation device.


The Code:-


String voice;
#define relay1 2    //Connect relay1 to pin 2
#define relay2 3    //Connect relay2 to pin 3
#define relay3 7   //Connect relay1 to pin 2
#define relay4 8    //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);
  pinMode(relay3, OUTPUT);      //Set relay2 as an output
  pinMode(relay4, OUTPUT);
  digitalWrite(relay1, LOW);     //Switch relay1 off
  digitalWrite(relay2, LOW);     //Swtich relay2 off
  digitalWrite(relay3, LOW);     //Switch relay1 off
  digitalWrite(relay4, 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();
      }               
      else if(voice == "*switch off"){
        switchoff();
      }             
      else if(voice == "*bulb1 on"){   
        digitalWrite(relay1, LOW);
      }
      else if(voice == "*bulb1 off"){
        digitalWrite(relay1, HIGH);
      }
       else if(voice == "*bulb2 on"){   
        digitalWrite(relay2, LOW);
      }
      else if(voice == "*bulb2 off"){
        digitalWrite(relay2, HIGH);
      }
       else if(voice == "*fan1 on"){   
        digitalWrite(relay3, LOW);
      }
      else if(voice == "*fan1 off"){
        digitalWrite(relay3, HIGH);
      }
      else if(voice == "*fan2 on"){
        digitalWrite(relay4, LOW);
      }
      else if(voice == "*fan2 off"){
        digitalWrite(relay4, HIGH);
      }
      voice="";
    }
}
void switchon()               //Function for turning on relays
{
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay4, LOW);
}
void switchoff()              //Function for turning on relays
{
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
}

MOBILE APP:-

If you don't know how to make android application then click the link below.
https://www.youtube.com/watch?v=dWKam0eekhU&t=1s


42 comments:

  1. Sir can u plz tell me kae apnae arduino pae jo.supply di wo daigrm mae nae han q

    ReplyDelete
  2. It just shows the error message like,
    Voice port is unidentified.

    ReplyDelete
  3. Sir mujhe iss app ka aia file mil sakta hai please de dijiye sir

    ReplyDelete
  4. Sir mobile app kesy install ho gy

    ReplyDelete
  5. Sir mujhe this bluetooth device and Esp82.66 both use kare hoy coding milsakte hy plz

    ReplyDelete
  6. It gives error during uploading how can I remove this please guide me

    ReplyDelete
    Replies
    1. Unplug the connection and install code to arduino

      Delete
  7. there is an error related to voice

    ReplyDelete
  8. Replies
    1. Send an mail at
      waimchoudhary@gmail.com
      I will send you

      Delete
  9. Replies
    1. String voice;
      #define relay1 2 //Connect relay1 to pin 2
      #define relay2 3 //Connect relay2 to pin 3
      #define relay3 7 //Connect relay1 to pin 2
      #define relay4 8 //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);
      pinMode(relay3, OUTPUT); //Set relay2 as an output
      pinMode(relay4, OUTPUT);
      digitalWrite(relay1, LOW); //Switch relay1 off
      digitalWrite(relay2, LOW); //Swtich relay2 off
      digitalWrite(relay3, LOW); //Switch relay1 off
      digitalWrite(relay4, 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();
      }
      else if(voice == "*switch off"){
      switchoff();
      }
      else if(voice == "*bulb1 on"){
      digitalWrite(relay1, LOW);
      }
      else if(voice == "*bulb1 off"){
      digitalWrite(relay1, HIGH);
      }
      else if(voice == "*bulb2 on"){
      digitalWrite(relay2, LOW);
      }
      else if(voice == "*bulb2 off"){
      digitalWrite(relay2, HIGH);
      }
      else if(voice == "*fan1 on"){
      digitalWrite(relay3, LOW);
      }
      else if(voice == "*fan1 off"){
      digitalWrite(relay3, HIGH);
      }
      else if(voice == "*fan2 on"){
      digitalWrite(relay4, LOW);
      }
      else if(voice == "*fan2 off"){
      digitalWrite(relay4, HIGH);
      }
      voice="";
      }
      }
      void switchon() //Function for turning on relays
      {
      digitalWrite(relay1, LOW);
      digitalWrite(relay2, LOW);
      digitalWrite(relay3, LOW);
      digitalWrite(relay4, LOW);
      }
      void switchoff() //Function for turning on relays
      {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, HIGH);
      digitalWrite(relay3, HIGH);
      digitalWrite(relay4, HIGH);
      }

      Delete
    2. Code me relay 3 pin 7 se kiyu define kiya hai . Circuit me to relay 3 pin 4 se and relay 4 pin 5 se connect kiya hai . Ye thora bta do please. Confuse ho gya hu

      Delete
  10. Bro please send arduino code in Bluetooth home automation...

    ReplyDelete
    Replies
    1. #define relay1 2 //Connect relay1 to pin 2
      #define relay2 3 //Connect relay2 to pin 3
      #define relay3 7 //Connect relay1 to pin 2
      #define relay4 8 //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);
      pinMode(relay3, OUTPUT); //Set relay2 as an output
      pinMode(relay4, OUTPUT);
      digitalWrite(relay1, LOW); //Switch relay1 off
      digitalWrite(relay2, LOW); //Swtich relay2 off
      digitalWrite(relay3, LOW); //Switch relay1 off
      digitalWrite(relay4, 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();
      }
      else if(voice == "*switch off"){
      switchoff();
      }
      else if(voice == "*bulb1 on"){
      digitalWrite(relay1, LOW);
      }
      else if(voice == "*bulb1 off"){
      digitalWrite(relay1, HIGH);
      }
      else if(voice == "*bulb2 on"){
      digitalWrite(relay2, LOW);
      }
      else if(voice == "*bulb2 off"){
      digitalWrite(relay2, HIGH);
      }
      else if(voice == "*fan1 on"){
      digitalWrite(relay3, LOW);
      }
      else if(voice == "*fan1 off"){
      digitalWrite(relay3, HIGH);
      }
      else if(voice == "*fan2 on"){
      digitalWrite(relay4, LOW);
      }
      else if(voice == "*fan2 off"){
      digitalWrite(relay4, HIGH);
      }
      voice="";
      }
      }
      void switchon() //Function for turning on relays
      {
      digitalWrite(relay1, LOW);
      digitalWrite(relay2, LOW);
      digitalWrite(relay3, LOW);
      digitalWrite(relay4, LOW);
      }
      void switchoff() //Function for turning on relays
      {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, HIGH);
      digitalWrite(relay3, HIGH);
      digitalWrite(relay4, HIGH);
      }

      Delete
  11. Bro please send arduino code in Bluetooth home automation...

    ReplyDelete
  12. Sir can you send please 8 Kelay module codeing

    ReplyDelete
  13. sir is ko kasy download karyn or arduino ma kasy copy karyn

    ReplyDelete
  14. Keep it up 👏

    ReplyDelete
  15. super sir....but do a video with your voice sir...

    ReplyDelete
  16. If i want to add more output then what changes i should done in program?

    ReplyDelete
  17. One another Q is
    define relay1 2 //Connect relay1 to pin 2
    #define relay2 3 //Connect relay2 to pin 3
    #define relay3 7 //Connect relay1 to pin 2

    In 3rd row,
    Why "relay3 7"?
    Its "relay3 4"
    Is it correct or not please explain.

    In 3 row comment,
    Why "relay3 7" connect relay1 to pin 2
    Its "relay3 7" connect relay3 to pin 7
    Is it correct or not please explain

    Thank you.

    ReplyDelete
  18. do anyone knows how to do the proteus simulation using the apps?

    ReplyDelete
  19. bro the code ran successfully and i connected the BT in the ApK file you have attached. the problem am facing is, that on clicking the button "ALL ON ,ALL OFF ,etc" or on any other button my relays are not getting off
    please guide me.. am python programmer myself and i checked your code but there is no line of code related to HC-05 module. please guide me how can i overcome the issue i've told you.

    kind regards,

    ReplyDelete
  20. These project is workful
    But first me sare switch on ho jate he plz sir iska solution batye ki first me switch off rhe

    ReplyDelete
  21. problem with the coppied code.
    "an error occurs while uploading the sketch"
    plz help

    ReplyDelete
  22. Please could you send me proteus simulation for this project

    ReplyDelete
  23. Sir Maine ye project kiya bt ye without mobile app k command se hi jal rahaa hai command dene se pahile hi port ka Sara pin high hai

    ReplyDelete
  24. An impressive share, I just now given this onto a colleague who had previously been doing little analysis about this. Anf the husband the fact is bought me breakfast simply because I stumbled upon it for him.. smile. So permit me to reword that: Thnx for your treat! But yeah Thnkx for spending some time to debate this, I find myself strongly over it and enjoy reading more about this topic. If possible, as you become expertise, might you mind updating your site with more details? It truly is highly of great help for me. Huge thumb up because of this text! buy wallpaper

    ReplyDelete