DIY Voice Controlled Home Automation with Arduino and Bluetooth

Voice Controlled Home Automation using Arduino and Bluetooth

Smart homes have become popular due to their convenience and energy efficiency. An implemented project uses voice commands to wirelessly control home appliances and lights. An Android app performs the speech-to-text conversion and Bluetooth communicates with the microcontroller to execute commands. This eliminates the need for physical interaction with devices. Smart homes can save energy and reduce their carbon footprint by automating tasks and tracking energy usage. Smart technology in homes is an efficient way to make daily tasks easier. Smart home devices can also track energy usage and provide insights for improved efficiency.

Before this, we have built some IoT Home Automation Projects, here are some examples:

 

Components Required

  • Arduino UNO
  • HC-05 Bluetooth Module
  • 2-channel Relay Module(5v)
  • 2 holders
  • 2 Bulb
  • 220v Electrical wire with a 2-pin male socket
  • Sun board Piece
  • Jumper wires
  • Nuts & bolts
  • And a Smartphone

 

Bluetooth Module HC-05

It is a widely used module in electronic projects for wireless communication. It uses serial UART communication for data transfer.

The Module can work in two modes:

  1. Master mode: It can share data with all slaves.
  2. Slave mode: It receives data from a master Bluetooth.

Here, our Bluetooth module is working as a slave while the smartphone is a master.

HC 05 Pinout

HC-05 Bluetooth Module Pinout

It consists of 6 pins which are STATE, RXD, TXD, GND, VCC, and EN as mentioned on the back of the module.

  • STATE pin: This pin defines the state of the module whether it is paired or not with another device.
  • RxD pin: This pin uses serial UART communication. This pin is used to send AT command when the module is in command mode.
  • TxD pin: This pin uses serial UART communication. This pin is used to push out responses to AT command when the module is in command mode.
  • Vcc pin: This pin is used to supply power to the module to make it work. It is typically connected to the 5V pin on the Arduino board. Its voltage range lies between 3.6v to 5v.
  • GND pin: This pin is used to connect the module to the ground of the Arduino board.
  • EN pin: This pin is used to switch between command and data mode. The module will be in command mode if this pin is set to HIGH. Similarly, the module will be in data mode if this pin is set to LOW.

Relay

It is a switching electro-mechanical device that can be able to switch high Amps of AC- DC power.

Relay Pinout

Relay Module Pinout

The module has typically four pins:

  • Vcc pin: It is used to power up the relay module. It is normally connected to 5v.
  • GND pin: It is used to provide ground to the relay module.
  • IN1: It is used to control the output of the first relay inside the module.
  • IN2: It is used to control the output of the Second relay inside the module.

Also, there are three more pins at the side of the high-voltage terminals of each relay. These are NC (Normally closed), COM(Common), and NO (Normally Open).

 

Circuit Diagram

home automation circuit diagram

The connections are pretty simple, let's begin.

Bluetooth HC-05: To establish communication between the Arduino and the Bluetooth HC-05 module, pin 3 (Tx defined in code) of the Arduino is connected to the receive pin (RxD) of the Bluetooth module, while pin 2 (Rx) is connected to the transmit pin (TxD). The Bluetooth module is powered by connecting its Vcc and GND pins to the Arduino's respective power and ground pins.

Relay Module: The Arduino pin 5 is connected to IN1 of the relay Module whereas pin 6 is connected to IN2. These input pins are active low, which means that a logic LOW activates the relay and a logic HIGH deactivates it.

The relay module has two LEDs that indicate the status of the relay. When a relay is activated, the corresponding LED lights up. The relay module is powered by connecting its Vcc and GND pins to the Arduino's respective power and ground pins.

On the high-voltage side of the relay module, the COM port of both relays is connected to the live supply of AC. The NO terminal of each relay is connected to each separate bulb, while the Neutral wire is directly connected to both bulbs as shown in the circuit diagram.

Arduino based Home Automation

Setting up Voice Command Android App

To use the project first you need to install an app from Playstore called Arduino Bluetooth.

  • Download and install the app.
  • Give microphone permission and enable Bluetooth.
  • Start your project and Pair your device with HC-05.
  • Switch to voice mode in the app.

Home Automation App Setup

  • Tap the microphone icon to begin giving voice commands.
  • Speak the correct commands as per your code.
  • Enjoy controlling your device with voice prompts.

Voice Controlled Home Automation App Setup

 

Arduino Code Explanation

The program reads the Bluetooth module data through serial communication and compares it with defined conditions. If any of the conditions is true, then that task will perform. If any of the condition is not satisfied, it will do nothing.

Firstly, we must include all necessary Libraries for the successful execution of the code. Libraries include SoftwareSerial only. Also, we have defined the necessary variables and objects for further programming.

#include<SoftwareSerial.h>
// Define 2 channel relay pins
const int Light1 = 6; // Relay pin 1 (IN1)
const int Light2 = 5;   // Relay pin 2 (IN2)
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2, 3); /* (Rx,Tx) */
  • We used the Software Serial library to define the Rx & Tx serial communication pins to the Arduino. Other than that, we can directly use Arduino pin (0,1) for Rx and Tx, but it will create a hustle of removing the connection whenever we upload a fresh code.
  • Here, we define pin2 as Rx and pin3 as Tx. Always remember that RxD of Bluetooth is connected to Tx of Arduino while TxD is connected to Rx of Arduino.
void setup() {
  bt.begin(9600); /* Define baud rate for software serial communication */
  Serial.begin(9600); /* Define baud rate for serial communication */
  // Set Relay pins as OUTPUT
   pinMode(Light1, OUTPUT);
   pinMode(Light2, OUTPUT);
   digitalWrite(Light1, HIGH);
   digitalWrite(Light2, HIGH);
}

