Introduction: Bluetooth Based Home Automation Via SmartPhone

As we know that our life is full automation. Either we are at home or in a car or either in a office. Now i am taking this step to make my home full automatic.As we also know that Smartphone is also present in our pocket. Then i have decided to make this system for my home.

In this instructable i will tech you

Make Android app for Bluetooth applications.

Make program for Arduino Bluetooth applications.

Make program for Computer Bluetooth applications (using Processing).

Assemble parts to make parts compatible with 110/220v.

Step 1: Hardware Required

For home automation we have different options but we are using for switching purpose.

Relay is the main source for switching we are also using relay for switching. Relay is that device through which we couple 5v with 110v/220v appliances.

Parts Required

  1. Arduino UNO
  2. Bluetooth Module HC-06
  3. Android Mobile Phone/Tablet
  4. Wires
  5. 5v Relay Module

If you want to make your own Relay module

  1. 5v Relay
  2. 1K ohm Resister
  3. c828 NPN Transister
  4. 4007 Diode

Step 2: Software Required

There are different software in this project we required.All the software have different functions.

For Android App making

MIT APP Inventor

This is an online Program for making android app.No need to download.

Its Language is known as Blocky. Blocky is a graphical Language which is easy for non programmers.

For Computer Software making

Processing

This software is use to make GUI interference and communi for PC to Bluetooth.

It has many languages but we are using JAVA.

For Arduino coding

Arduino IDE

This is an Offline and also Online programming platform.

This software is use for making Arduino code which is open Source and free for all.

Its programming language is C/C++.

Step 3: Make Arduino Program

Use Arduino IDE to make a code for Arduino UNO or MEGA.

First Step:-

Do wiring according to diagram as shown on the top.

Be careful don't make any mistake in wiring its burn your devices or make short circuit.

int ch1=A0; int ch2=A1; int ch3=A2; int ch4=A3; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(ch1,OUTPUT); pinMode(ch2,OUTPUT); pinMode(ch3,OUTPUT); pinMode(ch4,OUTPUT); }

void loop() { // put your main code here, to run repeatedly: char cha=Serial.read();

//............ch1........... if(cha == 'A'){ digitalWrite(ch1,HIGH); } if(cha == 'a'){ digitalWrite(ch1,LOW); } //...........ch1............ //............ch2........... if(cha == 'B'){ digitalWrite(ch2,HIGH); } if(cha == 'b'){ digitalWrite(ch2,LOW); } //...........ch2............ //............ch3........... if(cha == 'C'){ digitalWrite(ch3,HIGH); } if(cha == 'c'){ digitalWrite(ch3,LOW); } //...........ch3............ //............ch4........... if(cha == 'D'){ digitalWrite(ch4,HIGH); } if(cha == 'd'){ digitalWrite(ch4,LOW); } //...........ch4............

}

Step 4: Use MIT App Inventor to Make Android App

Use MIT App Inventor to make an online Android App.

This is a very strong and powerful program to make a Android App.

Its Programming Language is Blocky.

Use these step to operate MIT App Inventor

  1. Open MIT App Inventor website.
  2. First of all Login with Gmail Account.
  3. Then accept the agreement.
  4. Then press continue.
  5. When new page appear. Press Projects then press Import project (.aia) from my computer ...
  6. Upload WirelessSwitch.aia file present at the bottom.
  7. Press Build at the top App ( save .apk to my computer ) to download on Mobile or PC.

When file is uploaded modify the program according to requirement.

Direct download the app

Press download at bottom in which WirelessSwitch.apk is present at the bottom.

Step 5: Testing Android App With Arduino

Testing is the main process to check the error.

Follow these steps to check the error.

  1. Switch on the Bluetooth of Android Phone.
  2. Open the app.
  3. When app open, press Bluetooth to connect with the device.
  4. Then list of pair devices are shown select the device of hardware.
  5. If mobile connect with the device, then do the following process.
    1. Press ON1 to switch on the relay-1.
    2. Press OFF1 to switch off the relay-1.
    3. Do same with all.
    4. if any error arises check the wiring.

Step 6: Now Making Computer Software by Using Processing

Download Processing from Official Website

This software is best for beginners.If any one wants to make GUI program try this.The best thing about this program is that examples are present. Examples can make your work easy.Its user friendly for programmer.

<p>/**<br> * Background Image. 
 * 
 * This example presents the fastest way to load a background image
 * into Processing. To load an image as the background, it must be
 * the same width and height as the program.
 */</p><p>PImage bg;
int y;
import processing.serial.*;</p><p>Serial myPort;  // Create object from Serial class
int val;        // Data received from the serial port</p><p>void setup() {
  size(620, 349);
  // The background image must be the same size as the parameters
  // into the size() method. In this program, the size of the image
  // is 640 x 360 pixels.
  bg = loadImage("F93QKACIPR3K0AF.MEDIUM.jpg");
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}</p><p>void draw() {
  background(bg);
  if (mouseOverRect() == true) {  // If mouse is over square,
                     // change color and
    myPort.write('A');              // send an H to indicate mouse is over square
  } 
  else {                        // If mouse is not over square,
                         // change color and
    myPort.write('a');              // send an L otherwise
  }
         </p><p>}
boolean mouseOverRect() { // Test if mouse is over square
  return ((mouseX >= 0) && (mouseX <= 640) && (mouseY >= 0) && (mouseY <= 349));
}</p>

Now you have change only com-port.test the code because testing is very important for any error checking.

Step 7: Add EEPROM to Save the Last Status

EEPROM is internal memory of Arduino it is use to save small reading or small data.

Here we are using this to save the last status because if switch 1 is on. Suddenly main gone and again come we will restore that last status of switches.This is very important part of system.Without this the system is based on electricity.If electricity gone you will loose all the status.

Importance

  1. Save Readings
  2. Restore reading
  3. Save data for long time
  4. Easy to save,Restore and clear the memory

Code

EEPROM.read(address);

EEPROM.write(address,value);

[code]
#include int output1=A0; int output2=A1; int output3=A2; int output4=A3; int output5=A4;

int input1=2; int input2=3; int input3=4; int input4=5; int input5=6;

void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(output1,OUTPUT); pinMode(output2,OUTPUT); pinMode(output3,OUTPUT); pinMode(output4,OUTPUT); pinMode(output5,OUTPUT);

pinMode(input1,INPUT); digitalWrite(input1,HIGH); pinMode(input2,INPUT); digitalWrite(input2,HIGH); pinMode(input3,INPUT); digitalWrite(input3,HIGH); pinMode(input4,INPUT); digitalWrite(input4,HIGH); pinMode(input5,INPUT); digitalWrite(input5,HIGH);

if(EEPROM.read(1) == 1){ digitalWrite(output1,HIGH); } if(EEPROM.read(1) == 0){ digitalWrite(output1,LOW); } if(EEPROM.read(2) == 1){ digitalWrite(output2,HIGH); } if(EEPROM.read(2) == 0){ digitalWrite(output2,LOW); } if(EEPROM.read(3) == 1){ digitalWrite(output3,HIGH); } if(EEPROM.read(3) == 0){ digitalWrite(output3,LOW); } if(EEPROM.read(4) == 1){ digitalWrite(output4,HIGH); } if(EEPROM.read(4) == 0){ digitalWrite(output4,LOW); } if(EEPROM.read(5) == 1){ digitalWrite(output5,HIGH); } if(EEPROM.read(5) == 0){ digitalWrite(output5,LOW); } }

void loop() { // put your main code here, to run repeatedly: char cha=Serial.read(); if(cha == 'A'){ digitalWrite(output1,HIGH); EEPROM.write(1, 1); } if(cha == 'a'){ digitalWrite(output1,LOW); EEPROM.write(1, 0); } if(cha == 'B'){ digitalWrite(output2,HIGH); EEPROM.write(2, 1); } if(cha == 'b'){ digitalWrite(output2,LOW); EEPROM.write(2, 0); } if(cha == 'C'){ digitalWrite(output3,HIGH); EEPROM.write(3, 1); } if(cha == 'c'){ digitalWrite(output3,LOW); EEPROM.write(3, 0); } if(cha == 'D'){ digitalWrite(output4,HIGH); EEPROM.write(4, 1); } if(cha == 'd'){ digitalWrite(output4,LOW); EEPROM.write(4, 0); } if(cha == 'E'){ digitalWrite(output5,HIGH); EEPROM.write(5, 1); } if(cha == 'e'){ digitalWrite(output5,LOW); EEPROM.write(5, 0); }

if(digitalRead(input1) == LOW){ digitalWrite(output1,HIGH); delay(100); EEPROM.write(1, 1); while(digitalRead(input1) == LOW){ } } if(digitalRead(input1) == LOW){ digitalWrite(output1,LOW); delay(100); EEPROM.write(1, 0); while(digitalRead(input1) == LOW){ } } if(digitalRead(input2) == LOW){ digitalWrite(output2,HIGH); delay(100); EEPROM.write(2, 1); while(digitalRead(input2) == LOW){ } } if(digitalRead(input2) == LOW){ digitalWrite(output2,LOW); delay(100); EEPROM.write(2, 0); while(digitalRead(input2) == LOW){ } } if(digitalRead(input3) == LOW){ digitalWrite(output3,HIGH); delay(100); EEPROM.write(3, 1); while(digitalRead(input3) == LOW){ } } if(digitalRead(input3) == LOW){ digitalWrite(output3,LOW); delay(100); EEPROM.write(3, 0); while(digitalRead(input3) == LOW){ } } if(digitalRead(input4) == LOW){ digitalWrite(output4,HIGH); delay(100); EEPROM.write(4, 1); while(digitalRead(input4) == LOW){ } } if(digitalRead(input4) == LOW){ digitalWrite(output4,LOW); delay(100); EEPROM.write(4, 0); while(digitalRead(input4) == LOW){ } } if(digitalRead(input5) == LOW){ digitalWrite(output5,HIGH); delay(100); EEPROM.write(5, 1); while(digitalRead(input5) == LOW){ } } if(digitalRead(input5) == LOW){ digitalWrite(output5,LOW); delay(100); EEPROM.write(5, 0); while(digitalRead(input5) == LOW){ } } } [/code]

Comments