Arduino Projects-Voice Control for Everything

Want to control your household Appliances or Projects with Voice?Then the answer is yes,this can be done just by using your Smartphone,Arduino and a Bluetooth Module without       using any voice recognisation Module costing Hundred’s of Dollars.The working is very simple,we use a smartphone application that used google voice recognisation to recognise our voice and sends it over a bluetooth connection in a text format to the Arduino.This text format is then Processed  to perform a task which we will write in our Arduino Sketch.We can use it to turn on Relay’s for home automation,control a robots movements etc.So lets get started!!

Things you need:

  •  Arduino
  •  Bluetooth Module(HC-05/06)
  •  LED’s(For example in this tutorial)
  •  Smartphone
  •  Wires
  •  Breaboard

Arduino Voice Control Code

This code is much simpler and use’s some basic C language.To process a command first we need to get the command from Bluetooth module then store it in a string named voice and compare the string with our commands written in the code.The code runs a Loop() which again consists of a while loop which checks if there is any serial data available to be read,if available the data will be stored in a string named voice character by character till “#” is found,as # is used by the smartphone application to indicate end of statement.After the data is stored in string,this string is checked with IF and Else to see if there is any command matching with it.when the command is found,respective function for the command is executed,if not found the the whole process starts again.

For eg-  When you speak a command on your smartphone application “Turn on all LED”.The command is sent to bluetooth module as”Turn on all LED#”.Arduino reads it till # and stores it in a                    string(voice=”Turn on all LED”).This string is then checked with the available commands in the code,and the respective function for the command is executed.

You can modify the code as per your needs and change the commands.

#include <SoftwareSerial.h>

SoftwareSerial BLU(0,1);

String voice;

int Blue   = 2;  //Connect To Pin #2 

int Green  = 3;  //Connect To Pin #3 

int Yellow = 4;  //Connect To Pin #4 

int Red    = 5;  //Connect To Pin #5 


 
void allon()
{
     
  digitalWrite(Red, HIGH); 
     
  digitalWrite(Yellow, HIGH); 
     
  digitalWrite(Green, HIGH); 
     
  digitalWrite(Blue, HIGH); 
     

}


void alloff()
{
     
  digitalWrite(Red, LOW); 
     
  digitalWrite(Yellow, LOW); 
     
  digitalWrite(Green, LOW); 
     
  digitalWrite(Blue, LOW); 
     
}


void setup() 
{
  
  Serial.begin(9600);
    
  BLU.begin(9600);
    
  pinMode(Red, OUTPUT); 
  
  pinMode(Yellow, OUTPUT); 
  
  pinMode(Green, OUTPUT); 
  
  pinMode(Blue, OUTPUT); 
  
}

void loop() 
{
  
  while (Serial.available())     //Check if there is an available byte to read
  {   
    delay(10);                   //Delay added to make thing stable 
  
    char c = Serial.read();      //Conduct a serial read
  
    if (c == '#') 
    {
      break;                     //Exit the loop when the # is detected after the word
 
    }   
    voice += c; 
 
  }  
  
  if (voice.length() > 0) 
  {
    if(voice == "*turn on all LED") 
    {
      allon();
    }  
    else if(voice == "*turn off all LED")
    {
      alloff();
    } 
    else if(voice == "*switch on red") 
    {
      digitalWrite(Red,HIGH);
    } 
  
    else if(voice == "*switch on yellow") 
    {
      digitalWrite(Yellow,HIGH);
    }
  
    else if(voice == "*switch on green") 
    {
      digitalWrite(Green,HIGH);
    }
  
    else if(voice == "*switch on blue") 
    {
      digitalWrite(Blue,HIGH);
    }

     else if(voice == "*switch off red") 
    {
      digitalWrite(Red,LOW);
    } 
  
    else if(voice == "*switch off yellow") 
    {
      digitalWrite(Yellow,LOW);
    }
  
    else if(voice == "*switch off green") 
    {
      digitalWrite(Green,LOW);
    }
  
    else if(voice == "*switch off blue") 
    {
      digitalWrite(Blue,LOW);
    }

    voice="";            //Reset variable
  }
}

 

Wiring up the Circuit

For explaination purpose I will be using four Led’s,You can connect anything you want to control eg-Relays,transistors etc.

I will be using 2,3,4 and 5 pins of arduino as output pins for my Blue,Green,Yellow and Red Led’s with a resistor in series to limit the current.Now connect the Bluetooth Module to Arduino.

Bluetooth Module>>Arduino

VCC>>5V

      GND>>Ground

TX>>RX

RX>>TX

Arduino Voice Control
Arduino Voice Control

Setting up your Smartphone

        Download the below application and Install it.After installing connect the Application to your Bluetooth Module while your whole circuit is powered on.(Password for HC-05 is 1234)

https://play.google.com/store/apps/details?id=robotspace.simplelabs.amr_voice&hl=en

Done!

        After the connection is established tap on the mic button and speak your command.For eg-“Turn on Red Led”.The red Led turns on.

 


You May Also Like

One thought on “Arduino Projects-Voice Control for Everything

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons