Bluetooth Controlled Home Automation System using 8051

embedded

BySaddam 90

Bluetooth Controlled Home Automation System Using 8051 Microcontroller

Imagine that you can control the electronic appliances of your home from anywhere inside the house, just using your Smart phone. In this project, we will use wireless Bluetooth technology to control the Home Electronic Appliances through a Android Phone. Bluetooth has a range of 10-15 meters, so that you can switch ON and OFF any electronic appliance within the range. We have also developed a Toy car controlled by Android Phone, using Bluetooth module and Arduino.

 

Here we have used 8051 microcontroller with a Bluetooth module, for wirelessly receive the data, sent from the Android Phone. So that microcontroller can Turn ON and OFF the home appliances accordingly. [Check here more 8051 microcontroller based projects]

 

Main Components

  • 8051 microcontroller
  • Bluetooth Module HC05
  • Relay
  • ULN2003
  • Bulb
  • Holder
  • Wire
  • IC 7805
  • Android phone
  • Bluetooth controller app Android app
  • 10uf capacitor
  • 1000uf capacitor
  • 10K resistor
  • 1k resistor
  • Power Supply

Bluetooth Module:

 HC-05 Bluetooth module consists two things one is Bluetooth serial interface module and a Bluetooth adaptor. Bluetooth serial module is used for converting serial port to Bluetooth.

Bluetooth-Module-HC-05

How to operate Bluetooth module?

You can directly use the Bluetooth module after purchasing from market, because there is no need to change any setting of Bluetooth module. Default baud rate of new Bluetooth module is 9600 bps. You just need to connect rx and tx to controller or serial converter and give 5 volt dc regulated power supply to module.

 

Bluetooth module has two modes one is master mode and second one is slave mode. User can set either mode by using some AT commands. Even user can set module’s setting by using AT command. Here is some commands uses are given:

First of all user need to enter AT mode with 38400 bps baud rate by pressing EN button at Bluetooth module or by giving HIGH level at EN pin. Note: all commands should ends with \r\n (0x0d and 0x0a) or ENTER KEY from keyboard.

After it if you send AT to module then module will respond with OK

AT → Test Command

AT+ROLE=0 → Slave Mode select

AT+ROLE=1 → Master Mode select

AT+NAME=xyz  → Set Bluetooth Name

AT+PSWD=xyz → Set Password

AT+UART=<value1>,<value2>,<value3>  → set Baud rate

Eg. AT+UART=9600,0,0

 

Pin Description of accelerometer:

  1. STATE  → Open
  2. Rx  → Serial receiving pin
  3. Tx  → Serial transmitting pin
  4. GND   → ground
  5. Vcc     → +5volt dc
  6. EN       → to enter in AT mode
  7.  

Working Explanation: 

In this project we have used 8051 microcontroller for controlling the whole process of this project. And a Bluetooth module is used for controlling the home appliances wirelessly. Home appliances will turned ON and OFF when user will touch button in the Bluetooth mobile app in Android mobile phone. To run this project, first we need to download Bluetooth app form Google play store. We can use any Bluetooth app that can send data using Bluetooth. Here are some apps name that can be used:

  1. Bluetooth Spp pro
  2. Bluetooth controller

After installing the App, you need to open it and then search Bluetooth device and select HC-05 Bluetooth device. And then configure keys.

Here in this project we have used Bluetooth controller app.

  1. Download and install Bluetooth Controller.
  2. Turned ON mobile Bluetooth.
  3. Now open Bluetooth controller app
  4. Press scan
  5. Select desired Bluetooth device (Bluetooth Module HC-05).
  6. Now set keys by pressing set buttons on screen

To set keys we need to press ‘set button’ and set key according to picture given below:

Bluetooth controller app for home automation

After setting keys press ok.

You can see in the above picture that there are 9 buttons in which first row is for fan controlling, second one is for light controlling and last one is for TV controlling.  Means First row’s ON and OFF buttons are used to ON and OFF the fan, second row’s buttons are for Light and third ones are for TV. We have used three bulbs of different colors instead of TV and fan, for demonstration purpose.

 

Now, when we touch any button in Bluetooth controller app then Android phone sends a value to Bluetooth module, after receiving this value, Bluetooth module sends the received value to the microcontroller and then microcontroller reads it and compare it with predefined value. If any match is occurred then microcontroller performs relative operation. Same operation will performed each time when button pressed.

Bluetooth Controlled Home Automation Block diagram

