Introduction: Home Automation With Arduino, Buttons ,LCD ,EEPROM AND Smart Phone

Picture of Home Automation With Arduino, Buttons ,LCD ,EEPROM AND Smart Phone

Now we can control full home with smart Phone

Step 1: Hardware Required

Picture of Hardware Required

for home automation you can add different things i choose switching or relay

In this project you will control switcher by mobile .if mobile is not present you can also operate with keypad

I also add lcd in the project to see the the present status of switches.

hardware required in this project

Android Mobile

jumper cables

16 * 2 LCD display

HC-06 Bluetooth Module

Arduino uno or MEGA

Bread Board

10k ohm varible for LCD

Relay Module

For making own relay Module

Relay

Transister

Resisters

PCB board

Step 2: Software Required

Picture of Software Required

https://play.google.com/store/apps/details?id=com....

Download this app for home automation it can control 8 relay at a time

Its also have a timer.

To program on arduino use Arduino IDE which is available on

https://www.arduino.cc/en/Main/Software

Step 3: Programming for Bluetooth Module and Relay Module

Picture of Programming for  Bluetooth Module and Relay Module

this is the wiring sequence of relay module and relay module

This program is only for bluetooth and relay module

<p>#include <SoftwareSerial,h></p><p></p><p>SoftwareSerial mySerial(0, 1); // 1-RX, 0-TX - </p><p>int ch1 =  A0;
int ch2 =  A1;
int ch3 =  A2;
int ch4 =  A3;</p><p> void setup()
 {
 mySerial.begin(9600);</p><p> 
 pinMode(ch1, OUTPUT);
 pinMode(ch2, OUTPUT);
 pinMode(ch3, OUTPUT);
 pinMode(ch4, OUTPUT);</p><p> }</p><p> void loop()
{</p><p> char caracter = mySerial.read();</p><p> //--------------------------------ch1---------------------
 if(caracter == 'A')
{
 digitalWrite(ch1,HIGH);
 </p><p>}</p><p>if(caracter == 'a')
{
 digitalWrite(ch1,LOW);
 
}
//---------------------------------ch1----------------------
//---------------------------------ch2---------------------
 if(caracter == 'B')
{
 digitalWrite(ch2,HIGH);</p><p>}</p><p>if(caracter == 'b')
{
 digitalWrite(ch2,LOW);
 
}
//---------------------------------ch2----------------------
//---------------------------------ch3---------------------
 if(caracter == 'C')
{
 digitalWrite(ch3,HIGH);</p><p>}</p><p>if(caracter == 'c')
{
 digitalWrite(ch3,LOW);
  
}
//---------------------------------ch3----------------------
//---------------------------------ch4---------------------
 if(caracter == 'D')
{
 digitalWrite(ch4,HIGH);
 
}</p><p>if(caracter == 'd')
{
 digitalWrite(ch4,LOW);
  
}
//---------------------------------ch4----------------------</p><p> delay(10);
}</p>

Step 4: Now Adding LCD With Arduino

Picture of Now Adding LCD With Arduino

* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11

* LCD D4 pin to digital pin 5

* LCD D5 pin to digital pin 4

* LCD D6 pin to digital pin 3

* LCD D7 pin to digital pin 2

* LCD R/W pin to ground

* 10K resistor:

* ends to +5V and ground

* wiper to LCD VO pin (pin 3)

<p>#include <SoftwareSerial.h><br> SoftwareSerial mySerial(0, 1);  
#include <LiquidCrystal.h>

