Code And Circuit Diagram For Home Automation System Using Arduino

** if you want to buy the entire package with a re-programmable Arduino Click Here **

1) Home Automation System






CODE :-

String inputs;
#define relay1 2 //Connect relay1 to pin 9
#define relay2 3 //Connect relay2 to pin 8
#define relay3 4 //Connect relay3 to pin 7
#define relay4 5 //Connect relay4 to pin 6
#define relay5 6 //Connect relay5 to pin 5
#define relay6 7 //Connect relay6 to pin 4
#define relay7 8 //Connect relay7 to pin 3
#define relay8 9 //Connect relay8 to pin 2
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
pinMode(relay3, OUTPUT); //Set relay1 as an output
pinMode(relay4, OUTPUT); //Set relay2 as an output
pinMode(relay5, OUTPUT); //Set relay1 as an output
pinMode(relay6, OUTPUT); //Set relay2 as an output
pinMode(relay7, OUTPUT); //Set relay1 as an output
pinMode(relay8, OUTPUT); //Set relay2 as an 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
digitalWrite(relay5, LOW); //Switch relay1 off
digitalWrite(relay6, LOW); //Swtich relay2 off
digitalWrite(relay7, LOW); //Switch relay1 off
digitalWrite(relay8, 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
}
inputs += c; //Means inputs = inputs + c
}
if (inputs.length() >0)
{
Serial.println(inputs);

if(inputs == “A”)
{
digitalWrite(relay1, LOW);
}
else if(inputs == “a”)
{
digitalWrite(relay1, HIGH);
}
else if(inputs == “B”)
{
digitalWrite(relay2, LOW);
}
else if(inputs == “b”)
{
digitalWrite(relay2, HIGH);
}
else if(inputs == “C”)
{
digitalWrite(relay3, LOW);
}
else if(inputs == “c”)
{
digitalWrite(relay3, HIGH);
}
else if(inputs == “D”)
{
digitalWrite(relay4, LOW);
}
else if(inputs == “d”)
{
digitalWrite(relay4, HIGH);
}
else if(inputs == “E”)
{
digitalWrite(relay5, LOW);
}
else if(inputs == “e”)
{
digitalWrite(relay5, HIGH);
}
else if(inputs == “F”)
{
digitalWrite(relay6, LOW);
}
else if(inputs == “f”)
{
digitalWrite(relay6, HIGH);
}
else if(inputs == “G”)
{
digitalWrite(relay7, LOW);
}
else if(inputs == “g”)
{
digitalWrite(relay7, HIGH);
}
else if(inputs == “H”)
{
digitalWrite(relay8, LOW);
}
else if(inputs == “h”)
{
digitalWrite(relay8, HIGH);
}
inputs=””;
}
}

*** IF YOU ARE GETTING A STRAY ERROR DOWNLOAD THE CODE FROM HERE ***

To Download The Bluetooth Application For Your Android CLICK HERE