Now, when user touch ‘Fan On’ button in Bluetooth controller app then microcontroller receives ‘1’ via Bluetooth module and then controller Switch ‘On’ the Fan by using relay driver and relay. And when user touch ‘Fan Off’ button in Bluetooth controller app then microcontroller receives ‘2’ via Bluetooth module and then controller Switch ‘Off’ the Fan by using relay driver and relay.

Likewise 3,4,5,6 numbers are sent by Android Phone, when Light On, Light Off, TV On, TV Off button has been touched respectively:

Button

Data

Operation

Fan On

1

Fan Turned On

Fan Off

2

Fan Turned Off

Light On

3

Light Turned On

Light Off

4

Light Turned Off

TV On

5

TV Turned On

TV Off

6

TV Turned Off

 

Circuit Diagram and Explanation

Circuit connections of this project are very simple. Bluetooth module’s Rx and Tx pins are directly connected to the  Tx and Rx pins of Microcontroller. Three 5 volt relays are used as a switch for turning On and Off the home appliances running on AC mains. And a relay driver ULN2003 is used for driving relays. Fan, Light and TV are connected at P2.1, P2.2 and P2.3 via relays and relay driver. An 11.0592 MHz Crystal oscillator is used in this circuit for generating clock signal for microcontroller. And a 5 volt voltage regulator LM7805 is used for provide 5 volt for the whole circuit.

Bluetooth Controlled Home Automation System Circuit Diagram

Program Explanation:

In this program, first of all we have included header file and defines input, output pins and variables.

#include<reg51.h>

sbit Fan=P2^0;
sbit Light=P2^1;
sbit TV=P2^2;

 char str;
 char Charin=0;

After this we have created a function for delay.

void delay(int time)
{
  unsigned int i,j;
  for(i=0;i<time;i++)
  for(j=0;j<1275;j++);
}

Here we have some functions that we have used in our program. In this we have configured 9600bps baud rate at 11.0592MHz Crystal Frequency.

void Serialwrite(char byte)
{
  SBUF=byte;
  while(!TI);
  TI=0;
}      
void Serialprintln(char *p)
{
  while(*p)
  {
    Serialwrite(*p);
    p++;
  }
  Serialwrite(0x0d);
}

void Serialbegin()
{
   TMOD=0x20;
   SCON=0x50;
   TH1=0xfd;
   TR1=1;
}

After this, in main program we have initialized UART and monitored the SBUF register for receiving the data. Then data is matched and compared with predefined values and relative operation has been performed.

