Hello guys, In this tutorial we will see how to control home appliances with Bluetooth module (HC-05). It is very simple to control any device with Bluetooth. So, Let’s get started.

This project can be used in many applications such as home automation, Controlling device remotely, getting sensor data remotely etc.

For making this project, You will need

  1. Arduino uno,
  2. Bluetooth module (HC-05),
  3. 2 channel Relay module,  (You can use 8 channel relay depends on your project),
  4. 1k & 2K Ohms Resistor
  5. Jumper Wire,
  6. Breadboard.

Do connection as shown in Diagram.

Arduino bluetooth home automation circuit diagram

Why we are using voltage divider for Rx pin of Bluetooth module?

Sending data from Tx pin of Bluetooth module required 3.3V, which is accurately given by Bluetooth module.

Problem with Rx Pin in bluetooth

But main problem is with Rx pin, it require 3.3V and we know arduino Tx pin is running on 5V. So we have to use voltage divider in order to reduce voltage to 3.3v. This is the reason I am using two resistor. You can use any combination of resistor for example 1k and 2k ohms resistor, as I am using in this tutorial or you can use 10k and 20k ohms resistor but make sure it should give 3.3V to Rx pin.

You can connect directly Arduino Tx pin to Rx pin without voltage divider but there is risk of damaging your Bluetooth module. You can use voltage divider formula to calculate it.

Vout = Vin * R2/(R1+R2)

Vin= 5V,

R1= 1000 Ohms,

R2= 2000 Ohms,

After calculating we will get

Vout = 3.333V.

Sketch:
char data = 0; //Variable for storing received data
void setup() 
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin for Light
pinMode(12, OUTPUT); //Sets digital pin 13 as output pin for Fan
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data and store it into variable data

// For Light
if(data == '1') //Checks whether value of data is equal to 1 
digitalWrite(13, HIGH); //If value is 1 then Light turns ON
else if(data == '0') //Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then Light turns OFF

// For Fan
else if(data == '2') //Checks whether value of data is equal to 2
digitalWrite(12, HIGH); //If value is 2 then Fan turns ON
else if(data == '3') //Checks whether value of data is equal to 3
digitalWrite(12, LOW); //If value is 3 then Fan turns OFF

//For ALL ON or OFF
else if(data == '4') { //Checks whether value of data is equal to 4
digitalWrite(13, HIGH); //If value is 4 then Light turns ON
digitalWrite(12, HIGH);} //If value is 4 then Fan turns ON
else if(data == '5') { //Checks whether value of data is equal to 5
digitalWrite(13, LOW); //If value is 5 then Light turns OFF 
digitalWrite(12, LOW); } //If value is 5 then Fan turns OFF
  } 
}
Explanation:

Lets come to programming part. Code is pretty much simple. We are storing character value in “data”.

char data = 0;

Define pinMode for Light and Fan.

pinMode(13, OUTPUT);
pinMode(12, OUTPUT);

Serial.available() Get the number of bytes (characters) available for reading from the serial port

if(Serial.available() > 0)

It will read incoming data and store in variable data.

data = Serial.read();

If it receive 1 character it will turn ON light. If it is 0, it will turn OFF light.

if(data == '1') //Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then Light turns ON
else if(data == '0') //Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then Light turns OFF

Similarly we can define character for Fan. Here I am using All ON and All OFF button. We can turn ON & OFF both at the same time with single button.

else if(data == '4') { //Checks whether value of data is equal to 4
digitalWrite(13, HIGH); //If value is 4 then Light turns ON
digitalWrite(12, HIGH);} //If value is 4 then Fan turns ON
else if(data == '5') { //Checks whether value of data is equal to 5
digitalWrite(13, LOW); //If value is 5 then Light turns OFF
digitalWrite(12, LOW); } //If value is 5 then Fan turns OFF
Download the App:

For controlling fan and light or any other device you will need an app. I am downloading Arduino Bluetooth Controller App. You can download any app from App Store or Play Store. All works same only difference is interface etc. After downloading app. Open the app. And connect app with Bluetooth module. If it ask for password. It must be 0000 or 1234. After connecting. You can see here by default some buttons.

bluetooth welcome screen

Go to setting by clicking on gear icon button.

Bluetooth buttons

we need to edit button. Click on button 1.

Edit Bluetooth button

You can set any name for label, its only mean to show button name. For ON code we will give 1. As you can see we already give 1 code for light ON and 0 code for light OFF. Give any command to voice ON & OFF. Because in this tutorial we are not controlling device with voice command. And save it. Similarly edit for button 2 and button 3. Make sure you add particular code for that button. You can add any number of button in this app. You can control anything like TV, Home theatre etc. You have to just add the buttons and extra relays.

Now you can see, I am controlling Light & Fan with our Arduino Bluetooth module.

Arduino bluetooth controller

Till then keep learning keep making.