Project tutorial
Controlling Appliances Using Android Device and Arduino

Controlling Appliances Using Android Device and Arduino © GPL3+

This project is simple representation of home automation and can be installed with conventional switchboards too.

  • 1,700 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

Ide web
Arduino IDE
Bluetooth Terminal for Arduino
Use this app for code (without panel)
Bluetooth Electronics
Use this app for the code(to control with panel)

About this project

This project is based on an Arduino Uno. In this project, we perform the following operations using an Android device and an Arduino:

1) Control all the appliances via Android app through HC-05 Bluetooth module.

2) Turn all the room appliances off, when everyone leaves the room.

3) Read the temperature and humidity percentage of the room.

4) Count the number of people in the room. (Any other function, such as opening of door automatically, can be implemented instead.)

Hardware Connections

a) Bluetooth Connection

Ø The Vcc and Gnd of the module goes to Vcc and Gnd of Arduino.

Ø The TXD pin goes to RXD pin of Arduino and RXD pin goes to TXD pin of Arduino i.e (digital pin 0 and 1), for obtaining communication in b/w Bluetooth and board.

Pin Connections: As shown above

b) IR Proximity Sensor

Ø IR transmitter emits infrared light and another receiver (usually photo-transistor) receives that IR light after reflection.

Ø The module has both analog and digital output:

Analog output can be used to calculate the distance to the nearest object while

digital sensor can be used to trigger an action when the module detects an obstacle.

Analog pin read the distance to the nearest obstacle and outputs analog values.

The digital output can be connected to trigger an activity when the distance becomes below a threshold value.

The threshold value of distance can be controlled by adjusting the pot(Knob like structure (it’s a variable resistance).

Now in order to use proximity sensors to initiate any task as the person enters the room, we have to place the proximity sensors as such they can track the interruptions occurred due to entering of the person.Here two IR sensors are used.

By using this we can initiate any task such as Turn on of any room light, counting number of persons entered, opening and closing of gate automatically, turn off all the lights if no one is in the room(for this we can also install a PIR sensor), etc.

Here we only show the initiation of a counter using proximity sensors.

Pin Definition

· AO: This is the analog output pin from the sensor and should be connected to Analog input pin of microcontroller. If you are using an Arduino, this can be connected to any of the analog pins A0 through A5 (on UNO for example). Analog output from IR proximity sensor can be used to identify distance to the nearest obstacle (note that it varies with change in color of different materials).

· DO: The pin is connected to a pull-up resistor and will read high. You can adjust the pot to set a threshold value. When it crosses the threshold, the pin goes low and signal LED turns on. This setup is very useful when you need to trigger an action when certain threshold is reached.

· VCC: Positive power pin and this should be connected to VCC (or +5V) of your microcontroller.

· GND: Ground pin and this should be connected to GND(or 0V) of your microcontroller.

Pin Connection: [Vcc and Gnd must be taken from the board, you can use the same Vcc and gnd to supply other components using parallel connections.][(IR sensor 1) DO => pin 14;( IR sensor 2) DO => pin 19]

c) DHT11 Sensor

This is a sensor used to sense temperature and humidity. This sensor includes a resistive-type humidity measurement component and an non linear resistance (NTC) temperature measurement component.

When the connecting cable is shorter than 20 metres, a 5K pull-up resistor is recommended (otherwise the results may not be obtained); when the connecting cable is longer than 20 metres, choose a appropriate pull-up resistor as needed.

Power and Pin

DHT11’s power supply is 3-5.5V DC. When power is supplied to the sensor, do not send any instruction to the sensor in within one second in order to pass the unstable status. A capacitor of sufficient value can be added between VDD and GND for power filtering.

Pin Connection:- [VDD and GND msut be given as shown above in fig 4][ VDD(with 5k resistor)=> pin 6]

d) LCD Interfacing with the Arduino Module

Pin diagram and description of each pin have explained in the following table.

Pins Connection: [rs =>pin 10, en =>pin 9, d4 =>pin 5, d5 =>pin 4, d6 =>pin 3, d7 =>pin 7;]

LCD is used to display current temperature, humidity, etc.

