Instructables
loading
loading

Voice Activated Arduino (Bluetooth + Android)

Featured
Picture of Voice Activated Arduino (Bluetooth + Android)

Control your Arduino with voice commands using an Android smartphone! Before we make a voice activated home automation system, we must first learn the basic principles of the experiment. This guide will let you command the Arduino using your Android smartphone and a HC-05 Bluetooth module.

The designer of the app did not include a sample code. I looked for alternatives in Google's PlayStore but none was as good as the app that I've found. Luckily, I was able to figure it out although it took me a while to program it. Sorry IOS users, this app isn't available in Apple's app store :/

How Does It Work?
Have you ever encountered Android's speech recognition? Yes android has one and you can use it to control your Arduino, via Bluetooth. The App works by pressing the mic button, then the it will wait for you to say a command. The app will then display the word's that you've stated and will send data strings for the Arduino to process.

Home Automation System (on July 4, 2014):
A month from now/ I'll be releasing a highly sophisticated home automation + security system. It's my biggest project ever! Our current agenda is to program a better smartphone app that work's like Siri (talks back) and sends strings (data types) to the Arduino via bluetooth. If you want to take a sneak peek of the project and it's concept, kindly skip to the last step. The prototype that I'm working on now is composed of a network of wireless switch boxes that connects to a main control panel via WiFi/ Bluetooth.

Here's A Quick Video Demo:

 
Remove these adsRemove these ads by Signing Up

Step 1: Parts & Materials

Picture of Parts & Materials
DSC_0081.JPG
collagef.jpg
bluetooth-HC05-02.jpg
If your having trouble in finding them, I'm sure RadioShack has all of them. If you want to buy online try searching on Amazon or DealExtreme.

Thing that you'll need:
- 5 LED Indicators (the color of your choice)
- Arduino UNO (a clone works fine)
- HC-05 Serial Bluetooth Module
- Solderless Breadboard
- Jumper Cables

Step 2: Assemble The Mini Bluetooth Shield

Picture of Assemble The Mini Bluetooth Shield
DSC_0084.JPG
DSC_0085.JPG
DSC_0091.JPG
My JY-MCU (DX Bluetooth Module) is still installed on my robots, what I have right now is the bare HC-05 module.

As we all know, the HC-05 doesn't come with a PCB. Soldering wires, directly to the metal conductors, isn't a good idea since the conductors could chip off anytime. As a solution, you can cut a fraction of perf-board then mount the HC-05 on it. I mistakenly connected my LED indicator on a blank (N/A) pin so mine doesn't work.
___________________________________________
Too lazy to assemble a Bluetooth shield? DX.com has a ready made version (click here). I've used the DX Bluetooth module on my robots, it's tested and it's 100% ok! You can visit Bluetooth related projects (Bluetooth Sumobot and Bluetooth FPV Rover) as reference.

Step 3: Connect The Bluetooth Module

Picture of Connect The Bluetooth Module
FJP6DCTHKVKX3JW.png
DSC_0100.JPG
DSC_0098.JPG
Grab some jumper cables and power the Bluetooth module with 3.3 volts. Remember, the bare HC-05 run on 3.3v and not on 5v. On the other hand, the JY-MCU has a built in regulator, it can run on a 5v line.

