Home automation with arduino, buttons ,LCD ,EEPROM AND Smart Phone


Introduction:

Home automation with arduino, buttons ,LCD ,EEPROM AND Smart Phone

Now we can control hull home with smart Phone


Step 1:

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

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

Files:
bt_4ch.ino

this is the wiring sequence of relay module and relay module

This program is only for bluetooth and relay module

#include

SoftwareSerial mySerial(1, 0); // 1-RX, 0-TX -

int ch1 = A0; int ch2 = A1; int ch3 = A2; int ch4 = A3;

void setup() { mySerial.begin(9600);

pinMode(ch1, OUTPUT); pinMode(ch2, OUTPUT); pinMode(ch3, OUTPUT); pinMode(ch4, OUTPUT);

}

void loop() {

char caracter = mySerial.read();

//--------------------------------ch1--------------------- if(caracter == 'A') { digitalWrite(ch1,HIGH);

}

if(caracter == 'a') { digitalWrite(ch1,LOW); } //---------------------------------ch1---------------------- //---------------------------------ch2--------------------- if(caracter == 'B') { digitalWrite(ch2,HIGH);

}

if(caracter == 'b') { digitalWrite(ch2,LOW); } //---------------------------------ch2---------------------- //---------------------------------ch3--------------------- if(caracter == 'C') { digitalWrite(ch3,HIGH);

}

if(caracter == 'c') { digitalWrite(ch3,LOW); } //---------------------------------ch3---------------------- //---------------------------------ch4--------------------- if(caracter == 'D') { digitalWrite(ch4,HIGH); }

if(caracter == 'd') { digitalWrite(ch4,LOW); } //---------------------------------ch4----------------------

delay(10); }

Step 4:

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)

#include
SoftwareSerial mySerial(1, 0); // 1-RX, 0-TX - #include 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)

void setup() { mySerial.begin(9600);

pinMode(ch1, OUTPUT); pinMode(ch2, OUTPUT); pinMode(ch3, OUTPUT); pinMode(ch4, OUTPUT);

lcd.begin(16, 2);

}

void loop() {

char caracter = mySerial.read();

//--------------------------------ch1--------------------- if(caracter == 'A') { digitalWrite(ch1,HIGH); lcd.setCursor(0, 0); lcd.print("r1 ON");

}

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"); }

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"); }

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"); }

if(caracter == 'd') { digitalWrite(ch4,LOW); lcd.setCursor(8, 1); lcd.print("r4 OFF"); } //---------------------------------ch4----------------------

delay(10); }

Step 5:

Adding Push Button in the project

Now we are adding Buttons

i use four button you can use it according to requirement

#include //

SoftwareSerial mySerial(1, 0); // 1-RX, 0-TX - #include

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);

pinMode(ch1, OUTPUT); pinMode(ch2, OUTPUT); pinMode(ch3, OUTPUT); pinMode(ch4, OUTPUT);

lcd.begin(16, 2);

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); }

void loop() {

char caracter = mySerial.read();

//--------------------------------ch1--------------------- if(caracter == 'A') { digitalWrite(ch1,HIGH); lcd.setCursor(0, 0); lcd.print("r1 ON");

}

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"); }

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"); }

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"); }

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"); }

delay(0); }

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

#include //

SoftwareSerial mySerial(1, 0); // 1-RX, 0-TX - #include

#include

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);

pinMode(ch1, OUTPUT); pinMode(ch2, OUTPUT); pinMode(ch3, OUTPUT); pinMode(ch4, OUTPUT);

lcd.begin(16, 2);

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);

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 } }

void loop() {

char caracter = mySerial.read();

//--------------------------------ch1--------------------- if(caracter == 'A') { digitalWrite(ch1,HIGH); lcd.setCursor(0, 0); lcd.print("r1 ON"); EEPROM.write(0, 1); }

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); }

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); }

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); }

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); }

delay(0); }

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

Add a Comment

Sign in to comment.