e) Relay Board

Here I used a quad-channel relay board, which is a simple and convenient way to interface four relays for switching application.

Features:

Input supply 12 VDC @ 170 mA

Output four SPDT relay

Relay specification 5 A @ 230 VAC

Trigger level 2 ~ 5 VDC

Berg pins for connecting power and trigger voltage

LED on each channel indicates relay status

Power Battery Terminal (PBT) for easy relay output and aux power connection

Four mounting holes of 3.2 mm each

PCB dimensions 88 mm x 68 mm

Applications: Industrial controls, microwaves oven, fans, DC motor, AC lamp, solenoid remote controls, etc.

Relay Load (Contact Capacity of Relay)

7 A @ 230-250 VAC

10 A @ 120 VAC

10 A @ 24 VDC

CN1 – CN4 Connector : Relay 1 to 4 (S1 to S4) Output (Normally Open/Normally Close)

CN5 Connector : Control Signal Input, Trigger 2 to 5 VDC and Supply Input 12 VDC

D2, D4, D6, D8 : Relay On/Off LED Indication

CN6 Connector : Axillary Supply 12 VDC

Pins connections:[D2=>pin2; D3 => pin13; D4 => 12; D5 =>pin 11;VCC and VDD are connected to remaining VCC and Gnd pins of board or by taking supply and gnd from connections]

PIN Connections:

Code

CodeArduino
Use this code if you want to control only via terminal emulator app.
Upload this code on the android device.
Download any terminal emulator app from play store.
Now open the app and pair it with the hc 05.
Send commands as explained in the code.
#include <LiquidCrystal.h>
#include <SimpleDHT.h>
#include <Streaming.h>

int pinDHT11 = 6;                                                /* this pin is assigned to DHT sensor's output. The data from DHT is read from this pin of arduino*/
SimpleDHT11 dht11;                                               

const int rs = 10, en = 9, d4 = 5, d5 = 4, d6 = 3, d7 = 7;       /* these pins are assigned to the LCD(16x2), used to display temprature, humidity */   
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define in 14                                                    /* This pin is assigned to first proximity sensor's data, it actuates when a person enteres in the room*/ 
#define out 19                                                   /* This pin is assigned to second proximity sensor's data, it actuates when a person leaves the room*/  

#define relay1 2                                                /* this pin actuates when count value becomes greater than 1
                                                                   the count increases by 1 as the first proximity sensor actuates  
                                                                   the count decreaes by 1 as the second proximity sensor actuates*/                                                                     
int LED1 = 11;                                                 /* this pin actuates as the command ON1 and turns off when the command OFF1 is given through command line*/ 
int LED2 = 12;                                                 /* this pin actuates as the command ON2 and turns off when the command OFF2 is given through command line*/
int LED3 = 13;                                                 /* this pin actuates as the command ON3 and turns off when the command OFF3 is given through command line*/
String Data;                                                   /* All the pin actuates relay on, when command ONALL is given through command line*/ 
                                                               /* All the pin turns off relay, when command OFFALL is given through command line*/ 
int count = 0;                                                 /*This will increase as proximity sensor 1 actuates and decrements when proximity sesnsor 2 actuuates*/      

void IN()                                                      /*this function senses the actuation of proximity sensor 1*/
{                                                          
  count++;
  Serial.println("Person In ROOM\n");
  delay(1000);
}

void OUT()                                                     /*this function senses the actuation of proximity sensor 2*/
{
  count--;
  Serial.println("Person Leaves ROOM\n");
  if (count < 0)
  {
    count = 0;
  }
  
  delay(1000);
}

void irsensor() {                                                     // this function generates signal for the above two functions, this recieves the value of count, count here 
                                                                      // represents number of persons,as a person enters, proximity 1 will become high and increases count by 1 and if a   
  if ((digitalRead(in) || digitalRead(out)))                          // person leaves the room proximity 2 will become high and decrements the count by 1.
  {                                                                   // Now if count becomes more than one after zero, then the relay pin 2 output remains high and a single light will automatically
    if (digitalRead(in))                                              // turns on and if count becomes zero then all the appliances connected to relay gets off automatically.                                            
      IN();
    if (digitalRead(out))
      OUT();

    if (count > 0)
    {
      digitalWrite(relay1, LOW);
      delay(200);
    }
    else
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED3, HIGH);
      delay(200);
    }
    
  }

}

