Hi guys, In this tutorial we are going to control home appliances with voice command. You have to just press the google mic button and give command to turn ON or OFF Light. So let’s get started.

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
we are using this voltage divider on Rx pin because Rx pin of Bluetooth module should only required 3.3.V. I have already explain this in detail. Please see previous tutorial on How to control home appliance with Bluetooth module.

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:

This sketch is same as previous tutorial. I have already explain it. Please see previous tutorial on How to control home appliance with Bluetooth module. We will go through the code briefly here. If Arduino receive 1 character via Mobile phone bluetooth. It will turn ON the light. If it get zero it will turn OFF the 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, Fan turn ON when it receive 2 and turn OFF when it get 3.

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

I have given All ON & All OFF button. With this All ON & All OFF button. We can turn ON or OFF both Light and Fan at the same time with single command.

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 App for Voice Command:

You can use any app which support voice command for Bluetooth module. I am using this app. After downloading the app. Open it. Connect the app with Arduino Bluetooth module. After connecting. You can see by default some buttons. Go to setting by clicking on gear icon button.

Click on button 1 to edit.

Bluetooth buttons

You can set any name for label. It is only mean to show button name. For ON code we will give 1 character because in our sketch we have given 1 code for light ON and zero for light OFF. In Voice ON, You have to give command which you are going to say to turn ON light. I have given “Light ON”. To turn OFF light. It is “Light OFF”.

Edit Bluetooth button

Whenever you say this command it will send particular code from mobile phone to Bluetooth module. If it is 1, it will turn ON light and if it is zero it will turn OFF the light. Finally Save it. Similarly, You can edit other buttons or if you want you can add more buttons.

how voice control with arduino works

Now let’s see how this works. It works fine only I can see when i was in front running fan it was facing difficulty to recognize the voice. And also make sure to turn ON internet on your mobile phone, when you are giving the command. If internet is ON, It will recognize voice quickly and efficiently. It can work offline but sometime it doesn’t recognize voice. So it is up-to you to turn ON internet or not. Because of the ads in the app, people don’t like to turn on internet while using this kind of app

Till then keep learning keep making.