Introduction
Valentine’s day is a way behind is, but you know what they say, it is always a right time to say your loving ones how you feel about them. And your Arduino definitely deserves it.
That’s right, you can talk to your Arduino system using voice recognition of your smart phone. Connection between your electronic pets is good old Bluetooth, so no need to worry about cable lengths or cables in any sense. What I’m going to describe in this post is quite simple: attach the Bluetooth module to the Arduino board (I use Duemilanove, with Atmega 328 on board), download the app on your Android phone, and start talking with your Arduino. I am sure it missed you a lot.
Bluetooth Module
I purchased a very cheap and popular HC-06 module from e-Bay for something like $6.00. If you are eager to learn more about this lovely piece of hardware, this guy made a such pretty analysis. If you are not, all you need to know is that it has embedded Bluetooth (version 2) reception and serial communication modules and it is quite simple to use it with any ordinary microcontroller. It supports both TTL and CMOS input/output standards, so there is no fear of burning it down if you’re a maniac with 5V system.
Connecting this module to your Arduino requires no more than four (4) wires, two for 5V power supply and two for serial communication. The module has designated pins RX and TX which are in standard serial communication envisaged for (r)eception and (t)ransmission of the data. Be careful, though. Your Arduino will also have a serial port with RX and TX pins and if you want to have a nice and polite conversation between Arduino and Bluetooth module, keep in mind that RX of Arduino goes to the TX pin of module and vice-versa. If all of the above is not enough, here’s a wiring diagram. Don’t blow it up now.
Arduino Code
Arduino has one serial port which all of us have used to print “Hello World!”, “boobs” or some other bad words on the serial monitor when we played with it for a first time. But did you know that you can create as many other serial ports on Arduino as you want (and as they are less then five)? That’s right! Masters of AVR have enabled us to convert any digital pins into the RX, TX pair for a serial communication. A really helpful tool to make this possible is Arduino’s SoftwareSerial library. Basically, it enables us to create an object which has all properties of the original serial functions but with arbitrary choice of pins. I decided to use this one for communication with the Bluetooth module, since I’ll be using the original one for the communication with the PC.
So, the code goes like this:
#include <SoftwareSerial.h> #include <string.h> // HC-06 Serial Setup #define rxBT 3 #define txBT 2 SoftwareSerial serialBT = SoftwareSerial(rxBT, txBT); String voice = ""; char c = '0'; void setup() { pinMode(rxBT, INPUT); pinMode(txBT, OUTPUT); Serial.begin(9600); serialBT.begin(9600); } void loop() { while (serialBT.available() && c!= '#'){ //Check if there is an available byte to read, and if it is end of the command delay(10); //Don't rush, give it some time c = serialBT.read(); //Read the data from serial port voice += c; //Add to string } if (voice.length() > 0) { Serial.println(voice.substring(1, voice.length()-1)); //print string to serial port, but cut * and # voice = ""; //Reset the variables c = '0'; } }
Small description of the code: first we create constructor for serial communication and begin the communication. Then, in the main loop, we wait until there is something Bluetooth wants to say and extract the bytes into the string called voice
. Later, the received data is transferred via second serial port to the PC. The data always starts with character “*” and ends with “#”, and that’s why I use substring
method to extract the given text.
Android app

There’s not much to say about the app. It uses standard Android voice recognition and pairs it with the Bluetooth protocol. Download it here, start it, connect with your HC-06 (if it brags about the password, try 1234 or 0000, it should work) and open your heart to your Arduino. Btw, I am not the one who takes credit for this app. I tried, unsuccessfully, to find the author on web. If you, dear SimpleLabsIn, see this, know that I’ll praise your name to the peoples of the world!
One thought on “Say to your Arduino how much you love it”