91 Comments on “Code And Circuit Diagram For Home Automation System Using Arduino”

  1. coming erorr message like that
    Sketch uses 3932 bytes (12%) of program storage space. Maximum is 32256 bytes.
    Global variables use 236 bytes (11%) of dynamic memory, leaving 1812 bytes for local variables. Maximum is 2048 bytes.

      1. BRO EK NAYA PROJECT KE BARE ME VIDEO TAYAR KARO
        SUB :- PLAY MUSIC VIA ONLINE USING AURDUINO WITH VOICE CONTROLL

  2. Bro the programme is saying can’t upload to board plzzzzzzz help me plzzzzzzz and one more thing is that I am using 8 channel relay board of 8 channel but it is having pins like in1, in2 and so on I the relay board correct
    Love ur videos

    1. Hey shree is ur problem resolved becoz I am facing the same problem “can’t be upload to the bord” plzz can you help me out plzz its urgent

  3. avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xf2
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

    I am facing this error plzzzz hepl me out harsh and I want to know that i am using a relay board which is having inputs like in1,in2 etc Does the board correct.
    plzzzzz reply me

      1. Sketch uses 3932 bytes (12%) of program storage space. Maximum is 32256 bytes.
        Global variables use 236 bytes (11%) of dynamic memory, leaving 1812 bytes for local variables. Maximum is 2048 bytes.
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30
        avrdude: stk500_recv(): programmer is not responding
        avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x30
        Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
        THE CODE IS NOT WORKING BROI

  4. avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xf2
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

    This is the error

  5. Hello Harsh,

    I am just trying to compile the above code but it throws error, I tried to resolve syntax errors like ” & ‘ and tried to compile it but it throws below error;
    Arduino: 1.8.5 (Windows 10), Board: “Arduino/Genuino Uno”

    C:\Users\y510\AppData\Local\Temp\ccaU67iB.ltrans0.ltrans.o: In function `_GLOBAL__sub_D_inputs’:

    C:\Users\y510\Desktop\Ardiuno\sketch_feb20a/sketch_feb20a.ino:1: undefined reference to `String::~String()’

    C:\Users\y510\AppData\Local\Temp\ccaU67iB.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_inputs’:

    C:\Users\y510\Desktop\Ardiuno\sketch_feb20a/sketch_feb20a.ino:1: undefined reference to `String::String(char const*)’

    c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main’

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    Could you please look into this and help me out.

    Regards,
    Rahul

  6. Hi,

    Good that you noticed my comment! 🙂

    One more question.

    Everything is perfectly setup for me but still unable to switch on and switch off light, could you please tell me what would the cause? And specifically why you used Device 7 button in Arduino Bluetooth Controller, any reason?

    Regards,
    Rahul

    1. Arduino: 1.8.5 (Windows 7), Board: “Arduino/Genuino Uno”

      Sketch uses 3932 bytes (12%) of program storage space. Maximum is 32256 bytes.
      Global variables use 236 bytes (11%) of dynamic memory, leaving 1812 bytes for local variables. Maximum is 2048 bytes.
      avrdude: ser_open(): can’t open device “\\.\COM1”: The system cannot find the file specified.

      Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

      This report would have more information with
      “Show verbose output during compilation”
      option enabled in File -> Preferences.

  7. Bhai agar meko isme kisi ek port pe dc motor lgana ho..and to programme that port to operate dc motor in both direction..to us port pe programming kaise hogi..is it possible to programme that particular port as our requirement(in the same programme)?

      1. Nhi ho payea sirf ek side run kregi bcz ek relay pe ek switch hai..we need two differ swlitches..instead of program just apply simpl logic changing the polarity of dc motor changes the direction of rotation..😉two battries use hogi or ek motor ko dono se connection dena..bas polarity change krna

  8. What if i have to on/off a light both in automatic (using bluetooth) and manual(using switch) switching?

  9. Sir jab m arduino ko program krny k bad suply k sath cnect krta hun..
    To arduino terminals always onn.. (1)
    So relys b onn e rehti hen… blutooth is also cnect to android… butt never work.. lamps always onn… so help me plzz pllzz…

    1. Jab relay on ho rha tik tik sound aa rhi hai ya nhi?if not then check ur jumper conection on the end of module u can see 3 pins on board..i have been through same problm

      1. Jab arduino on krta hun to sath hi relays b on ho jati hen.. phr arduino ko bnd krny k bad hi band hoti hen.. otherwise chlti rehti hen.

      2. Jab arduino on krta hun to sath hi relays b on ho jati hen or relys k on hony ki sound b ati h.. phr arduino ko bnd krny k bad hi relays band hoti hen.. otherwise chlti rehti hen.

  10. If we turn off the bluetooth from our phone will the bulb still glow ….
    and apart from the work are you a web desighner too i like your work i am also an IT student..

  11. hi harsh,
    appreciate your work a lot….i’ll definitely try making it…i had a doubt that whether we could control it using wifi or not?
    thanks for your support.

  12. Arduino: 1.8.5 (Windows 7), Board: “Arduino/Genuino Uno”

    new:36: error: stray ‘\342’ in program

    if (c == ‘#’){

    ^

    new:36: error: stray ‘\200’ in program

    new:36: error: stray ‘\230’ in program

    new:36: error: stray ‘#’ in program

    if (c == ‘#’){

    ^

    new:36: error: stray ‘\342’ in program

    if (c == ‘#’){

    ^

    new:36: error: stray ‘\200’ in program

    new:36: error: stray ‘\231’ in program

    new:45: error: stray ‘\342’ in program

    if(inputs == “A�)

    ^

    new:45: error: stray ‘\200’ in program

    new:45: error: stray ‘\234’ in program

    new:45: error: stray ‘\342’ in program

    new:45: error: stray ‘\200’ in program

    new:45: error: stray ‘\235’ in program

    new:49: error: stray ‘\342’ in program

    else if(inputs == “a�)

    ^

    new:49: error: stray ‘\200’ in program

    new:49: error: stray ‘\234’ in program

    new:49: error: stray ‘\342’ in program

    new:49: error: stray ‘\200’ in program

    new:49: error: stray ‘\235’ in program

    new:53: error: stray ‘\342’ in program

    else if(inputs == “B�)

    ^

    new:53: error: stray ‘\200’ in program

    new:53: error: stray ‘\234’ in program

    new:53: error: stray ‘\342’ in program

    new:53: error: stray ‘\200’ in program

    new:53: error: stray ‘\235’ in program

    new:57: error: stray ‘\342’ in program

    else if(inputs == “b�)

    ^

    new:57: error: stray ‘\200’ in program

    new:57: error: stray ‘\234’ in program

    new:57: error: stray ‘\342’ in program

    new:57: error: stray ‘\200’ in program

    new:57: error: stray ‘\235’ in program

    new:61: error: stray ‘\342’ in program

    else if(inputs == “C�)

    ^

    new:61: error: stray ‘\200’ in program

    new:61: error: stray ‘\234’ in program

    new:61: error: stray ‘\342’ in program

    new:61: error: stray ‘\200’ in program

    new:61: error: stray ‘\235’ in program

    new:65: error: stray ‘\342’ in program

    else if(inputs == “c�)

    ^

    new:65: error: stray ‘\200’ in program

    new:65: error: stray ‘\234’ in program

    new:65: error: stray ‘\342’ in program

    new:65: error: stray ‘\200’ in program

    new:65: error: stray ‘\235’ in program

    new:69: error: stray ‘\342’ in program

    else if(inputs == “D�)

    ^

    new:69: error: stray ‘\200’ in program

    new:69: error: stray ‘\234’ in program

    new:69: error: stray ‘\342’ in program

    new:69: error: stray ‘\200’ in program

    new:69: error: stray ‘\235’ in program

    new:73: error: stray ‘\342’ in program

    else if(inputs == “d�)

    ^

    new:73: error: stray ‘\200’ in program

    new:73: error: stray ‘\234’ in program

    new:73: error: stray ‘\342’ in program

    new:73: error: stray ‘\200’ in program

    new:73: error: stray ‘\235’ in program

    new:77: error: stray ‘\342’ in program

    else if(inputs == “E�)

    ^

    new:77: error: stray ‘\200’ in program

    new:77: error: stray ‘\234’ in program

    new:77: error: stray ‘\342’ in program

    new:77: error: stray ‘\200’ in program

    new:77: error: stray ‘\235’ in program

    new:81: error: stray ‘\342’ in program

    else if(inputs == “e�)

    ^

    new:81: error: stray ‘\200’ in program

    new:81: error: stray ‘\234’ in program

    new:81: error: stray ‘\342’ in program

    new:81: error: stray ‘\200’ in program

    new:81: error: stray ‘\235’ in program

    new:85: error: stray ‘\342’ in program

    else if(inputs == “F�)

    ^

    new:85: error: stray ‘\200’ in program

    new:85: error: stray ‘\234’ in program

    new:85: error: stray ‘\342’ in program

    new:85: error: stray ‘\200’ in program

    new:85: error: stray ‘\235’ in program

    new:89: error: stray ‘\342’ in program

    else if(inputs == “f�)

    ^

    new:89: error: stray ‘\200’ in program

    new:89: error: stray ‘\234’ in program

    new:89: error: stray ‘\342’ in program

    new:89: error: stray ‘\200’ in program

    new:89: error: stray ‘\235’ in program

    new:93: error: stray ‘\342’ in program

    else if(inputs == “G�)

    ^

    new:93: error: stray ‘\200’ in program

    new:93: error: stray ‘\234’ in program

    new:93: error: stray ‘\342’ in program

    new:93: error: stray ‘\200’ in program

    new:93: error: stray ‘\235’ in program

    new:97: error: stray ‘\342’ in program

    else if(inputs == “g�)

    ^

    new:97: error: stray ‘\200’ in program

    new:97: error: stray ‘\234’ in program

    new:97: error: stray ‘\342’ in program

    new:97: error: stray ‘\200’ in program

    new:97: error: stray ‘\235’ in program

    new:101: error: stray ‘\342’ in program

    else if(inputs == “H�)

    ^

    new:101: error: stray ‘\200’ in program

    new:101: error: stray ‘\234’ in program

    new:101: error: stray ‘\342’ in program

    new:101: error: stray ‘\200’ in program

    new:101: error: stray ‘\235’ in program

    new:105: error: stray ‘\342’ in program

    else if(inputs == “h�)

    ^

    new:105: error: stray ‘\200’ in program

    new:105: error: stray ‘\234’ in program

    new:105: error: stray ‘\342’ in program

    new:105: error: stray ‘\200’ in program

    new:105: error: stray ‘\235’ in program

    new:109: error: stray ‘\342’ in program

    inputs=��;

    ^

    new:109: error: stray ‘\200’ in program

    new:109: error: stray ‘\235’ in program

    new:109: error: stray ‘\342’ in program

    new:109: error: stray ‘\200’ in program

    new:109: error: stray ‘\235’ in program

    C:\Users\Awais\Desktop\new\new.ino: In function ‘void loop()’:

    new:36: error: expected primary-expression before ‘)’ token

    if (c == ‘#’){

    ^

    new:45: error: ‘A’ was not declared in this scope

    if(inputs == “A�)

    ^

    new:49: error: ‘a’ was not declared in this scope

    else if(inputs == “a�)

    ^

    new:53: error: ‘B’ was not declared in this scope

    else if(inputs == “B�)

    ^

    new:57: error: ‘b’ was not declared in this scope

    else if(inputs == “b�)

    ^

    new:61: error: ‘C’ was not declared in this scope

    else if(inputs == “C�)

    ^

    new:65: error: ‘c’ was not declared in this scope

    else if(inputs == “c�)

    ^

    new:69: error: ‘D’ was not declared in this scope

    else if(inputs == “D�)

    ^

    new:73: error: ‘d’ was not declared in this scope

    else if(inputs == “d�)

    ^

    new:77: error: ‘E’ was not declared in this scope

    else if(inputs == “E�)

    ^

    new:81: error: ‘e’ was not declared in this scope

    else if(inputs == “e�)

    ^

    new:85: error: ‘F’ was not declared in this scope

    else if(inputs == “F�)

    ^

    new:89: error: ‘f’ was not declared in this scope

    else if(inputs == “f�)

    ^

    new:93: error: ‘G’ was not declared in this scope

    else if(inputs == “G�)

    ^

    new:97: error: ‘g’ was not declared in this scope

    else if(inputs == “g�)

    ^

    new:101: error: ‘H’ was not declared in this scope

    else if(inputs == “H�)

    ^

    new:105: error: ‘h’ was not declared in this scope

    else if(inputs == “h�)

    ^

    new:109: error: expected primary-expression before ‘;’ token

    inputs=��;

    ^

    exit status 1
    stray ‘\342’ in program

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

  13. Arduino: 1.6.0 (Windows 7), Board: “Arduino Uno”

    /arduino-1.6.0/hardware/tools/avr/bin/avr-ar: unable to rename ‘C:\Users\dell\AppData\Local\Temp\build830993635132636886.tmp/core.a’; reason: Permission denied
    Error compiling.

    C:\Users\dell\AppData\Local\Temp\build830993635132636886.tmp/core.a(wiring.c.o): In function `delay’:
    C:\Users\dell\Downloads\Compressed\arduino-1.6.0\hardware\arduino\avr\cores\arduino/wiring.c:114: undefined reference to `yield’
    collect2: error: ld returned 1 exit status
    Error compiling.

    This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.

  14. hlo sir.these are the following errors i am facing.pls help
    Arduino: 1.8.5 (Windows 7), Board: “Arduino/Genuino Uno”

    Sketch uses 3932 bytes (12%) of program storage space. Maximum is 32256 bytes.
    Global variables use 236 bytes (11%) of dynamic memory, leaving 1812 bytes for local variables. Maximum is 2048 bytes.
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xc0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xc0

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

  15. sir sorry for inconvenience.the above problem solved by removing the bluetooth.
    but another problem arose.bluetooth module is on but the android app is still not able to scan the device.wht to do?

  16. Bro i done it.Thank you very much <3
    But ab ma es system k sath touchscreen attach krna chata hon. plzzz help me Bro…

  17. When i upload code to arduino then all relays are closed.. butt i want all relays open in initial condition.. help.. pllzz

Leave a Reply

Your email address will not be published. Required fields are marked *