Instructables

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 109Next »

hi angelo i love your projects keep it up

but i am having some sort of problem the led dosent light up nor does the arduino get a serial command but when i put the module in at mode it reacts

i dont know what the problem is but please tell me a solution

amohsen55 days ago

I use HC-06 ,when i do this ,the first command applied but when i say anther command , there was no response for it !!!!!

akhilk26 days ago

hii..i am facing problem in the output. The command that i speak is displayed on the screen correctly but there is no output visible on the LEDs. And, yeah, HC-05 is connected to my android 4.4 kitkat.

Kindly solve this issue

vtrguy18 days ago

If I were you, I would use an initialized password and a menu option to actually toggle everything; you could even have that hard coded/changeable at an interface using an LCD or button series assuming the arduino is going to be secure.

If you haven't muddled with the BT pairing of the 05/06 the default 1234 could yield someone else using your goodies.

Paired with a door locking/security system may be a large vulnerability but it is a nice looking system with a couple of amendments!

ChristineM11 month ago

Can I do this with the HC 06? If i try to connect the HC 06 as you have connected the HC 05 it does not work.....I cannot see the connections clearly around the Bluetooth transmitter in photographs so it is hard to get it to work

imatxain1 month ago

Could the same be done with a wifi module? I would like to have this except that I would like to be able to execute the orders from another room or floor (I have a good router). Bluetooth can't be used from another floor. If the answer is yes, would I be able to follow this guide with that difference?

pls tell fast.....

can i use roboduino ATmega 328

http://robokits.co.in/shop/index.php?main_page=product_info&cPath=72&products_id=34

can i use roboduino ATmega 328

http://robokits.co.in/shop/index.php?main_page=product_info&cPath=72&products_id=34

can i use roboduino ATmega 328

http://robokits.co.in/shop/index.php?main_page=product_info&cPath=72&products_id=343

vak521 month ago

Hi! This is a great instructable! I have a problem though. For some reason my android device isn't sending the strings properly. I am using your code, but with the commands changed to things like "*red light on". When I open the serial monitor and type in my command (ex. *red light on#) and send it, it does what it is supposed to do. There is just some issue with my arduino receiving the strings from my android. By the way, I am using the JY-MCU bluetooth module.

Thanks for this awesome instructable and I'm looking forward to your home automation project :D

IMAG0230.jpgUntitled.png
Zerjio2 months ago

I´m using an Arduino Nano and a HC-05, I have problems with the data transmission. The Bluetooth is connected RX-->TX(Arduino), TX-->RX(Arduino), 5V-->5V(Arduino) and GND-->GND(Arduino). I tested the program only with the PIN13 but don't work. Any possible solution?

//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 = 13; //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

michaudtime3 months ago

This works great!! and it was a quick code change to remove the asterisk all I did was nest the char addition to be:

else if(c != '*') {voice +=c;} not sure if it's the most elegant way to do it but it works for me :-)

hi

For mobile phone, click the audio button code where before there android?

I would appreciate if you send me.

Project'll do it. I gave Banners electronic products. However, links will be like?

I would appreciate information.

thanks

mail: turkiye-facebook@windowslive.com

vgangwar1 made it!2 months ago

Cheers!
:D
Made it!
addition of delay command at appropriate places in the code made it work as expeted!

Aviary Photo_130478537984066022.png
ASCAS (author)  vgangwar12 months ago

Nice! :D

nichloe2 months ago

Hi there!

For the HC-05 Serial Bluetooth Module can we use this one?...

http://www.amazon.com/gp/product/B00JP05S6C/ref=gn...

Thanks!

ASCAS (author)  nichloe2 months ago

That should work! slr.

nichloe nichloe2 months ago

Never mind! I tried it and it worked! :)

nichloe made it!2 months ago

This was such a great project! I haven't done any electronics projects since last year. It was really intimidated going back into them because it was really difficult for me the first time around.

Thank you so much for this welcoming project. :)

IMG_20140624_222356.jpg
BhaveshTechz2 months ago

Hi Angelo, Can i use "Wireless 4 Pin Bluetooth RF Tansciever Module RS232" in place of HC-05 bluetooth module. The link of the product is this http://www.banggood.com/Wholesale-New-Wireless-Serial-4-Pin-Bluetooth-RF-Transceiver-Module-RS232-With-Backplane-p-43441.html

bluetooth module front.jpgbluetooth module back.jpg
ASCAS (author)  BhaveshTechz2 months ago

Yes, that should work.

jkabigting2 months ago

Can i use arduino nano? With your code?

ASCAS (author)  jkabigting2 months ago

Yes, as long as you use the same pin#.

javierrios733 months ago

hola a todos

Descargue el codigo y lo cargue en el arduino, monte el circuito en la proto y estoy usando un rn42 , no me funciona ..... alguien me puede ayudar?????

ryks javierrios732 months ago

mira porfavor a los cables rx con tx y a revers tx con rx(no rx-rx y tx-tx)me paso a mi y no me functiono....

javierrios73 ryks2 months ago
El tx y el rx estan conectados correctamente y no funciona aun no se que es lo que esta pasando
ryks javierrios732 months ago

puedes poner una foto aqui con las coneciones puestas???

Hola explica un poco mas haver si te puedo ayudar como lo conectastes? el bluetooth se conecta tu celular? as cambiado el Baud rate del bluetooth? que arduino usas?en fin un poco mas de info para ver donde esta el problema el código y el App funcionan muy bien.

Aun no, estoy iniciando con el modulo bletooth y no conozco mucho de eso, tienes watsapp? O un correo electronico mail?
Hi

Estoy usando un Arduino Uno R3 y un Bluetooth Modem - BlueSMiRF Silver RN42, si hay conexion entre el celular y el modem, programe el arduino con el codigo pero no funciona.

una pregunta as probado el arduino y el modulo de bluetooth con algun otro programa como el de encender un led via android app??

cartiman2 months ago

I will try to apply it to plc.

Thanks for you sharing. I like it.

ryks2 months ago

thank you .working well .

https://www.youtube.com/watch?v=Stq3RQYciUA

BhaveshTechz2 months ago

Hi Angelo, Can i use "Wireless 4 Pin Bluetooth RF Tansciever Module RS232" in place of HC-05 bluetooth module. The link of the product is this http://www.banggood.com/Wholesale-New-Wireless-Serial-4-Pin-Bluetooth-RF-Transceiver-Module-RS232-With-Backplane-p-43441.html

bluetooth module back.jpgbluetooth module front.jpg
eddieBeg3 months ago

hye, can I ask for the android source code please...I really appreciate it if you can send it by email to eddie.stf@gmail.com.....tQ

ASCAS (author)  eddieBeg2 months ago

you mean the Arduino source code?

eddieBeg ASCAS2 months ago
no the source code of the android apps.....I want to know how the process of data delivered...
ASCAS (author)  eddieBeg2 months ago

I'm not the developer of the app.

guruvaraja3 months ago

Very nice working at first attempt with your supplied code . I want to change the code for home automation , thanking you for guiding in this subject , expecting your next project for my inspiration .

1-40 of 109Next »