int ch1 =  A0;
int ch2 =  A1;
int ch3 =  A2;
int ch4 =  A3;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);;//(rs, enable, d4, d5, d6, d7) </p><p> void setup()
 {
 mySerial.begin(9600);</p><p> 
 pinMode(ch1, OUTPUT);
 pinMode(ch2, OUTPUT);
 pinMode(ch3, OUTPUT);
 pinMode(ch4, OUTPUT);</p><p>lcd.begin(16, 2);</p><p> }</p><p> void loop()
{</p><p> char caracter = mySerial.read();</p><p> //--------------------------------ch1---------------------
 if(caracter == 'A')
{
 digitalWrite(ch1,HIGH);
 lcd.setCursor(0, 0);
 lcd.print("r1 ON");</p><p>}</p><p>if(caracter == 'a')
{
 digitalWrite(ch1,LOW);
 lcd.setCursor(0, 0);
 lcd.print("r1 OFF");
}
//---------------------------------ch1----------------------
//---------------------------------ch2---------------------
 if(caracter == 'B')
{
 digitalWrite(ch2,HIGH);
 lcd.setCursor(8, 0);
 lcd.print("r2 ON");
}</p><p>if(caracter == 'b')
{
 digitalWrite(ch2,LOW);
  lcd.setCursor(8, 0);
 lcd.print("r2 OFF");
}
//---------------------------------ch2----------------------
//---------------------------------ch3---------------------
 if(caracter == 'C')
{
 digitalWrite(ch3,HIGH);
  lcd.setCursor(0, 1);
 lcd.print("r3 ON");
}</p><p>if(caracter == 'c')
{
 digitalWrite(ch3,LOW);
  lcd.setCursor(0, 1);
 lcd.print("r3 OFF");
}
//---------------------------------ch3----------------------
//---------------------------------ch4---------------------
 if(caracter == 'D')
{
 digitalWrite(ch4,HIGH);
  lcd.setCursor(8, 1);
 lcd.print("r4 ON");
}</p><p>if(caracter == 'd')
{
 digitalWrite(ch4,LOW);
  lcd.setCursor(8, 1);
 lcd.print("r4 OFF");
}
//---------------------------------ch4----------------------</p><p> delay(10);
}</p>

Step 5: Adding Push Button in the Project

Picture of Adding Push Button in the Project

Now we are adding Buttons

i use four button you can use it according to requirement

<p>#include <SoftwareSerial.h> //</p><p> SoftwareSerial mySerial(0, 1); // 1-RX, 0-TX - 
#include <LiquidCrystal.h></p><p>int ch1 =  A0;
int ch2 =  A1;
int ch3 =  A2;
int ch4 =  A3;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);;//(rs, enable, d4, d5, d6, d7) 
int switchPin[] = {6,7,8,9};
 void setup()
 {
 mySerial.begin(9600);</p><p> 
 pinMode(ch1, OUTPUT);
 pinMode(ch2, OUTPUT);
 pinMode(ch3, OUTPUT);
 pinMode(ch4, OUTPUT);</p><p>lcd.begin(16, 2);</p><p>pinMode(switchPin[0], INPUT);
  digitalWrite(switchPin[0], HIGH);
  pinMode(switchPin[1], INPUT);
  digitalWrite(switchPin[1], HIGH);
  pinMode(switchPin[2], INPUT);
  digitalWrite(switchPin[2], HIGH);
  pinMode(switchPin[3], INPUT);
  digitalWrite(switchPin[3], HIGH);
   pinMode(switchPin[4], INPUT);
  digitalWrite(switchPin[4], HIGH);
 }</p><p> void loop()
{</p><p> char caracter = mySerial.read();</p><p> //--------------------------------ch1---------------------
 if(caracter == 'A')
{
 digitalWrite(ch1,HIGH);
 lcd.setCursor(0, 0);
 lcd.print("r1  ON");</p><p>}</p><p>if(caracter == 'a')
{
 digitalWrite(ch1,LOW);
 lcd.setCursor(0, 0);
 lcd.print("r1 OFF");
}
//---------------------------------ch1----------------------
//---------------------------------ch2---------------------
 if(caracter == 'B')
{
 digitalWrite(ch2,HIGH);
 lcd.setCursor(8, 0);
 lcd.print("r2  ON");
}</p><p>if(caracter == 'b')
{
 digitalWrite(ch2,LOW);
  lcd.setCursor(8, 0);
 lcd.print("r2 OFF");
}
//---------------------------------ch2----------------------
//---------------------------------ch3---------------------
 if(caracter == 'C')
{
 digitalWrite(ch3,HIGH);
  lcd.setCursor(0, 1);
 lcd.print("r3  ON");
}</p><p>if(caracter == 'c')
{
 digitalWrite(ch3,LOW);
  lcd.setCursor(0, 1);
 lcd.print("r3 OFF");
}
//---------------------------------ch3----------------------
//---------------------------------ch4---------------------
 if(caracter == 'D')
{
 digitalWrite(ch4,HIGH);
  lcd.setCursor(8, 1);
 lcd.print("r4  ON");
}</p><p>if(caracter == 'd')
{
 digitalWrite(ch4,LOW);
  lcd.setCursor(8, 1);
 lcd.print("r4 OFF");
}
//---------------------------------ch4----------------------
if (digitalRead(switchPin[0]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch1, HIGH) ; 
      lcd.setCursor(0, 0);
 lcd.print("r1  ON"); 
  }
  if (digitalRead(switchPin[0]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch1, LOW) ;
       lcd.setCursor(0, 0);
 lcd.print("r1 OFF"); 
  }
   if (digitalRead(switchPin[1]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch2, HIGH) ;
       lcd.setCursor(8, 0);
 lcd.print("r2  ON");
  }
  if (digitalRead(switchPin[1]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch2, LOW) ;
        lcd.setCursor(8, 0);
 lcd.print("r2 OFF"); 
  }
  if (digitalRead(switchPin[2]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch3, HIGH) ;
 lcd.setCursor(0, 1);
 lcd.print("r3  ON");
  }
  if (digitalRead(switchPin[2]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch3, LOW) ;
         lcd.setCursor(0, 1);
 lcd.print("r3 OFF");
  }
   if (digitalRead(switchPin[3]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch4, HIGH) ; 
        lcd.setCursor(8, 1);
 lcd.print("r4  ON");// toggle running variable
        
  }
  if (digitalRead(switchPin[3]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch4, LOW) ;
          lcd.setCursor(8, 1);
 lcd.print("r4 OFF");
  }</p><p> delay(0);
}</p>