Now connect the RX (pin #0) of the Arduino to the TX pin of the Bluetooth module and the TX (pin #1) of the Arduino to the RX pin of the Bluetooth module. (refer to the image above)

Step 4: Connect The LEDs

Picture of Connect The LEDs
DSC_0104.JPG
DSC_0106.JPG
Connect the positive leads of each LED on pins # 2,3,4,5,6 of the Arduino. The negative leads of each LED goes to the negative rail of the breadboard. The negative rail of the breadboard goes to the Arduino's ground.

Step 5: Programming The Arduino

Picture of Programming The Arduino
Understanding The App: 
Before you program the arduino, you must first learn how the app works. The app work by recognizing your voice command, it will then display the words that you've spoken then sending data/ strings to the arduino via bluetooth. What's a string? A string is like a word, you can make conditional statements out of it [ex: if (voice == "*computer on") {// turn Pin #2 on} ]. The "voice" is your string, "==" is your condition (means equal to), "*computer on" is your command and the code inside the curly-braces "{ }" are the codes to be executed once your string matches the command condition. 

What's the format of the string? How does it know when the next command kicks in? How does it differentiate a set of words from a new command? The app sends strings in this format *command#, the asterisk (*) indicates the start of a new command and the hash-tag (#) indicates the end of a command. I was able to remove the hash-tag (#) after each word in the conditional statement was not able to remove the asterisk (*). You'll need to start your command condition with an asterisk otherwise the sketch will not work. 

How Can I Change The Commands?
You can see that the "*TV on" is highlighted from the image above. If you want to change the command to ,humm let's say "open garage door", you can replace the "*TV on" with "*open garage door". Always remember to start the command with an asterisk.

//Coded By: Angelo Casimiro (4/27/14)
//Voice Activated Arduino (Bluetooth + Android)
//Feel free to modify it but remember to give credit

String voice;
int
led1 = 2, //Connect LED 1 To Pin #2
led2 = 3, //Connect LED 2 To Pin #3
led3 = 4, //Connect LED 3 To Pin #4
led4 = 5, //Connect LED 4 To Pin #5
led5 = 6; //Connect LED 5 To Pin #6
//--------------------------Call A Function-------------------------------// 
void allon(){
     digitalWrite(led1, HIGH);
     digitalWrite(led2, HIGH);
     digitalWrite(led3, HIGH);
     digitalWrite(led4, HIGH);
     digitalWrite(led5, HIGH);
}
void alloff(){
     digitalWrite(led1, LOW);
     digitalWrite(led2, LOW);
     digitalWrite(led3, LOW);
     digitalWrite(led4, LOW);
     digitalWrite(led5, LOW);
}
//-----------------------------------------------------------------------// 
void setup() {
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, 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; //Shorthand for voice = voice + c
  } 
  if (voice.length() > 0) {
    Serial.println(voice);
//-----------------------------------------------------------------------//   
  //----------Control Multiple Pins/ LEDs----------// 
       if(voice == "*all on") {allon();}  //Turn Off All Pins (Call Function)
  else if(voice == "*all off"){alloff();} //Turn On  All Pins (Call Function)
 
  //----------Turn On One-By-One----------//
  else if(voice == "*TV on") {digitalWrite(led1, HIGH);}
  else if(voice == "*fan on") {digitalWrite(led2, HIGH);}
  else if(voice == "*computer on") {digitalWrite(led3, HIGH);}
  else if(voice == "*bedroom lights on") {digitalWrite(led4, HIGH);}
  else if(voice == "*bathroom lights on") {digitalWrite(led5, HIGH);}
  //----------Turn Off One-By-One----------//
  else if(voice == "*TV off") {digitalWrite(led1, LOW);}
  else if(voice == "*fan off") {digitalWrite(led2, LOW);}
  else if(voice == "*computer off") {digitalWrite(led3, LOW);}
  else if(voice == "*bedroom lights off") {digitalWrite(led4, LOW);}
  else if(voice == "*bathroom lights off") {digitalWrite(led5, LOW);}
//-----------------------------------------------------------------------// 
voice="";}} //Reset the variable after initiating

Step 6: Learn To Use The App

Picture of Learn To Use The App
Download The Free App Here: Android Meets Robots : Voice 

5 Simple Steps:
1st.)  Download the app from Google PlayStore
2nd.) Tap on options menu then select "Connect Robot"
3rd.)  Click on your BT-Module (in my case it's the HC-05)
4th.)  Wait until it says Connected to BT-Module (HC-05)
5th.) Tap on the mic icon and state your command!

Here's A Quick Demo Video:

Step 7: Next Project: Highly-Sophisticated Home Automation (Network)

Picture of Next Project: Highly-Sophisticated Home Automation (Network)
Here's a drawing of what to expect on my next Arduino project!

Sorry for the terrible doodle :)
1-40 of 180Next »
jmaag1 year ago

I tried it and it did not work. I have a galaxy S4 and it takes 7 secs after I say the command for it to appear at the bottom of what I said. And then nothing from the HC-05. No leds light. So what do I do to fix this. I dont mind the lag, but there is no response.

ASCAS (author)  jmaag1 year ago

I'm using my Nexus 7, the KitKat update made things run faster, I'm not sure with the S4 though. You'll need to say the exact words written in the code's conditions. Did you unplug the HC-05 from the project before uploading the sketch? It needs to be done, otherwise the Arduino wouldn't receive the codes. Tell me if it still doesn't work, I'll help you figure it out.

I AM USING GINGERBREAD A PHONE....I ALSO TRIED WITH KITKAT..

I UPLOADED SKETCH WITHOUT THE BLUETOOTH CONNECTED

THE LED'S ARE NOT TURNING ON ...

COMMANDS ARE DISPLAYED ON THE ANDROID APP...

HELP ME OUT...

jmaag ASCAS1 year ago
Hi ASCAS,
I have version 4.4.2. I do say the exact words because it is displayed below on my screen but 7 seconds later. Yes I programmed the uno before setting up the circuit. Thanks for helping me try to figure it out.
ShadowByte15 days ago

This is sort of off topic but can you provide the code for the Android Application. Of course the whole thing would be very complex but at least the functions where the voice input is taken and the Bluetooth part of it please. I've built a custom app for a home automation project im working on but i cant figure out the bluetooth part.

Luc Volders15 days ago