void btcontrol() {                                               // this is the function used for bluetooth communication with the arduino board. 
  if (Serial.available())                                        // this will recieves and send data to arduino to control the appliances connected to the relay
  { //wait for data receiverj                                    // by the help of terminal emulator 
    Data = Serial.readString();
    Serial.print(Data);
    if (Data == "ON1") {                                         //Send ON1 from terminal emulator to turn the appliance on connected to pin 3 of relay  
      digitalWrite(LED1, LOW);
      Serial.println("LED1\n");
      Serial.println("LED1 On!\n");
    }
    else if (Data == "OFF1") {                                   //Send OFF1 from terminal emulator to turn the appliance off connected to pin 3 of relay 
      digitalWrite(LED1, HIGH);
      Serial.println("LED1 Off!\n");
      Serial.println("LED1 Off !\n");
    }
    if (Data == "ON2") {                                         //Send ON2 from terminal emulator to turn the appliance on connected to pin 4 of relay                
      digitalWrite(LED2, LOW);
      Serial.println("LED2 On\n");
      Serial.println("LED2 On!\n");
    }
    else if (Data == "OFF2") {                                   //Send OFF2 from terminal emulator to turn the appliance off connected to pin 4 of relay  
      digitalWrite(LED2, HIGH);
      Serial.println("LED2 Off\n");
      Serial.println("LED2 Off !\n");
    }
    if (Data == "ON3") {                                         //Send ON5 from terminal emulator to turn the appliance on connected to pin 5 of relay    
      digitalWrite(LED3, LOW);
      Serial.println("LED3 On\n");
      Serial.println("LED3 On!\n");
    }
    else if (Data == "OFF3") {                                   //Send OFF5 from terminal emulator to turn the appliance off connected to pin 5 of relay      
      digitalWrite(LED3, HIGH);
      Serial.println("LED3 Off!\n");
      Serial.println("LED3 Off !\n");
    }
    if (Data == "ON4") {                                        //Send ON4 from terminal emulator to turn the appliance on connected to pin 2(i.e also actuated from IR sensor)of relay. 
      digitalWrite(relay1, LOW);
      Serial.println("relay1 On\n");
      Serial.println("relay1 On!\n");
    }
    else if (Data == "OFF4") {                                  //Send OFF4 from terminal emulator to turn the appliance off connected to pin 2 of relay 
      digitalWrite(relay1, HIGH);
      Serial.println("relay1 Off!\n");
      Serial.println("relay1 Off !\n");
    }
    if (Data == "ONALL") {                                      //Send ONALL from terminal emulator to turn all the appliances on which are connected to relay   
      digitalWrite(LED1, LOW);
      digitalWrite(LED2, LOW);
      digitalWrite(LED3, LOW);
      digitalWrite(relay1, LOW);
      Serial.println("LEDs ON\n");
      Serial.println("LEDs On!\n");
    }
    else if (Data == "OFFALL") {                                    //Send OFFALL from terminal emulator to turn all the appliances off which are connected to relay        
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED3, HIGH);
      digitalWrite(relay1, HIGH);
      Serial.println("LEDs Off!\n");
      Serial.println("LEDs OFF  !\n");
    }
  }
 
}

void temprature() {                                                           // This function is for DHT sensor which reads and writes the value of temperature and humidity  
  
  if (Data=="TEMP"){                                                         // Send Temp from terminal emulator to get the current temprature and humidity   
  
  Serial.println("=================================");
  Serial.println("DHT11 readings...");
  delay(2000);
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  
  if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("No reading , err="); Serial.println(err); delay(1000);
    return;
  }
  Serial.print("temp: ");
  Serial.print((int)temperature); Serial.print(" Celcius, ");
  Serial.print("humidity:");
  Serial.print((int)humidity); Serial.println(" %");
    
  lcd.clear();                                                   // this will print the data on the LCD display

  lcd.setCursor(0, 0);
  
  lcd.print("Temp: ");
  
  lcd.print((int)temperature);
  
  lcd.setCursor(0, 1);
  
  lcd.print("Humidity(%): ");
  
  lcd.print((int)humidity);
  delay(750);
  
  }
}