void main()
{
  P2=0x00;
  Serialbegin();
  Serialprintln("System Ready...");
  delay(50);
  while(1)
  {
    while(!RI);
    Charin=SBUF;
    str=Charin;
    RI=0;
      if(str=='1')
      {
        Fan=1;
        Serialprintln(" Fan ON");
        delay(50);
      }
      else if(str=='2')
      {
        Fan=0;
        Serialprintln(" Fan OFF");
        delay(50);
      }

So that’s how we can create a whole system for the house and can connect all the AC appliances to the 8051 microcontroller using Relays. And this bluetooth controlled home automation system can be operated from a Smart phone.

Code

#include<reg51.h>

sbit Fan=P2^0;
sbit Light=P2^1;
sbit TV=P2^2;

 char str;
 char Charin=0;

void delay(int time)
{
 unsigned int i,j;
 for(i=0;i<time;i++)
 for(j=0;j<1275;j++);
}

void Serialwrite(char byte)
{
  SBUF=byte;
  while(!TI);
  TI=0;
}

void Serialprintln(char *p)
{
  while(*p)
  {
    Serialwrite(*p);
    p++;
  }
  Serialwrite(0x0d);
}

void Serialbegin()
{
   TMOD=0x20;
   SCON=0x50;
   TH1=0xfd;
   TR1=1;
}

void main()
{
  P2=0x00;
  Serialbegin();
  Serialprintln("System Ready...");
  delay(50);
  while(1)
  {
    while(!RI);
    Charin=SBUF;
    str=Charin;
    RI=0;
      if(str=='1')
      {
        Fan=1;
        Serialprintln(" Fan ON");
        delay(50);
      }
      else if(str=='2')
      {
        Fan=0;
        Serialprintln(" Fan OFF");
        delay(50);
      }

       else if(str=='3')
      {
        Light=1;
        Serialprintln(" Light ON");
        delay(50);
      }

       else if(str=='4')
      {
        Light=0;
        Serialprintln(" Light OFF");
        delay(50);
      }

       else if(str=='5')
      {
        TV=1;
        Serialprintln(" TV ON");
        delay(50);
      }

       else if(str=='6')
      {
        TV=0;
        Serialprintln(" TV OFF");
        delay(50);
      }
      str=0;
  }
}

Video

Comments

  • Pearl's picture
    Pearl
    Feb 05, 2016

    Please I can't really interpret the circuit diagram and what software did you use for the simulation (was it proteus)

  • saddam khan's picture
    saddam khan
    Feb 07, 2016

    this circuit diagram is draw by using dip trace software.

    and i think it easy to understand. you need to give some of your concentration on the circuit to understand.
    try it again.

  • Shah Hussain's picture
    Shah Hussain
    Feb 13, 2016

    how to use AT commands in program

  • ronnie's picture
    ronnie
    Feb 24, 2016

    Sir what IDE you use for code?

  • ronnie's picture
    ronnie
    Feb 24, 2016

    sir i'm using egbt-045ms as my bluetooth module. what will be the adjustment?

  • ronnie's picture
    ronnie
    Feb 25, 2016

    Can i usethe same android app. even i'm using egbt-045ms as my bluetooth module?

  • aarti's picture
    aarti
    Mar 15, 2016

    sir plz give me complete information

  • eman adel's picture
    eman adel
    Apr 04, 2016

    please, can i get Code In Assembly language by Keil 8051 Compiler ?

  • Azmath's picture
    Azmath
    Apr 13, 2016

    Sir , what is "R2" in circuit diagram (left side of circuit diagram),
    please explain it.

  • MOHAMMAD ALI's picture
    MOHAMMAD ALI
    Apr 23, 2016

    Sir , please provide the code with LCD interface also the modified circuit diagram.

  • Namrata's picture
    Namrata
    May 16, 2016

    Is RS232 MAX required for bluetooth interfacing with microcontroller?

  • Malik Saad's picture
    Malik Saad
    May 28, 2016

    sir i need a help to understand what is TI in the program......if register it is not configured....kindly let me know.

  • Abhishek's picture
    Abhishek
    Jul 09, 2016

    SBUF (serial buffer special function register) is used for serial communication, whenever we want to send any byte to serial device we put that byte in SBUF register, when the complete byte has been sent then TI bit is set by hardware. We need to reset it for sending next byte. It’s a flag that indicates that byte has been sent successfully. TI is the second bit of SCON register.

  • shivam 's picture
    shivam
    Jun 17, 2016

    Sir whether we require 12v or5v relay ??
    Is there will be no damage by using5v relay??
    Plzz give info in detail I m confused???

  • Sumana's picture
    Sumana
    Jul 08, 2016

    Good project

  • zahra modi's picture
    zahra modi
    Jul 25, 2016

    as bluetooth range is 10-15 meters so if range extension is possible?

  • Shivali singh's picture
    Shivali singh
    Jul 26, 2016

    difference b/w SBUF and str

  • Maddy's picture
    Maddy
    Aug 20, 2016

    SBUF is the 8051's internal Register which is used in Serial Communication where as 'str' is just user defined variable.

  • saddam khan's picture
    saddam khan
    Jul 29, 2016

    yes you may use another bluetooth module with good quality antenna.

  • manoj's picture
    manoj
    Aug 26, 2016

    i can't understood anything of the circuite diagram.
    please explain the circuite diagram.

  • pg's picture
    pg
    Aug 30, 2016

    is the given code full code?? I dnt think that the given code is working. can u kindly provide me the right o
    ne

  • sumangal mistry's picture
    sumangal mistry
    Sep 09, 2016

    if I change Bluetooth module to extension the rang. then is there program will change?

  • sumangal mistry's picture
    sumangal mistry
    Sep 18, 2016

    if I increase the rang of Bluetooth module up to 100 meter so what I shall I do. pleaze told me sir.

  • pvn's picture
    pvn
    Oct 03, 2016

    is the given code working or it needs come modification ??
    I need complete code.
    I have tried the abive mentioned code but its not working in proteus. wat can I do to make it work?
    plz help man

  • Mitul 's picture
    Mitul
    Oct 06, 2016

    Can we use atmega32 instead of 8051.Can you give the code and the block diagram.

  • sumangal mistry's picture
    sumangal mistry
    Oct 07, 2016

    if I increase the rang of Bluetooth module up to 100 meter so what I shall I do. pleaze told me sir.

  • Maddy's picture
    Maddy
    Oct 07, 2016

    Your question is already answered above, why are you posting it again and again. Your comment is only visible after getting approved, so you wont be able to see it just after posting.

  • ali 's picture
    ali
    Oct 11, 2016

    can we use arduino instead of micro controller

  • omartag's picture
    omartag
    Oct 26, 2016

    do u have an assembly code for this project?

  • prakash 's picture
    prakash
    Nov 05, 2016

    sir can u help me ,doing bluthooth controlled HA ,but the program is not uploded in targeted MC unit ,i have already chekked that all pheriperal interfaces ande power sources ,i am using friendly board of ours

  • Maqsood ali ansari's picture
    Maqsood ali ansari
    Nov 23, 2016

    SIR, i want to control my load using Gsm, not bluetooth, may it possible.

  • monib ahmad's picture
    monib ahmad
    Nov 29, 2016

    can u plz provide me the code and circuit diagram to control home appliances using arduino and bluetooth module from android mobile..

  • uma mahesh's picture
    uma mahesh
    Dec 08, 2016

    is the above code is assembly language

  • Sarmad's picture
    Sarmad
    Dec 18, 2016

    Hello guys please I need help, I've done everything as mentioned in the article but the issue I am facing is that when I press 0n key from my phone the relay only ticks very low sound as if it is not being magnetised properly to switch on or off inside relay please tell me a solution the signal from microntroller are not enough to energise the relay even though I'm using relay driver

  • sumangal mistry's picture
    sumangal mistry
    Dec 26, 2016

    sir if I make ISP burner then what I shall do. plz send circuit diagram of AT89C51 ISP burner

  • UMA MAHESH BEERAM's picture
    UMA MAHESH BEERAM
    Jan 21, 2017

    Can you please help me about Bluetooth module

  • Jitendra's picture
    Jitendra
    Jan 22, 2017

    Sir what oscillator is used in circuit for 11.0592 MHz frequency

  • VINOD KUMAR MISHRA's picture
    VINOD KUMAR MISHRA
    Jan 25, 2017

    Dear sir,
    I have degitizer, which is communicate data to PC over comport. I am a software developer and need communication with Android over Bluetooth.
    Can you please provide the circuit to convert from comport to Bluetooth.

    I shall be highly grateful to you.
    Thanking you

  • Kirankumar's picture
    Kirankumar
    Feb 03, 2017

    10uf & 1000uf capacitor voltage??

  • sumangal mistry's picture
    sumangal mistry
    Feb 09, 2017

    sir if I make ISP burner then what I shall do. plz send circuit diagram of AT89C51 ISP burner

  • akash's picture
    akash
    Feb 12, 2017

    Anyone can give me the PCB layout for this circuit

  • mousa's picture
    mousa
    Feb 26, 2017

    what is the type of this language
    is it c or c++ or java or what ?

  • Mahaan's picture
    Mahaan
    Mar 22, 2017

    Sir in video as shown below relay have u connected IC ULN2003A n if u have connected frm dat have taken one i/p wire r frm relay

  • Abhrodeep's picture
    Abhrodeep
    Apr 06, 2017

    Please Sir reply. Can i use 12Mhz crystal oscillator in this project? is the source code complete?

  • Abhishek's picture
    Abhishek
    Apr 08, 2017

    Source code is complete, you can use 12Mhz crystal but then you need to change the the frequency in Keil uVision software while uploading the code.

  • sohil 's picture
    sohil
    Apr 22, 2017

    sir can we use 8051 development board

  • Rustem's picture
    Rustem
    May 25, 2017

    Hi sir. How did u programm this microcontroller? what did u use to programm ? for example phyton chipporog etc..

  • john wick's picture
    john wick
    Jun 14, 2017

    Sir, could i use the "5V charger or 9V battery through 7805" to supply relays, HC05 and microcontroller instead of using 12V through 7805 ??

  • john wick's picture
    john wick
    Jun 15, 2017

    Sir, could i use the "5V charger or 9V battery through 7805" to supply relays, HC05 and microcontroller instead of using 12V through 7805 ??

  • Sam's picture
    Sam
    Jun 16, 2017

    HI, its a nice project, got scope for lots of applications,
    why are there no header files for bluetooth and usart in the above code.
    could you post it on the wall

  • john wick's picture
    john wick
    Jun 18, 2017

    Sir, what is the function of S1 (in the left hand side of the circuit diagram). Can we skip it ?

  • vasky's picture
    vasky
    Jul 09, 2017

    IS it possible that we can use WiFi instead of Bluetooth to extend its range???

  • Hrishikesh's picture
    Hrishikesh
    Aug 12, 2017

    Sir....I did all the connections properly.......I programmed microcontroller properly.............Then why it's not working............Please reply me.....
    It worked once......

  • Arul 's picture
    Arul
    Nov 27, 2017

    Hi sr vvvvv nice to your project and code vvv thanks sr ........pls led and sd card with Arduino pls workout this project dr

  • Antjony's picture
    Antjony
    Dec 11, 2017

    Hi I am using keil uvission5 but cannot create hex file from code. It states no END statement and error on ever line of program most invalid symbols. Can you help with this issue tjamks

  • amol's picture
    amol
    Dec 22, 2017

    hello sir,
    share link for android application

  • Sheraz Ahmad's picture
    Sheraz Ahmad
    Jan 02, 2018

    this project works will while controlling relay or dc motor etc, but the message along with the activation of relay or motor does't recieved send by the 8051 mcu. i m using "realterm" & "teraterm" serial terminal.

  • Akahat's picture
    Akahat
    Jan 15, 2018

    How do I control the hc-05 in proteus simulation? Also, I can't find this exact application on the play store. So can we use any other application?

  • AISHA's picture
    AISHA
    Jan 15, 2018

    You cannot use the Bluetooth module directly on Proteus. But you can use the virtual monitor to check if the code is working as expected.

    And yes you can use any alternative application from play store

  • asharib's picture
    asharib
    May 06, 2018

    virtuL TERMINL window is not taking any input

  • romil's picture
    romil
    Jan 18, 2018

    In Pin Description of accelerometer where i have to connect EN pin microcontroller ??

  • romil's picture
    romil
    Jan 18, 2018

    can i use P89V51RD2 microcontroller ???

  • romil's picture
    romil
    Jan 18, 2018

    give me the link of Bluetooth controller application ....... because in playstore so many applications are there so which one i have to use i don't know so please give me link....

  • AISHA's picture
    AISHA
    Jan 30, 2018

    You can use any bluetooth application. My personal choice is "Bluetooth Terminal" it works well and should also work for this project 

  • Mohamed Gbla's picture
    Mohamed Gbla
    Jan 25, 2018

    I WANT TO BE IMPLEMENTING AUDINO PROJECT

  • SA 's picture
    SA
    Feb 09, 2018

    BT r both getting paired, but if 1,3 or 5 is sent thru app 'Bluetooth Terminal" no changes is occurred even after connecting LED at MCU output pin 21,22, and 23. Any one can help plaese....

  • SA 's picture
    SA
    Feb 10, 2018

    Both the BT is paired, but when putting 1,3 or 5 pin 21,22 or 23 is not changed as i put led in that pin. can any body say the cause???????????

  • SA RAHAMAN's picture
    SA RAHAMAN
    Feb 11, 2018

    Ckt connection as per given n code upload is also successful, I connected LEDs at o/p pin 21,22,23 with register 330ohm for each and loaded a app ‘Bluetooth Terminal’in android phone and it paired with hc05 correctly,, but even spite of putting 1,3 or 5 on BT terminal nothing is getting changed on pin 21,22 or 23 ie LEDs not getting ON.

    my BT module is same as mentioned HC05(BC417).

    anybody can help me the problem is what???

    thnx

  • Pradip 's picture
    Pradip
    Feb 21, 2018

    Sir,
    application for Bluetooth controller is not available on play store
    Please send me app link

  • rushi 's picture
    rushi
    Feb 23, 2018

    sir i was follow you all or instructions but my projects its NOT run LED only blinking when i applyde to 5v power supply my all connections its correct my mobaile app HC05 its connected but its not run sir plz can you help me ?

  • Tarun's picture
    Tarun
    Apr 02, 2018

    pls give me hex file

  • FN's picture
    FN
    Apr 15, 2018

    Sir i need Android app code .app that you used for controlling appliances

  • sai's picture
    sai
    Apr 23, 2018

    bro can u make the program and proteus output for voice based home automation system using lcd and bluetooth and 2 loads using interface through voice we have an app called amr_voice

  • FARRUKH's picture
    FARRUKH
    Jul 06, 2018

    sir i use G-540 TO burn program but i couln't burn it kindly tell me which software is use to burn code

  • abhilash's picture
    abhilash
    Sep 03, 2018

    why bluetooth HC-05 used

Log in or register to post Comment