Step 6: Now We Are Using EEPROM to Save Last Status of Switches

Using EEPROM

I am adding internal EEPROM to save the last status

If the device go out of power and again connected

it load the last status of switches

those switches which are on before power off now they are still on

<p>#include <SoftwareSerial.h> //</p><p> SoftwareSerial mySerial(1, 0); // 1-RX, 0-TX - 
#include <LiquidCrystal.h></p><p>#include <EEPROM.h></p><p>int ch1 =  A0;
int ch2 =  A1;
int ch3 =  A2;
int ch4 =  A3;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);;//(rs, enable, d4, d5, d6, d7) 
int switchPin[] = {6,7,8,9};
 void setup()
 {
 mySerial.begin(9600);</p><p> 
 pinMode(ch1, OUTPUT);
 pinMode(ch2, OUTPUT);
 pinMode(ch3, OUTPUT);
 pinMode(ch4, OUTPUT);</p><p>lcd.begin(16, 2);</p><p>pinMode(switchPin[0], INPUT);
  digitalWrite(switchPin[0], HIGH);
  pinMode(switchPin[1], INPUT);
  digitalWrite(switchPin[1], HIGH);
  pinMode(switchPin[2], INPUT);
  digitalWrite(switchPin[2], HIGH);
  pinMode(switchPin[3], INPUT);
  digitalWrite(switchPin[3], HIGH);
   pinMode(switchPin[4], INPUT);
  digitalWrite(switchPin[4], HIGH);</p><p>  if (EEPROM.read(0) == 1)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch1, HIGH) ; 
       lcd.setCursor(0, 0);
 lcd.print("r1  ON");
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(0) == 0)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch1, LOW) ;
       lcd.setCursor(0, 0);
 lcd.print("r1 OFF"); 
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(1) == 1)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch2, HIGH) ;
       lcd.setCursor(8, 0);
 lcd.print("r2  ON"); 
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(1) == 0)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch2, LOW) ;
        lcd.setCursor(8, 0);
 lcd.print("r2 OFF"); 
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(2) == 1)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch3, HIGH) ; 
       lcd.setCursor(0, 1);
 lcd.print("r3  ON");
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(2) == 0)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch3, LOW) ; 
       lcd.setCursor(0, 1);
 lcd.print("r3 OFF");
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(3) == 1)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch4, HIGH) ; 
       lcd.setCursor(8, 1);
 lcd.print("r4  ON");
        // toggle running variable
          // indicate via LED
  }
  if (EEPROM.read(3) == 0)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch4, LOW) ; 
       lcd.setCursor(8, 1);
 lcd.print("r3 OFF");
        // toggle running variable
          // indicate via LED
  }
 }
 </p><p> void loop()
{</p><p> char caracter = mySerial.read();</p><p> //--------------------------------ch1---------------------
 if(caracter == 'A')
{
 digitalWrite(ch1,HIGH);
 lcd.setCursor(0, 0);
 lcd.print("r1  ON");
EEPROM.write(0, 1);
}</p><p>if(caracter == 'a')
{
 digitalWrite(ch1,LOW);
 lcd.setCursor(0, 0);
 lcd.print("r1 OFF");
 EEPROM.write(0, 0);
}
//---------------------------------ch1----------------------
//---------------------------------ch2---------------------
 if(caracter == 'B')
{
 digitalWrite(ch2,HIGH);
 lcd.setCursor(8, 0);
 lcd.print("r2  ON");
 EEPROM.write(1, 1);
}</p><p>if(caracter == 'b')
{
 digitalWrite(ch2,LOW);
  lcd.setCursor(8, 0);
 lcd.print("r2 OFF");
 EEPROM.write(1, 0);
}
//---------------------------------ch2----------------------
//---------------------------------ch3---------------------
 if(caracter == 'C')
{
 digitalWrite(ch3,HIGH);
  lcd.setCursor(0, 1);
 lcd.print("r3  ON");
 EEPROM.write(2, 1);
}</p><p>if(caracter == 'c')
{
 digitalWrite(ch3,LOW);
  lcd.setCursor(0, 1);
 lcd.print("r3 OFF");
 EEPROM.write(2, 0);
}
//---------------------------------ch3----------------------
//---------------------------------ch4---------------------
 if(caracter == 'D')
{
 digitalWrite(ch4,HIGH);
  lcd.setCursor(8, 1);
 lcd.print("r4  ON");
 EEPROM.write(3, 1);
}</p><p>if(caracter == 'd')
{
 digitalWrite(ch4,LOW);
  lcd.setCursor(8, 1);
 lcd.print("r4 OFF");
 EEPROM.write(3, 0);
}
//---------------------------------ch4----------------------
if (digitalRead(switchPin[0]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch1, HIGH) ; 
      lcd.setCursor(0, 0);
 lcd.print("r1  ON");
 EEPROM.write(0, 1); 
  }
  if (digitalRead(switchPin[0]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch1, LOW) ;
       lcd.setCursor(0, 0);
 lcd.print("r1 OFF");
 EEPROM.write(0, 0); 
  }
   if (digitalRead(switchPin[1]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch2, HIGH) ;
       lcd.setCursor(8, 0);
 lcd.print("r2  ON");
  EEPROM.write(1, 1);
  }
  if (digitalRead(switchPin[1]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch2, LOW) ;
        lcd.setCursor(8, 0);
 lcd.print("r2 OFF");
 EEPROM.write(1, 0); 
  }
  if (digitalRead(switchPin[2]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch3, HIGH) ;
 lcd.setCursor(0, 1);
 lcd.print("r3  ON");
 EEPROM.write(2, 1);
  }
  if (digitalRead(switchPin[2]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch3, LOW) ;
         lcd.setCursor(0, 1);
 lcd.print("r3 OFF");
  EEPROM.write(2, 0);
  }
   if (digitalRead(switchPin[3]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
       digitalWrite(ch4, HIGH) ; 
        lcd.setCursor(8, 1);
 lcd.print("r4  ON");// toggle running variable
        EEPROM.write(3, 1);
  }
  if (digitalRead(switchPin[3]) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
        digitalWrite(ch4, LOW) ;
          lcd.setCursor(8, 1);
 lcd.print("r4 OFF");
  EEPROM.write(3, 0);
  }</p><p> delay(0);
}</p>

Step 7: Adding Sensers in the Project

If you want to add senser i think Arduino MEGA is Better because it has more pins than uno

if you want to use Arduino UNO Than use Shields

Comments

IvanR1 (author)2016-06-28

Interesting, thanks!

awaiskhawar (author)IvanR12016-06-28

Thanks for feedback

Gul asfand (author)awaiskhawar2017-01-31

Lcd can not show any character ,if upload the code . what i do ?

awaiskhawar (author)Gul asfand2017-01-31

Add step 4,5 or 6 code.

Or
Contact me on whatsapp
+923065090466

PrashantM38 (author)2016-09-02

I was able to do it with HC-05 Bluetooth. Renaming the Default Name of bluetooth would have helped in this (which i did ...research)..Thanks

awaiskhawar (author)PrashantM382016-09-02

yes you can use it hc-05 in slave mode

TarekM2 made it! (author)2016-07-17

G.T

RaheelA13 (author)2016-07-03

Great man

Saliksheraz (author)2016-07-02

O Great bro thanks really amazing it is I will insha Allah try it after my test for nust

M. TahaA (author)2016-07-02

Good work bro ! Keep it up (Y)

qwaqar8 (author)2016-07-02

Let's plan it on a large scale

Shah SaudK (author)2016-07-02

Well done good job

awaiskhawar (author)Shah SaudK2016-07-02

Thanks man

HubertC (author)2016-07-02

Thanks

HubertC (author)2016-07-02

I do not believe the first one works because the <p></p> does not register with the arduino.

awaiskhawar (author)HubertC2016-07-02

See down .ino file is available go and download from there

When i paste program from pc
Then this will appear

DavidJ202 (author)2016-06-28

In all of your schematics (except the first one in step 3), you have the Vcc of the bluetooth module connected to ground!! I take it that is a mistake??

awaiskhawar (author)DavidJ2022016-06-28

Haha
Thanks for telling

SideTracked350 (author)2016-06-28

can this be set up so no 2 switches can be turned on at the same time? IE: if you activate one the previously active one switches off. Im looking for something like this (modified) to prevent my GF from using 2 appliances at once such as the toaster and AC because it trips the breaker and the super is about ready to put up a "NO Air Conditioner" policy if she keeps popping the breaker.

If you want to make contact me personally

Yes possible

When you on the toster Ac become off at that time. When you off the toster ac become on again

jjussi (author)2016-06-28

Do it really works, those buttons.. Because your code says:

if (digitalRead(switchPin[0]) == LOW)

{ // switch is pressed - pullup keeps pin high normally

digitalWrite(ch1, HIGH) ;

lcd.setCursor(0, 0);

lcd.print("r1 ON");

EEPROM.write(0, 1);

}

if (digitalRead(switchPin[0]) == LOW)

{ // switch is pressed - pullup keeps pin high normally

digitalWrite(ch1, LOW) ;

lcd.setCursor(0, 0);

lcd.print("r1 OFF");

EEPROM.write(0, 0);

}

If I press button 1, first 'if' catch it.. Ok.. After that if {...} button is still down and second 'if' is true too.. So, first we set relay to ON and right after we turn it OFF..

You should have something like:

if (digitalRead(switchPin[0]) == LOW && pin0 == false) { pin0=true};

if (digitalRead(switchPin[0]) == HIGH && pin0 == true)

{

pin0=false;

pin0status=pin0status==HIGH?LOW:HIGH;

digitalWrite(ch1,pin0status);

// do rest of stuff...

}

awaiskhawar (author)jjussi2016-06-28

Yes its work i check it first. Then i upload

Load this on arduino then see the result

Anerek (author)2016-06-28

Is there an IOs version of this software, for the iPhone?

About This Instructable

34,137views

522favorites

Bio: I love electronics .Arduino automation
More by awaiskhawar:Bluetooth Based Home Automation Via SmartPhoneWrite any thing on LCD with One button with Arduino its a gameAutomatic garden watering system BY arduino, LCD,  Buttons, EEPROM, solenoid valve, Motor and underground sprinkler
Add instructable to: