Introduction: Bluetooth Voice Interface for Autonomous Robots
I wanted the ability to give verbal commands to my robot. I looked into utilizing either speech to text software or speech to text hardware to communicate my commands to the robot. I found that the software and hardware readily available for micro controllers restricted the number of commands I could use. Android has speech to text and text to speech APIs that are freely available on their mobile platforms. Therefore, I decided to make use of the Android speech APIs.
The robot used for this project is the DFRobot Baron - 4WD Arduino Mobile Robot Platform. The microcontroller used is the Arduino Uno. I used the Adafruit Motor Shield for this project because it could handle four motors and it also handles the Pulse Width Modulation (PWM), therefore it does not need any Arduino GPIO pins to handle speed control for the robot.
To communicate with the phone, I used a HC-05 Bluetooth device. Since I used the HC-05 in client mode any Bluetooth device will work. I choose the HC-05 because it was cheap and it works. I used the DHT22 Temperature sensor because I had it laying around from another project. Any temperature sensor will work with modification to the Arduino sketch.
I used MIT's AppInventer to create the App on the phone side. AppInventer is a web-based IDE for mobile phone development. Instead of code it uses Code Blocks to create Apps. I do not think it is as powerful as Android Studio. However, it does not require as much technical expertise and it is quicker to develop for small projects.
For this this project, I only used a few commands to control the robot. However, it is easily extensible for use with as many commands as you need.
Sounds interesting? Read on.
Step 1: List of Required Hardware, Tools, and Software
This section lists the hardware, tools, and software used for this project. I listed the links I used to buy components. However, feel free to purchase your components from another vendor. I have a habit of purchasing items from Amazon due to the free 2-day shipping (I have Amazon prime). However, I may use other vendors if I make large purchases, or if the component is not available on Amazon. Items listed below that have no associated link, with the exception of the Android phone and PC/Laptop, were purchased at Walmart.
DSD TECH HC-05 Bluetooth Serial Pass-through Module: from Amazon
Shield Stacking Header Set for Arduino UNO R3: from Amazon
Male/Male Jumper Wires: from Adafruit
Standoffs - M2.5 Nylon Hex M-F Spacer/Screw/Nut Assorted Kit: from Amazon
9 volt battery
5 - 10 Rechargeable AA Batteries, NiMH, at least 2000 mAh
1in Wide Velcro Strips - For attaching the battery holders to the robot platform.
Bluetooth enabled Android phone or tablet.
PC / Laptop
Small Phillips screwdriver
Listed below is the software required for the project. All of the software is free. We will discuss the instructions for downloading and installing the software in later sections.
I used the DFRobot Baron for my robot chassis. However, you can use any robot chassis capable of hauling the required components. This includes the Arduino board, the motor controller, and batteries. If you want to add headlights to your robot you will need room on the front of the chassis to hold half of a half-size breadboard. If you want to use a temperature sensor, you need room to mount at least a half of a half-size breadboard for the temperature sensor. You can use a two-wheel drive chassis as well. It will just require wiring two motors to the motor controller instead of wiring four motors.
This project uses the Arduino Uno R3. However, the Due, Leonardo and Mega R3 are acceptable substitutes. Arduino clones will also work. Be cautious when choosing clones. Some clones are inferior to the original. However, remember that the Arduino boards are open source and it is acceptable to manufacture clones or make modifications to the original design. Some clones are manufactured with the same standards as the original Arduino boards and perform just as well.
This project uses the battery holder that comes with the DFRobot Baron kit to power the motors and a 9 volt battery to power the Arduino. You can substitute other batteries. Just make sure battery(s) that power the Arduino are in the 7-12 volt range. The DFRobot Baron motor voltage range is 4.5 to 6 volts. Check the power requirements for your chosen robot platform before selecting battery(s) if you are substituting the battery holder supplied with your kit.
If my robot dies due to dead batteries I like to get running again as soon as possible. Therefore, I have an extra set of charged batteries to swap out with the dead batteries. If you do not mind waiting for your dead batteries to charge your can just purchase five batteries. Otherwise, you may want to purchase 10 batteries so that you can charge one set of batteries while running with the other set of batteries.
If you substitute another sensor for the DHT22 Temperature-Humidity sensor there is no guarantee that the wiring or the code will work. The substitute sensor may use a different interface for its output. It may also use a different format for sending the data.
I am using the HC-05 Bluetooth module of this project. Other modules may work. However, like the DHT22 Temperature-Humidity sensor, I cannot guarantee that the wiring or the code will work with a different module.
Step 2: Assembling the Mobile Robot Platform - Part 1
This step covers assembling the DFRobot Baron - 4WD Arduino Mobile Robot Platform. If you have an assembled robot chassis or if you have a different robot chassis kit you can skip this step.
The DFRobot Baron kit does not come with instructions. However, you can download the instructions from the DFRobot website. The instructions for the DFRobot kit leaves out some of the details, especially when it comes to wiring. So, I decided to supplement the DFRobot instructions with my own instructions.
The first step is to mount the motors on the chassis. The Baron kits comes with two encoders. You can use the encodes to tell if the robot is moving, determine the speed of the robot, and how far the robot has moved. The encoders are not necessary for this project. Therefore, you can skip adding the encoders if you desire. However, if you want to add encoders in the future you will have to dis-assemble the chassis so you can mount the encoders to the motors. This can become problematic once you have added components to your chassis, such as a micro controller, motor controller, sensors, or a camera. Therefore, I decided to add the encoders now so I can use the robot for other projects that require encoders in the future.
Mounting a motor to the chassis with encoders is difficult. It takes a little patience to get it done. However, it is worth the effort.
First, mount the wheel encoder to one of the motors. The best way I found to do this is screw the self-tapping screw into the wheel encoder until it is sticking out of the other side (Figure 1). The screw is a tight fit. And that is the way we want it. We do not want it to slip as it spins on the axle because we will end up with inaccurate readings.
Next, screw the wheel encoder into the axle. It takes a lot of pressure to get the screw flush on the axle. I found using a needle-nose pliers to keep the motor from spinning worked best for me (Figure 2).
Once you have the encoder mounted on the motor, repeat the process with the second encoder with another motor.
Before we go any further we need to determine which end of the chassis is the front end since the motors with the encoders will be mounted to the front of the chassis. See Figure 3 to see which end I designated as the front end.
Now for the fun part. We need to mount the motor to the chassis with the encoder sensor. The order of the spacer, washers and nut are shown in figure 4. I noticed that the encoder sensor was rubbing against the encoder wheel, so I added a nut and washer next to motor body (Figure 5).
I slid a screw through the top hole in chassis and motor (make sure you use the long screws). I then tightened the motor to the chassis with a nut and slipped a washer on the screw and then slipped on the spacer. I slid a screw through the bottom hole in chassis and motor but did not tighten the nut. I wanted some wiggle room to attach the encoder sensor to the screws.
Then I slipped the encoder sensor onto the screws. I added the three washers and nut to the top screw and tighten the nut. I tightened the bottom nut flush with the motor. Then I added the three washers and nut to the bottom screw and tighten the nut. I found it easier to add the washers and nut from the bottom of the chassis. I wish I could tell you that there is some magical trick to could use to slip on the bottom washers and nut. However, I cannot. It took me several attempts to get them on and tighten the nut. You need patience and persistence here. Once you are finished with the first motor, repeat the process for the second motor.
The final result is shown in Figure 6. Notice that one encoder sensor is sitting higher than the other. This is normal.
Now, on to the next step.
Step 3: Assembling the Mobile Robot Platform - Part 2
We need to mount the other two motors to the rear of the chassis. This is much easier than mounting the front motors with encoders. Use a washer and nut on the screws you use to mount the motors to the rear of the chassis (Figure 1). That is it. Your motors are now mounted to the chassis.
While we are at it, mount the battery holder to the chassis. Use the two flat-head screws to mount the battery holder in between the motors (Figure 1).
Now mount the wheels onto the motors. Aline the wheel with the motor shaft and snap the wheel on. It takes a little more pressure than you might think.
After you mounted the wheels mount the switch to the upper plate of the chassis. Use the hole on the left side of the rear of the upper plate (Figure 2). Use a nut on the top part of the switch (Figure 2) and a washer and nut on the bottom part of the switch (Figure 3).
In preparation of wiring up the switch, solder two wires to the switch. One wire should be soldered to one of the outside terminals. It does not matter which one. And the other wire should be soldered to the middle terminal (Figure 4). I used a heavier gauge wire than the wire that came with the kit, a 22-AWG solid copper wire. Just my preference, in my opinion the 22-AWG wire is easier to insert into the motor controller terminals and into a breadboard.
I did not mount the power jack to the chassis since I do not plan to use it.
This step is optional. Mount the IR sensor mounting brackets on the top plate (Figure 5). Use two screws for the center mounting bracket and three screws for the outside mounting brackets. Mount the mounting brackets front slots on the top plate. These are not needed for this project. However they are easy to mount and will be ready for future projects.
I could not get the holes to aligned so that I could screw the top plate into the base plate of the chassis. So I screwed the top plate to the base plate using the two screw holes on the rear of the plate. I turned the chassis upside down. I inserted a metal paper clip into the threaded hole on the support arm and scratched the surface of the bottom of the top plate. I used the scratches as a guide to drill holes (1/8 inch drill bit) into the top plate (Figure 5). After I drilled the holes I turned the chassis right side up and screwed the top plate to the bottom plate. I only used the two front screw holes and the rear right screw hole. The other screw hole will be covered by the Arduino and I do not want to take off the Arduino every time I change batteries.
While I had the drill out, I enlarged the charger plug hole, (3/8 inch drill bit) to accommodate the 9-volt battery plug (Figure 6).
Step 4: Attach the Arduino Uno R3 to the Robot Platform
Now that we have a robot platform we can start mounting components onto it. We will start with the Arduino. Screw the standoffs into the Arduino. Note that one of the standoffs is too close to the headers to attach with a nut (Figure 1).
Cut a piece of Velcro about the size of the 9-volt battery holder (Figure 2). Attach one piece of the Velcro to the battery holder. If you have the top plate attached to the bottom plate, unscrew it and turn it over. Attach the other piece to the underside of the top plate (Figure 3). I avoided covering any holes in the plate in case I want to use the holes in the future.
I could only find two holes to use to mount the Arduino to the top plate (Figure 4 & Figure 5). However, just screwing in two standoffs is enough to anchor down the Arduino. Screw in the two standoffs closest to the front of the chassis. Then re-attach the top plate to the bottom plate.
Put a battery into the 9-volt battery holder. If your battery hold comes with a switch turn it on. Then attach the battery holder to the under of the top plate (Figure 6). Thread the battery holder plug through the enlarged hole or just bring it over the top plate, then connect it to the Arduino. You should see a yellow and a green LED light up on the Arduino (Figure 7). Our Arduino is ready to go.
Disconnect the plug when your Arduino is not in use to save battery power.
Step 5: Attach the Motor Controller to the Arduino Uno R3
Before we attach the motor controller board to the Arduino we want to add the stacking headers to the motor controller. Using stacking headers (Figure 1), instead of the headers that come with the motor controller allows us to stack the motor controller onto the Arduino and stack other boards onto the motor controller board in the future. This will reduce the footprint of the components and reduce the wring required to connect other components to the Arduino.
The easiest way I found to solder the headers to a circuit board is use two half-size breadboards to secure the headers. I used 6.25mm headers (figure 2) to attach the motor controller. I attached the 6.25mm headers to the stacking headers (Figure 3). Then I inserted the stacking headers in the appropriate holes in the motor controller. Finally, I mounted the motor controller onto the breadboards (Figure 4). Make sure the headers are flush to the board before you begin soldering (Figure 5). It is difficult to remove the headers, without ruining the board, once the headers are soldered in place. Also, make sure that you solder the headers to the correct side of the board ( Figures 6 & 7). Note that the 6 pin, double-row header is mounted in the opposite direction when compared to the other stacking headers (Figures 6 & 7).
Do not worry if you are new to soldering. It is not as hard as it looks if you use the proper tools. I am not mechanically inclined. So believe me when I say," If I can do it anyone can". If you are new to soldering, here are two excellent soldering guides:
After you solder the headers to the motor controller mount the motor controller on the Arduino (Figure 8).
Now you are ready for the next step.
Step 6: Wiring the Motor Controller - Part 1
Its time to connect the motors to the motor controller. First we want to connect the power to the motor controller. Ensure you have the polarity correct when connecting the wires from your battery holder to the motor controller. Feed the red wire from the switch through a hole on the top plate and connect it to the positive power terminal on the motor controller (Figure 1). Feed the black wire from the battery holder through a hole on the top plate and connect it to the negative power terminal on the motor controller. Turn the switch on. The green LED on the motor controller should light (Figure 2). You now have power to the motor controller.
Feed the motor wires through any unused holes in the top plate. Make sure you keep track of which wires belong to which motors.
Step 7: Wiring the Motor Controller - Part 2
Your robot is like a train. The wheels are powered by electricity so you have to specify which end of your robot is the front end and which end is the rear end. Your DC electric motors do not care which direction they turn. They run equally well in either direction. Figure 1 shows which end I decided to call the front end.
Once you determine which end is the front end of your robot you need to hookup the motors so that they run in the forward direction by default. Lift the wheels off the floor or desk. A short 2 by 4 works. Switch the motor controller off. Insert the two wires from the left rear motor in the M1 terminals (Figure 2) and tighten the terminal screws. Do not use the middle terminal (GND). Switch the motor controller on. If the wheel turns counterclockwise leave the wires as they are. If the wheel turns clockwise, turn off the motor controller and switch the wires. Turn on the motor controller. The wheel should turn counterclockwise.
Switch the motor controller off. Insert the two wires from the right rear motor in the M2 terminals (Figure 2) and tighten the terminal screws. Do not use the middle terminal (GND). Switch the motor controller on. If the wheel turns counterclockwise leave the wires as they are. If the wheel turns clockwise, turn off the motor controller and switch the wires. Turn on the motor controller. The wheel should turn counterclockwise.
Switch the motor controller off. Insert the two wires from the left front motor in the M3 terminals (Figure 2) and tighten the terminal screws. Do not use the middle terminal (GND). Switch the motor controller on. If the wheel turns counterclockwise leave the wires as they are. If the wheel turns clockwise, turn off the motor controller and switch the wires. Turn on the motor controller. The wheel should turn counterclockwise.
Switch the motor controller off. Insert the two wires from the right front motor in the M4 terminals (Figure 2) and tighten the terminal screws. Do not use the middle terminal (GND). Switch the motor controller on. If the wheel turns counterclockwise leave the wires as they are. If the wheel turns clockwise, turn off the motor controller and switch the wires. Turn on the motor controller. The wheel should turn counterclockwise.
We have completed the writing of the motor controller. Now it is time to add the other components.
Step 8: Add the HC-05 to the Arduino
It is time to hook up our Bluetooth device, the HC-05. First add a half-size breadboard to your robot platform (Figure 1). Next, mount your HC-05 to the breadboard (Figure 2).
Before we use our HC-05 we need to verify its settings. There is an excellent Instructable on how to view and change the HC-o5 settings at:
Figure 3 shows my wiring while verifying the setting.The only discrepancy I found with the tutorial was my HC-05 Baud rate was set at 9600 instead of 38400. Therefore, I had to set my serial monitor to 9600. Figure 5 contains my default settings for the HC-05. These settings will work for this project so I did not have to change any of the settings. After you are finished with verifying the HC-05 settings disconnect all of the wiring. We will write it differently for the project.
Now, attach a jumper wire from the receive pin on the HC-05 to pin 4 on the Arduino. Attach a jumper wire from the transmit pin on the HC-05 to pin 3 on the Arduino.
To add power to the HC-05, add a jumper wire from 5-volt pin on the Arduino to a positive pin on the breadboard's power rail. Also, add a jumper wire from a ground pin on the Arduino to the ground pin on the breadboard's ground rail. Now, attach a jumper wire from the breadboard power rail to the VCC pin on the HC-05. To complete connections attach a jumper wire from the ground rail on the breadboard to the ground pin on the HC-05. Our HC-05 is now connected to the Arduino (Figure 4).
Step 9: Pair the HC-05 With Your Phone
It is time to pair the HC-05 with your phone. The HC-05 is not a Bluetooth LE device so it will not pair with a iPhone. You must use an Android compatible phone. I will use my phone for the example. The steps you use will varying depending on your phone.
- Press on the Settings App.
- Press Connections (Figure 1).
- Press Bluetooth (Figure 2).
- The Bluetooth device will scan for new Bluetooth devices.
- The found devices are displayed in the Available Devices Section (Figure 3).
Your HC-05 is now paired with your phone.
Step 10: Add the Temperature Sensor
Now, let us hook up the temperature sensor. Mount the temperature sensor on the breadboard Figure 1. Attach a jumper wire from the power rail of the breadboard to the VCC pin on the temperature sensor. Attach a jumper wire from the ground rail on the breadboard to the ground pin on the temperature sensor. Connect the data pin on the temperature sensor to pin 2 on the Arduino.
The temperature senor is now ready to send data to the Arduino (Figure 2).
Step 11: Add Headlights
Now let us add headlights to our robot. We need to mount a breadboard to the front of our robot. You could mount a half-size breadboard. However, I sawed a half-size breadboard in half with a jigsaw which contained a fine blade (Figure 1). I used a hot glue gun to mount the breadboard to the frame of the robot.
Now, connect a jumper wire from Pin 7 on the Arduino to the power rail on the breadboard you just mounted. Connect another jumper wire from the Ground Pin on the Arduino to the ground rail on the breadboard you just mounted. View Figure 2 to see how the connections are made to the breadboard.
Its time to mount the LEDs. Notice that a LED has one leg that is longer than the other leg (Figure 3). This call the anode or positive end. The shorter end is called the cathode or negative end. The current flows from the positive end to the negative end. If you connect your LED wrong it will not light. Just switch the legs round so the current is flowing in the correct direction.
The LEDs stick out past the frame of the robot when you insert one into the breadboard. Cut the legs so that they are flush with the breadboard. Make sure you cut the anode end longer than the cathode end so you know which end is the positive end.
Now, insert the LEDs into the breadboard as shown in Figure 4. Connect a jumper wire from the power rail to the anode leg of the left LED. Connect a jumper wire from the ground rail to the cathode leg of the right LED. Connect a jumper wire between the left and right anode legs. Connect a jumper wire between the left and right cathode legs.
We can test the headlights by modifying the MotorTest.ino as shown in Figure 5. The changes are in Lines 13, 16, 22, 24, 25, and 26. The complete code resides on GitHub at MotorTestWithHeadlights.
Upload the sketch and you finish making the modifications. Switch the motor controller off since we are not testing the motors. The LEDs should light for 2 seconds, then turn off for 2 seconds.
Step 12: Create Arduino Sketch - Initialization
Its time to start coding. We will start by creating an Arduino sketch. Open the Arduino IDE and click on File, then New. Replace the code inside the sketch with the code on GitHub at BluetoothRobot.
The sketch now contains the code required for the robot to accept voice commands and send message back to the phone. In a later step we will discuss the code required for the phone to capture voice commands and send the command to the robot.
You can download the code on GitHub at BluetoothRobot. I have included a description on how the sketch works below. The line number I reference are the line numbers used on GitHub.
Lines 1-3 are used to include the libraries required to compile and run the sketch. The SoftwareSerial library allows us to use serial ports other at 0 and 1. The Adafruit_MotorShield library is required to access the Motor controller. The DHT library is required to read data from the DHT22.
If you do not have these libraries loaded into your Arduino IDE and not know how to load libraries, refer to this link to learn more about how to load libraries:
Lines 5-12 creates the Adafruit_MotorShield object and sets up the motors for use.
Lines 14-18 define the constants used by the sketch. It allow you to use these variables in multiple places in the sketch. However, if you want to change the value of one of these variables you would do that here.
Lines 20-22 creates the array to hold the valid keywords used to control the robot. The CONNAND_ARRAY_SIZE variable will always contain the number items in the robotCommands array. Therefore, you can use the CONNAND_ARRAY_SIZE variable in your loops and not have to if your loops will fail if you add or delete any items in the robotCommands array.
Line 24 create a BTserial object with the receive port on Pin 3 and the transmit port on Pin 4.
Lines 26-32 contain variables used by the sketch. The use of these variables will be described in the steps that discusses the functions that uses them.
Lines 34-39 Creates the DHT object, initializes the sensor, and defines the variables needed to process the DHT data (Temperature & Humidity).
Line 43 initializes the Motor controller.
Line 45 sets the HEADLIGHTS_PIN as an output pin.
Lines 46-47 sets the mode for the Software Serial ports.
Lines 49-50 initializes the serial ports.
Line 51 initializes the DHT22 sensor.
Line 53 Sends a message to the serial debug port, which is displayed on the serial monitor.
The loop function consist of 16 lines, 56-71.
Line 58 checks for data from the phone. If data is found the receivedData buffer is initialized to 0.
Line 64 reads the data on the serial line.
Lines 65-58 calls the GetCommand function if the first byte in the receivedData buffer is an ASCII character. The code assumes if the first byte in the receivedData buffer is not a ASCII character then it is a transmission error and ignores the data.
Step 13: Create Arduino Sketch - Motor Functions
In this section we will discuss the code required to drive the motors.
Lines 73-207 contain the motor function. Lines 73-155 contain the functions that specify which direction the motors should turn to move the robot in the desired direction. There is a function to move the robot forward, move it backwards, turn it to the right, turn it to the left, and stop it. Each function calls the 4 motor functions to move each motor in the appropriate direction. These functions are called by the switch command which starts on line 223.
The motor's speed is controlled by pulse width modulation (PWM). The PWM is handled by the motor controller. Therefore, none of the PWM pins on the Arduino are used. The Speed variable used in the motor function can be set from 0 to 255. The Speed variables are set to 100 via the DEFAULT_SPEED constant. You can the DEFAULT_SPEED constant to increase or decrease the speed. The milliSeconds variable is set to 2200 milliseconds via the MILLISECONDS constant. The milliseconds variable is used in the delay statement to determine how far the robot will turn left or right. You can change the MILLISECONDS constant value if you desire.
The functions in Lines 157-207 move the individual motor in desired direction (forward or backwards) and speed.
This function processes the data received from the phone.
In line 211 the data is moved into a string buffer.
The commandFoundAtIndex variable is initialized in line 212.
Lines 214-221 looks for a valid command. It checks to see if one of the phrases in the robotCommands array is contained in the string sent by the phone. If a phrase is found its index number is stored in commandFoundAtIndex.
The switch statement in lines 223-291 executes the appropriate command based on the value in the commandFoundAtIndex variable. There is a case statement for every command in the robotCommands array. In each case statement a message will be generated and sent to the debug port to be displayed on the serial monitor. That same message is sent to the phone where the message is displayed on the phone and also sent to the text-to-speech module for output through the phone's speaker. The case statement will call the appropriate function to execute the command.
Note that a message will only display on the serial monitor if the Arduino is tethered to your PC.
The GetNumber function in lines 295-331 is used to determine if the move forward or move backwards commands request that the robot only move a specified amount of time, in seconds. It is call by case 0, 1, 5, and 6 in the switch statement.
Lines 297-302 initializes the numberIndex and moveSeconds variables and the numberBuffer array.
Lines 303-316 checks the command from the phone for any digits. The digits found are stored in the numberBuffer. The contents of numberBuffer is converted into a string (numbericStringBuffer). The string is converted into an integer (moveSeconds). moveSeconds is used in the delay statement, so it is multiplied by 1000 to convert it into milliseconds.
If no digits are found by the GetNumber function the case statement will move the robot in the desired direction until another command is given. Otherwise, the robot will the amount of milliseconds given it the variable moveSeconds.
Sometimes the speech-to-text function on the phone will display the word for a number instead of a digit. Lines 319-329 are used to handle those cases. It searches for a particular word and converts it to a digit, then converts the number into milliseconds. I only ran into two instances of this ("one" and "to"). If you run into any other instances of a digit displaying as a word, add code here to rectify the problem.
Step 14: Create Arduino Sketch - Temperature Sensor
In this section we will cover the temperature/humidity sensor. As covered in previous sections, before we can use the sensor we must:
- Include the DHT library (Line 3).
- Define the data pin, sensor type, and create the DHT object (Lines 34-36).
- Define the variables to store the data (Lines 37-39).
- Initialize the sensor (Line 51).
If the GetCommand function detects a request for temperature/humidity data (Case10 and 11) it will call the getTemperature function in line 283.
The getTemperature function will query the sensor for the temperature and humidity (Lines 335-336). If the data cannot be read an error message is generated. If the data is successfully read the data is stored in the sendTemperature variable (Lines 343-346).
Finally, in the case statement, the data is sent to the serial monitor and to the phone (Lines 284-285).
Step 15: Create Arduino Sketch - Headlights
There is not much code for the headlights. The HEADLIGHTS_PIN constant is defined to specify the pin used to power the headlights (Line 16). The pin is set to output on Line 48.
Finally, the pin is set to high in the case statement to turn on the headlights (Line 271-275) or the pin is set to low to turn off the headlights (Lines 276-280).
Step 16: Create Bluetooth Android Code
Instead of using Android Studio to create the phone App I decided to try MIT's AppInventer. I do not think it is as powerful as Android Studio. However, it does not require as much technical expertise and it is quicker to develop for small projects. I do not know if I would use it to create a large program.
Figure 1 contains the main screen for the App. The App contains Three buttons. One button to connect the phone to another Bluetooth device. Another button to disconnect a connected Bluetooth device. And a button to allow you to speak to the robot. In between the buttons are text areas that display status messages, display android thought you said, and the response sent back from the robot.
Figure 2, Figure3, and Figure 4. Display the code blocks for the App. These are the instructions the App will execute.
Figure 2. Shows the code blocks used to initialize the screen and initialize variables.
Figure 3 shows the code blocks for voice processing. This includes sending and receiving messages to/from the HC-05, processing spoken text, speaking text send by the robot, and speaking any status message generated by the App.
Figure 4 shows the code blocks used for connecting a Bluetooth device (The HC-05).
If you are interested in learning AppInventor check out the links below:
You can download my App from GitHub BluetoothTestII.aia
Once you downloaded it and imported into AppInventor on your PC you can use it to control your robot. Also, feel free to modify it to your hearts content.
Step 17: Robot Demonstration - Part 1
Before we can start the demonstration we need to start the App an the phone. If you have not loaded the MIT AI2 Companion App on your phone, now is the time to do it. Start the Google Play App on your phone. Enter MIT AI2 Companion to downdload the App.
First, browse to your MIT AppInventor account (Figure 1). Click on Connect, then click on AI Companion.
A popup window will appear with the code required to start your phone App (Figure 2).
Start the MIT AI Companion App on your phone (Figure 3).
Type in the code display in the popup window (Figure 4).
The MIT AppInventor site will initialize your App (figure 5).
Your App is now initialized. Continue to Robot Demonstration - Part 2.
Step 18: Robot Demonstration - Part 2
Once the MIT AI2 Companion App is initialized it will display the main menu (Figure 1). Notice that we are not connected to the robot (Status: Not Connected).
Press the Connect button and the App will display a list of devices available for connection (Figure 2). Press on the desired device.
Notice that the status is now Connected (Figure 3).
We are ready to go to Robot Demonstration - Part 3.
Step 19: Robot Demonstration - Part 3
Now we are ready to control the robot. We will start with the commands to move the robot.
Press the Microphone button. The App will ask you to say something (Figure 2). Say "Robbie move forward" (Figure 2). Note that you do not have to say "Robbie", the robot will respond to any name or no name. The Robot will respond by saying "Moving forward". Note that anything you say or anything that the robot responds with is displayed on the screen. The robot will continue to move until you issue another command.
Press the Microphone button and say "Robbie stop". The robot will stop (Figure 3).
Press the Microphone button and say "Robbie move backwards" (Figure 4). The robot will move backwards until you issue another command.
Press the Microphone button and say "Robbie stop". The robot will stop (Figure 3).
Press the Microphone button and say "Robbie turn right" (Figure 5). The robot will turn to the right and stop.
Press the Microphone button and say "Robbie turn left" (Figure 6). The robot will turn to the left and stop.
Press the Microphone button and say "Robbie move forward 4 seconds. The robot will move for 4 seconds and then stop.
We are not ready to access our sensors. Go to Robot Demonstration - Part 4.
Step 20: Robot Demonstration - Part 4
This is the last part of our demonstration. First, we will turn the headlights on and off.
Press the Microphone button and say "Robbie turn lights on" (Figure 1.). The headlights will light up.
Press the Microphone button and say "Robbie turn lights off" (Figure 2.). The headlights will go off.
Now for the temperature sensor:
Press the Microphone button and say "Robbie what is the temperature" (figure 3). The robot will respond with the current temperature and humidity readings from the sensor.
Go to Robot Demonstration - Part 5 to see the demonstration in action.
Step 21: Robot Demonstration - Part 5
Step 22: Summary
The goal of the project was to built a voiced controlled robot. The main requirement was incorporating an extensible set of robot commands that the robot would obey. To accomplish this requirement I created an array of commands. Anytime I want to add a robot command all I have to do is add the command to the array, add a case in the switch statement, and add the logic for the command.
I used the android speech-to-text and text-to-speech functionality to communicate with the robot. I utilized the MIT App Inventor to build the Phone App. To demonstrate how the voice controlled robot operates, I added a temperature sensor and headlights to a four-wheel drive robot chassis.
This project shows that you can build voice controlled robot with an extensible set of commands. The only restriction for the present implementation is the amount of memory your micro controller contains. Although, you can overcome this restriction by adding a SD card module to your micro-controller. You could store your commands on a SD card in stead of storing your commands in an array, giving a unlimited amount of store for your commands.
Participated in the