Speech Control with the Arduino and an Android phone

Speech recognition differs from voice recognition in that it will recognise any voice. A very good app available from the play store called AMR_voice does most of the hard work. Download this onto an Android device.

Communication is via Bluetooth so the following components are required

Arduino Uno
Bluetooth board such as the HC-05 or HC-06
5v to 3v level shifting board
Connecting wires and solderless breadboard


The bluetooth unit can be supplied from 5v but the Tx and Rx pins are 3v and a level shifting board should be used. Software Serial is used to ensure Arduino pins 0 and 1 are available to upload programs. Pin 10 is connected to Rx on the Bluetooth and pin 11 is connected to Tx through a level shifter. Gnd and +5v on the Arduino are connected to Gnd and 5v on the Bluetooth board. 3v from the Arduino is connected to the 3v connection on the level shifter board (if it is required).

The sketch I used to control a Red, Blue and Green is as follows:

Speech command using the AMR_Voice app for Android

Connect the HC05 or HC06 as follows, use a 5v to 3v level convertor for Tx and Rx
+5v to 5 volt pin
Gnd to GND pin
Tx to pin 10 via level convertor
Rx to pin 11 via level convertor

In this example three LEDs are used Red, Green and blue
connect each led using a 220R resistor to gnd from pin2 (red) pin3 (green) and pin 4 (blue)


SoftwareSerial mySerial(10, 11); // RX, TX
String voiceCommand = ""; // Stores voice string sent from bluetooth device
// string from Android starts with * and ends with #
// set up commands, replace commands 3 onwards with your own and add as required
String command1 = "all on"; // do not alter
String command2 = "all off"; // do not alter
String command3 = "red led"; // change command3 to command7 as required
String command4 = "green led";
String command5 = "blue led";
String command6 = "output4 on";
String command7 = "output5 on";
// set output pins, these can drive LEDs or relays, add as required
int output1 = 2;
int output2 = 3; // PWM pin
int output3 = 4;
int output4 = 5; // PWM pin
int output5 = 6; // PWM pin
void setup()
Serial.begin(9600); // Open serial communications at default BT speed
//Serial.flush(); // clear the buffer to allow the first string sent to print properly
Serial.println("Bluetooth Connected");
// SoftwareSerial "com port" data rate. JY-MCU v1.05 defaults to 9600.
mySerial.begin(9600); // start software serial
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
pinMode(output3, OUTPUT);
pinMode(output4, OUTPUT);
pinMode(output5, OUTPUT);
allOff(); // clear all outputs

void loop(){

while(mySerial.available()) { // While there is more to be read, keep reading.
delay(10); //Delay added to make thing stable
char c = mySerial.read(); //Conduct a serial read
if (c == '#') {break;} //Exit the loop when the # is detected after the word
// ignore the starting *
if (c != '*') { // chop off the * character at the start of the phrase
voiceCommand += c; //build the string
if (voiceCommand.length() > 0) {
Serial.println(voiceCommand); // print the command
// now select the command to use
if(voiceCommand==command1){ allOn();}
else if(voiceCommand == command2){ allOff();}
else if(voiceCommand == command3){ digitalWrite(output1, HIGH);}
else if(voiceCommand == command4){ digitalWrite(output2, HIGH);}
else if(voiceCommand == command5){ digitalWrite(output3, HIGH);}
else if(voiceCommand == command6){ digitalWrite(output4, HIGH);}
else if(voiceCommand == command7){ digitalWrite(output5, HIGH);}

voiceCommand=""; // reset command

}// END loop()

void allOn(){
digitalWrite(output1, HIGH);
digitalWrite(output2, HIGH);
digitalWrite(output3, HIGH);
digitalWrite(output4, HIGH);
digitalWrite(output5, HIGH);
void allOff(){
digitalWrite(output1, LOW);
digitalWrite(output2, LOW);
digitalWrite(output3, LOW);
digitalWrite(output4, LOW);
digitalWrite(output5, LOW);

Connect your phone to the Bluetooth board and run the app, speaking red led will turn the red led on. Speaking all off will turn all the LEDs off.

The Android app sends the phrase you speak adding a * character at the beginning an a # character at the end. The sketch strips both these characters off and prints the phrase you have spoken. Try pausing briefly between words in a phrase to ensure it is interpreted correctly.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: