Dhananjay Khairnar @. Powered by Blogger.

25 March 2017

Bluetooth Controlled Home Equipments:

Basic about bluetooth:

Bluetooth is a wireless technology standard for exchanging data over short distances (using short-wavelength UHF radio waves in the ISM band from 2.4 to 2.485 GHz) from fixed and mobile devices, and building personal area networks (PANs). Invented by telecom vendor Ericsson in 1994

Radio frequency communication (RFCOMM)

The Bluetooth protocol RFCOMM is a simple set of transport protocols, made on top of the L2CAP protocol, providing emulated RS-232 serial ports (up to sixty simultaneous connections to a Bluetooth device at a time). The protocol is based on the ETSI standard TS 07.10.

RFCOMM is sometimes called serial port emulation. The Bluetooth serial port profile is based on this protocol.

RFCOMM provides a simple reliable data stream to the user, similar to TCP. It is used directly by many telephony related profiles as a carrier for AT commands, as well as being a transport layer for OBEX over Bluetooth.

Many Bluetooth applications use RFCOMM because of its widespread support and publicly available API on most operating systems. Additionally, applications that used a serial port to communicate can be quickly ported to use RFCOMM

In the protocol stack, RFCOMM is bound to L2CAP.
In our project we are going to use RFCOM socket.

Requrments :
1) Arduino
2) Bluetooth module HC-05
3) Relay circuit
4) Connecting wires

Aim : Controll Device from bluetooth

Software Design:

Arduino code:
Here we design simple protocol between mobile device and microcontroller to agree on some data code like.
if mobile sends string 'START1' means turn on Device, if mobile sends string 'STOP1' then turn off device.
And 'GETSEN' for sensor readings
 following code is design for do that

Arduino Turn LED On/Off using Bluetooth 
Created feb 6 2017
by Dhananjay
It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.

Possible string values:
a (to turn the LED on)
b (tor turn the LED off)
#include < softwareserial.h >
SoftwareSerial mySerial(10, 11); // RX, TX
char junk;
String str;

void setup()                    // run once, when the sketch starts
 Serial.begin(9600);            // set the baud rate to 9600, same should be of your Serial Monitor
 pinMode(13, OUTPUT);
 pinMode(A0, INPUT);

void loop()

      str = mySerial.readString();
    if(str == "START1\r\n"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH); 
    else if(str == "STOP1\r\n"){   //in case of 'b' turn the LED off
      digitalWrite(13, LOW);
    else if(str == "GETSEN\r\n")// Send analogue sensor value
      int anlgval = analogRead(A0)%100;

    str = "";

In above code we are controlling one equipment which are connected to relay from Arduino pin 13.
You can increase count of equipment by adding extra if conditions .

Android code:
Now its some hard part of this project as electronics guys dont know android coding but dont worry is not so hard if you know some basics of OOPS and how to deal with Java. You need to install Arduino IDE with along proper Android SDK. If you SDK is latest and not supported by following code then you need to mange Android studio to compile following code.

Sreen shot given as:

Code in Android studio:
Download the rar file it contains source code of simple android app written by me. You can customize it. Open Android Studio and open project.
Structure of project:

method for write data to HC05:

Method for receive String from HC05

Gradal build settings:

Hardware Design:

HC-05 :

HC-05 PinOut (Right) :

  • KEY: If brought HIGH before power is applied, forces AT Command Setup Mode. LED blinks slowly (2 seconds)
  • VCC: +5 Power
  • GND: System / Arduino Ground
  • TXD: Transmit Serial Data from HC-05 to Arduino Serial Receive. NOTE: 3.3V HIGH level: OK for Arduino
  • RXD: Receive Serial Data from Arduino Serial Transmit
  • STATE: Tells if connected or not


The module has two modes of operation, Command Mode where we can send AT commands to it and Data Mode where it transmits and receives data to another bluetooth module.
The default mode is DATA Mode, and this is the default configuration, that may work fine for many applications:

In some cases you may want to change some of the configuration setup values. There are two ways to get into Command Mode.
Connect the KEY/WAKEUP pin high before applying power to the module. This will put the module into command mode at 38400 baud. This is commonly used, and needed if you don't know the baud rate the module is set to.
AT+ROLE=0 : You can change role by 0 for SLAVE & 1 for Master. Leave it as 0 as we want this module to be SLAVE.
AT+NAME=DKS_BLUE : change name of device which is brodcast

Open KEY?WAKEUP pin  dont connect it anywhere then power up module it is in now Data Transfer mode. Whatever data you send to the module from serial terminal that get transfer to the connected device via RFCOM.
  • Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit, Parity : None, Handshake: None
  • Passkey: 1234
  • Device Name: HC-05
Connection Diagram:

make this connection to operate bulb from bluetooth.

About DK

Hi, My Name is DK. I am a embedded system designer and embedded programmer. I am a certified holder of Diploma in Embedded system designing. We have a team of professinal programmers, developers work together and implement innovative concepts.


  1. Excusme Sir, where the link to download this android studio project?