Ok guys if anybody is interested: I finally got it working on an Attiny85.

There was a serious bug in the Attiny85 compiler (provided by the MIT) that made it impossible to compile programs larger as 4k. So now this bug has been fixed this works on an Attinty85 which greatly reduces costs. You can use a 1 dollar processor instead of an Arduino.

For more info look at my web-log:

http://lucstechpage.weebly.com/blog

There is a link to the mit pages with great instructions on how to program an Attiny85 with the Arduino IDE.

Luc

OsamaM made it!17 days ago

THANKS!

IMAGW22.jpg
cristinef2 months ago

I tried to do this for my laboratory but unfortunately it didn't work. I used the Bluetooth shield v1.1 and gizduino atmega 168.

Can you give me some advice. Please reply,

THANK YOU IN ADVANCE.

try using the ATMEGA328 instead. it comes standard on all arduinos now.
what ever happened to the home automation project? Did you never follow through with it? I'm working on one myself and I'd like to see how your central control panel would work.
DaveT1320 days ago

Great work! You can remove the asterisk (*) at the start of each string by using "StringRemove". The middle line of this example is the additional code, so people know where to put it in your code:

if (voice.length() > 0) {
voice.remove(0,1);
Serial.println(voice);

Shakil141 month ago

if i execute the "allon" instruction, next time when i say "alloff" it doesnt work.. infact i can only execute one instruction.. sir, plzzz tell me why is this happening..??

Shakil141 month ago

if i execute the "allon" instruction, next time when i say "alloff" it doesnt work.. infact i can only execute one instruction.. sir, plzzz tell me why is this happening..??

Shakil141 month ago
acap1231 month ago

Great!!!!!Sir I require the source code for the android application. Please mail me as early as possible on my id amirulacap92@gmail.com

sajeer1231 month ago

Hi am sajeer am note getting the out put please help me in this ..

hoply ur friend

caferd7 months ago

Hi , I will do the project. You use the Android phone but i have got a i phone .Can i use the i phone ? how can i control it ?

Try searching (build on) which send data through bluetooth, but as far as I know, bluetooth in IPhone is complicated to only send voice data

ASCAS (author)  caferd5 months ago

Sorry, I don't think the app has an apple counterpart.

Deepak_Dulal3 months ago

can we test it with only one LED?

Yes

ASCAS (author)  Deepak_Dulal3 months ago

Yes! Just remove all the "else if" before the "if statement" and you're good to go.

wildan.mai3 months ago

does the project needs Wi-Fi connection ?

Android Software connects to Bluetooth device. You have find the software which send Serial on Wifi instead of Bluetooth

Hi i am trying to make a mobile robotic arm.i want my robot to move 10 cm when i say robot go front 10 cm.so can you help me with code. I cannot understand how to take in the distance as a value of a variable from the voice string

try using this command. Instead of "Tv on" use this "front ten" then try speaking same. Use English words instead of numbers

I think there is one way. You can use time delay. once you say front 10 cm, your robot will move for time delay that is assigned for 10cm, maybe 2 secs or so.

daooda2 months ago

hi friend ,thank you for sharing this project >>> I just need to ask >>>can i use bluetooth module (HC-6)

because i made the project but it unable to connect with my phone

please reply soon

thanks so much

٢٠١٥٠٣٢١_١٨٤٨٤١.jpg٢٠١٥٠٣٢١_١٨٤٩٣١.jpg

Yes, You can use HC-06 Bluetooth Module. No problem with that. I have also used same module and it works

iceland.szt2 months ago

Hy! Is there any problem if instead of arduino uno I use Due? Thanks in advance.

fkaz72 months ago
Hai sir,could u mind sharing its source code to me .. i really need to have practise this project
.. plese mail me at nursyafiqah2626@gmail.com
diy_bloke fkaz72 months ago

have you seen step 5?

JackS4 made it!2 months ago

i made it

thanks man it is really awesome project

keep it up

IMG_1907.JPGIMG_1904.JPGIMG_1905.JPG
karthiG2 months ago
VineethK2 months ago

Hi sir..thanks for the project.....we found some problem with" tv on and off " "fan on /off"...then "all off".....these 3 commands are not working...i opened the serial monitor i found some voice char for tv on "tv on" but u use upper case...???? can u please give me an solution for this

lorenzdmng3 months ago

can I use a bluetooth shield?

lorenzdmng3 months ago

What is the possible solution if when I try to upload the file it also appear the error, not sync. Can anyone please help me. TIA

YogeshPatel3 months ago

Great!!!!!Sir I require the source code for the android application. Please mail me as early as possible on my id yogigotu1234@gmail.com

lorenzdmng3 months ago

How do you assemble your bluetooth module on the pcb? I can't see it clearly in the pictures. Please reply asap. Tia

1-40 of 180Next »