void setup()                                                                   // This is the function used to initiate the program
{
  Serial.begin(9600);

  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  Serial.println("Waiting for command...");
  Serial.println("Send ON'X' to turn on the LED. Send OFF'X' to turn Off");

  digitalWrite(relay1, HIGH);
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  digitalWrite(pinDHT11,HIGH);
  
  lcd.begin(16, 2);

}

void loop()
{
  if ((digitalRead(in) || digitalRead(out)))
  {
    irsensor();
  }
  if (Serial.available())
  {
    btcontrol();
  }
  temprature();
  
}
Code(to control with panel panel)Arduino
This code is used with the panel file, which is a .kwl file.
Upload this code in the arduino.
Then on the android device download the following software:-
https://play.google.com/store/apps/details?id=com.keuwl.arduinobluetooth&hl=en
Now open the bluetooth electronics app
Now download and paste the Mini pronect (1).kwl file in the keuwlsoft folder in the file manager.
Now go back to the app and click on save icon, on the top left of the app.
Then click on Load Panels.
Then upload this file into the software as panel as follows
Now Click on connect and pair yor android device with the HC 05
The uploaded panel is now showing in the list, click on it to open.
#include <LiquidCrystal.h>
#include <SimpleDHT.h>
#include <Streaming.h>
int pinDHT11 = 6;

SimpleDHT11 dht11;
const int rs = 10, en = 9, d4 = 5, d5 = 4, d6 = 3, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define in 14
#define out 19
#define relay1 2
int LED1 = 11; // the on-board LED
int LED2 = 12;
int LED3 = 13;
String Data; // the data received
int count = 0;

void IN()
{
  count++;
  Serial.println("Person In ROOM\n");
  delay(1000);
}

void OUT()
{
  count--;
  Serial.println("Person Leaves ROOM\n");
  if (count < 0)
   {
     count = 0;
   }
  
  delay(1000);
}

void irsensor() {

  if ((digitalRead(in) || digitalRead(out)))
  {
    if (digitalRead(in))
      IN();
    if (digitalRead(out))
      OUT();

    if (count > 0)
    {
      digitalWrite(relay1, LOW);
      delay(200);
    }
    else
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED3, HIGH);
    }
    Serial.print(count); Serial <<"*P" << (count) << "*" <<endl;
    Serial.println("\n");
  }
}
void btcontrol() {
  if (Serial.available())
  { //wait for data receiverj
    Data = Serial.readString();
    Serial.print(Data);
    if (Data == "ON1"&&(digitalRead(LED1))) {
      digitalWrite(LED1, LOW);
      Serial.println("LED1\n");
      Serial.println("LED1 On!\n");
      }
    else if (Data == "OFF1"&&(!digitalRead(LED1))) {
      digitalWrite(LED1, HIGH);
      Serial.println("LED1 Off!\n");
      Serial.println("LED1 Off !\n");
     }
    if (Data == "ON2"&&(digitalRead(LED2))) {
      digitalWrite(LED2, LOW);
      Serial.println("LED2 On\n");
      Serial.println("LED2 On!\n");
    }
    else if (Data == "OFF2"&&(!digitalRead(LED2))) {
      digitalWrite(LED2, HIGH);
      Serial.println("LED2 Off\n");
      Serial.println("LED2 Off !\n");
     
    }
    if (Data == "ON3"&&(digitalRead(LED3))) {
      digitalWrite(LED3, LOW);
      Serial.println("LED3 On\n");
      Serial.println("LED3 On!\n");
     
    }
    else if (Data == "OFF3"&&(!digitalRead(LED3))) {
      digitalWrite(LED3, HIGH);
      Serial.println("LED3 Off!\n");
      Serial.println("LED3 Off !\n");
     
    }
    if (Data == "ON4"&&(digitalRead(relay1))) {
      digitalWrite(relay1, LOW);
      Serial.println("relay1 On\n");
      Serial.println("relay1 On!\n");
     
    }
    else if (Data == "OFF4"&&(!digitalRead(relay1))) {
      digitalWrite(relay1, HIGH);
      Serial.println("relay1 Off!\n");
      Serial.println("relay1 Off !\n");
     
    }
    if (Data == "ONALL") {
      digitalWrite(LED1, LOW);
      digitalWrite(LED2, LOW);
      digitalWrite(LED3, LOW);
      digitalWrite(relay1, LOW);
      Serial.println("LEDs ON\n");
      Serial.println("LEDs On!\n");
    }
    else if (Data == "OFFALL") {
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED3, HIGH);
      digitalWrite(relay1, HIGH);
      Serial.println("LEDs Off!\n");
      Serial.println("LEDs OFF  !\n");
    }
      
  }
}

void temprature() {
  irsensor();
  if (Data=="TEMP"){
  
  Serial.println("=================================");
  Serial.println("DHT11 readings...");
  delay(2000);
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  
  if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("No reading , err="); Serial.println(err); delay(1000);
    return;
  }
  Serial.print("temp: ");
  Serial.print((int)temperature); Serial.print(" Celcius, ");
  Serial.print("humidity:");
  Serial.print((int)humidity); Serial.println(" %");
  Serial <<"*T" <<(int)temperature << "*" <<endl;
  Serial <<"*H" << ((int)humidity) << "*" <<endl;
    
  lcd.clear();

  lcd.setCursor(0, 0);
  
  lcd.print("Temp: ");
  
  lcd.print((int)temperature);
  
  lcd.setCursor(0, 1);
  
  lcd.print("Humidity(%): ");
  
  lcd.print((int)humidity);
  delay(750);
  
  }
}

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

  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  Serial.println("Waiting for command...");
  Serial.println("Send ON'X' to turn on the LED. Send OFF'X' to turn Off");

  digitalWrite(relay1, HIGH);
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  digitalWrite(pinDHT11,HIGH);
  
  lcd.begin(16, 2);

}

void loop()
{
  if ((digitalRead(in) || digitalRead(out)))
  {
    irsensor();
  }
  if (Serial.available())
  {
    btcontrol();
  }
  temprature();
   statuS();
  }
void statuS(){
 
if(!digitalRead(LED1))
Serial.print("*A1=ON*");
 if(digitalRead(LED1))
Serial.print("*A1=Off*");  
 if(!digitalRead(LED2))
Serial.print("*B2=ON*");
 if(digitalRead(LED2))
Serial.print("*B2=Off*");  
 if(!digitalRead(LED3))
Serial.print("*C3=ON*");
 if(digitalRead(LED3))
Serial.print("*C3=Off*");  
 if(!digitalRead(relay1))
Serial.print("*D4=ON*");
 if(digitalRead(relay1))
Serial.print("*D4=Off*"); 
 if(!digitalRead(LED1)&&!digitalRead(LED2)&& !digitalRead(LED3)&& !digitalRead(relay1))
Serial.print("*EALL=ON*"); 
 if(digitalRead(LED1)&&digitalRead(LED2)&&digitalRead(LED3)&&digitalRead(relay1))
Serial.print("*EALL=Off*"); 

}

Schematics

Schematics
Homeautomate kczkdmsxqb

Comments

Similar projects you might like

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 43,118 views
  • 21 comments
  • 121 respects

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 3,617 views
  • 2 comments
  • 16 respects

Controlling A Roomba Robot With Arduino And Android Device

Project tutorial by MJRoBot

  • 14,657 views
  • 4 comments
  • 16 respects

Control Home Appliances Through Web Or Mobile

Project tutorial by Team Gadget Programmers

  • 9,843 views
  • 4 comments
  • 22 respects

Arduino Uno + Electrical Device (Bulb) + Android Phone

Project tutorial by Stephen Simon

  • 9,785 views
  • 9 comments
  • 40 respects

Two Mode Robot Controlling through Android and Windowsphone8

Project tutorial by Muhammad Anas

  • 19,208 views
  • 10 comments
  • 53 respects
Add projectSign up / Login