In the setup() function, serial communication is initiated.

  • The Bluetooth module can only communicate on the baud rate 9600. Hence, we initialize the BT module.
  • Also, we define all Pinmodes.
void loop() {
  String data="";
  char ch;
  while (bt.available()) /* If data is available on serial port */
    { ch = bt.read(); /* Print character received on to the serial monitor */
      data=data+ch;
    }
   Serial.print(data);
  // Control the devices using voice command
    if ((data == "turn on light one")||(data == "turn on light 1"))               // turn on Device1
    {
      digitalWrite(Light1, LOW);
      delay(200);
    }
    else if ((data == "turn off light one")||(data == "turn off light 1"))          // turn off Device1
    {
      digitalWrite(Light1, HIGH);
      delay(200);
    }
    // Control the devices using voice command
    else if ((data == "turn on light two")||(data == "turn on light to")||(data == "turn on light 2")) // turn on Device2
    {
      digitalWrite(Light2, LOW);
      delay(200);
    }
    else if ((data== "turn off light two")||(data == "turn off light to")||(data == "turn off light 2")) // turn off Device2
    {
      digitalWrite(Light2, HIGH);
      delay(200);
    }
}

In the Above loop part, we have done all the processing tasks like reading the serial port, comparing text, and executing the tasks.

  • The available data on the serial port is read and stored in the string variable “data”. Further, the stored data is compared with different conditions which we implemented using the IF-Else condition.
  • You can change the comparison text according to your ease. Also, you can check the received data on the serial Monitor which was sent by your voice command through your smartphone.

That is all about the code, just upload the code. Be careful about Rx & Tx pins and don’t forget to set the baud rate to 9600 on your serial monitor.

The complete code you will find below in the code section.

Working of Project

Home Automation using Arduino

  • Power on your project with the uploaded code.
  • Open the app and pair your BT module.
  • Start sending the voice commands used in your code to control the appliances.

Arduino Home Automation

Hope you enjoyed the article and learned something useful from it. If you have any questions, you can leave them in the comment section below.

Code

#include<SoftwareSerial.h>

// DeUfine 2 channel relay pins

const int Light1 = 6; // Relay pin 1 (IN1)

const int Light2 = 5;   // Relay pin 2 (IN2)

/* Create object named bt of the class SoftwareSerial */

SoftwareSerial bt(2, 3); /* (Rx,Tx) */

void setup() {

  bt.begin(9600); /* Define baud rate for software serial communication */

  Serial.begin(9600); /* Define baud rate for serial communication */

  // Set Relay pins as OUTPUT

   pinMode(Light1, OUTPUT);

   pinMode(Light2, OUTPUT);

   digitalWrite(Light1, HIGH);

   digitalWrite(Light2, HIGH);

}

void loop() {

  String data="";

  char ch;

  while (bt.available()) /* If data is available on serial port */

    { ch = bt.read(); /* Print character received on to the serial monitor */

      data=data+ch;

    }

   Serial.print(data);

  // Control the devices using voice command

    if ((data == "turn on light one")||(data == "turn on light 1"))               // turn on Device1

    {

      digitalWrite(Light1, LOW);

      delay(200);

    }

    else if ((data == "turn off light one")||(data == "turn off light 1"))          // turn off Device1

    {

      digitalWrite(Light1, HIGH);

      delay(200);

    }  

    // Control the devices using voice command

    else if ((data == "turn on light two")||(data == "turn on light to")||(data == "turn on light 2")) // turn on Device2

    {

      digitalWrite(Light2, LOW);

      delay(200);

    }

    else if ((data== "turn off light two")||(data == "turn off light to")||(data == "turn off light 2")) // turn off Device2

    {

      digitalWrite(Light2, HIGH);

      delay(200);

    }

}

8 Comments

|There is no such thing as being perfectly fashionable. There is no perfect sense of fashion, just opinions. Next, you will appear to be pushing too hard when you attempt to be perfect. Celebrities such as Kate Moss also have flaws, so do not think you always have to be perfect.

Nice post. I learn something more difficult on completely different blogs everyday. It should always be stimulating to read content material from different writers and practice just a little something from their store. I抎 favor to make use of some with the content on my blog whether or not you don抰 mind. Natually I抣l give you a hyperlink in your net blog. Thanks for sharing.

I am only commenting to make you know of the great experience my princess found going through the blog. She picked up many details, which include what it's like to possess an incredible teaching mood to get many others smoothly fully understand chosen problematic issues. You really exceeded our expectations. I appreciate you for providing the valuable, dependable, edifying and in addition easy tips about the topic to Emily.

I and also my buddies appeared to be studying the excellent things from your site while instantly came up with an awful feeling I never expressed respect to the site owner for those strategies. All the women were definitely certainly joyful to study them and now have extremely been making the most of those things. Appreciation for getting indeed accommodating as well as for utilizing such very good subject areas millions of individuals are really eager to discover. My very own sincere regret for not expressing gratitude to you sooner.

Thanks for all of the effort on this blog. My daughter loves getting into investigation and it is easy to understand why. We notice all regarding the powerful form you deliver very helpful tips and hints on your blog and even strongly encourage contribution from other ones on that topic while our own simple princess is being taught a lot of things. Have fun with the remaining portion of the new year. You have been doing a really good job.

There are some attention-grabbing points in time in this article however I don抰 know if I see all of them heart to heart. There may be some validity but I'll take hold opinion until I look into it further. Good article , thanks and we would like more! Added to FeedBurner as properly

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.