loading

To make this voice controlled vehicle, you need a robotic platform, an Arduino board and some mp3 modules.

Step 1: Making a Platform

The platform I used to build this robot was the Cherokey 4WD platform. The first step was to get the robot to move – this was the easy part.

The great thing about this kit is that it includes everything you need to get it moving – it has its own set of motors and motor drivers and a Romeo V2 microcontroller, so all you need to do is add extra modules to make it do what you want it to do. To put the platform together you will need to solder some wires to each motor and then wire them in to the screw terminals on the motor driver board (M1, M2, M3 and M4). In order to connect the microcontroller to the kit, you need to connect D4, D5, D6, D7 pins on the Cherokey platform to pins 4, 5, 6, 7 on the microcontroller with jumper wires (or you can solder them if you prefer for a permanent solution). You are now ready to program the microcontroller to get it moving! There is a sample code included on the DFRobot Wiki page, which can be found here.

In the sample code there are four basic functions controlled by key inputs in the serial monitor. Press “w” to go forward, press “a” to turn left, press “d” to turn right, press “x” to stop and press “z” to print “hello” in the serial monitor. This is a good test to see if the platform works as you need it to, and all the motor directions are correct. If you have problems with a motor’s direction, you can try changing the direction pins to either HIGH or LOW in the code, or for a low-tech solution you can simply reverse the polarity of the wiring in the motor binding posts on the Cherokey platform.

The code I used is as follows:

<p>int E1 = 5;     //M1 Speed Control<br>int E2 = 6;     //M2 Speed Control
int M1 = 4;     //M1 Direction Control
int M2 = 7;     //M1 Direction Control
 
void stop(void)                    //Stop
{
digitalWrite(E1,0);
digitalWrite(M1,LOW);   
digitalWrite(E2,0);  
digitalWrite(M2,LOW);   
}  
void advance(char a,char b)          //Move forward
{
analogWrite (E1,a);      //PWM Speed Control
digitalWrite(M1,HIGH);   
analogWrite (E2,b);   
digitalWrite(M2,HIGH);
} 
void back_off (char a,char b)          //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);  
analogWrite (E2,b);   
digitalWrite(M2,LOW);
}
void turn_L (char a,char b)             //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);   
analogWrite (E2,b);   
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b)             //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);   
analogWrite (E2,b);   
digitalWrite(M2,LOW);
}
 
void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT); 
Serial.begin(19200);      //Set Baud Rate
Serial.println("Run keyboard control");
digitalWrite(E1,LOW);  
digitalWrite(E2,LOW);
 
}
 
void loop(void)
{
if(Serial.available()){
char val = Serial.read();
if(val != -1)
{
switch(val)
{
case 'w'://Move Forward
advance (255,255);   //move forward in max speed
break;
case 's'://Move Backward
back_off (255,255);   //move back in max speed
break;
case 'a'://Turn Left
turn_L (100,100);       
break;      
case 'd'://Turn Right
turn_R (100,100);
break;
case 'z':
Serial.println("Hello");
break;
case 'x':
stop();
break;
}
}
else stop(); 
}
 
}</p>

Step 2: Adding Voice Control

I used a DFRobot Voice recognition board for this. The SKU is DFR0177, but it is only available in China right now!

Unfortunately when trying to add voice control functionality, I experienced problems. After getting in touch with one of the engineers at DFRobot, they told me that the Romeo V2 board was based on an ATmega32u4 chip, which would not support my voice recognition module. This was irritating, but I didn’t let that stop me. I swapped my Romeo V2 board for a DFRduino UNO R3 and then tried again.

Here is a code I used:

#include
#define SUM 2 //variable no greater than 50 uint8 nAsrStatus=0; char sRecog[SUM][80] = {"turn on lights", "turn off lights"};//variable not greater than 79, user can modify int state=7; //status indicator int led=8; //control digital port void finally (unsigned char n) { switch(n) //array corresponding keyword serial number, such as arrays recognise the first keyword is “turn on lights” and corresponding sequence number is 0; { case 0: Serial.println( "turn on lights"); Serial.println( " "); digitalWrite(led,LOW); break; case 1: Serial.println( "turn off lights"); digitalWrite(led,HIGH); break; default: Serial.println( "error"); Serial.println( " "); break; } } void ExtInt0Handler () { Voice.ProcessInt0(); //send an interrupt signal } void setup() { Serial.begin(9600); Voice.Initialise(MIC,VoiceRecognitionV1);//Initialise mode MIC or MONO,default is MIC //VoiceRecognitionV1 is VoiceRecognitionV1.0 shield //VoiceRecognitionV2 is VoiceRecognitionV2.1 module attachInterrupt(0,ExtInt0Handler,LOW); pinMode(led,OUTPUT); pinMode(state,OUTPUT); digitalWrite(state,HIGH); digitalWrite(led,HIGH); } void loop() { uint8 nAsrRes; nAsrStatus = LD_ASR_NONE; while(1) { switch(nAsrStatus) { case LD_ASR_RUNING: case LD_ASR_ERROR: break; case LD_ASR_NONE: { nAsrStatus=LD_ASR_RUNING; if (Voice.RunASR(SUM,80,sRecog)==0) //incorrect identification { nAsrStatus= LD_ASR_ERROR; Serial.println( "ASR_ERROR"); } digitalWrite(state,LOW); Serial.println( "ASR_RUNING....."); break; } case LD_ASR_FOUNDOK: { digitalWrite(state,HIGH); nAsrRes =Voice. LD_GetResult();//once asr recognition process ends, pick up asr recognition results finally(nAsrRes); nAsrStatus = LD_ASR_NONE; break; } case LD_ASR_FOUNDZERO: default: { nAsrStatus = LD_ASR_NONE; break; } }// switch delay(500); }// while }

char sRecog[SUM][80] = {"turn on lights", " turn off lights"} can be used to give the vehicle voice control features. We can change this section to add the features we want, such as “go forward”, “go back”, “turn left”, “turn right”, “stop”, etc. We will also need to modify the “void finally()” function. In case 0, the first command is advance, so we can output “go forward” from “Serial.println()” and call to the function “advance” at the same time. When the voice recognition module detects the “advance” function, it will output go forward and the vehicle will move forward. The same applies for the other directions.

One of the limitations of this project is that the voice recognition module isn’t always accurate, because of different users’ voices, ambient noise and other factors. This will be improved in future examples.

The code is as follows:

#include
//#include //ruan chuankou #define SUM 5 //SUM uint8 nAsrStatus=0; //SoftwareSerial mySerial(10, 11); // RX, TX char sRecog[SUM][80] = {"qian jin", "hou tui","zuo zhuan", "you zhuan","ting zhi"};// int E1 = 5; //M1 Speed Control int E2 = 6; //M2 Speed Control int M1 = 4; //M1 Direction Control int M2 = 7; //M1 Direction Control void stop(void) //Stop { digitalWrite(E1,0); digitalWrite(E2,0); } void advance(char a,char b) //Move forward { analogWrite (E1,a); //PWM Speed Control digitalWrite(M1,HIGH); analogWrite (E2,b); digitalWrite(M2,HIGH); } void back_off (char a,char b) //Move backward { analogWrite (E1,a); digitalWrite(M1,LOW); analogWrite (E2,b); digitalWrite(M2,LOW); } void turn_L (char a,char b) //Turn Left { analogWrite (E1,a); digitalWrite(M1,LOW); analogWrite (E2,b); digitalWrite(M2,HIGH); } void turn_R (char a,char b) //Turn Right { analogWrite (E1,a); digitalWrite(M1,HIGH); analogWrite (E2,b); digitalWrite(M2,LOW); } void finally (unsigned char n) { switch(n) // { case 0: Serial.println( "qian jin"); Serial.println( " "); advance (255,255); break; case 1: Serial.println( "hou tui"); back_off (255,255); break; case 2: Serial.println( "zuo zhuan"); turn_L (100,100); break; case 3: Serial.println( "you zhuan"); turn_R (100,100); break; case 4: Serial.println( "ting zhi"); stop(); break; default: Serial.println( "error"); Serial.println( " "); break; } } void ExtInt0Handler () { Voice.ProcessInt0(); // } void setup(void) { int i; for(i=4;i<=7;i++) pinMode(i, OUTPUT); Serial.begin(19200); //Set Baud Rate Voice.Initialise(MIC,VoiceRecognitionV1);//Initialise mode MIC or MONO,default is MIC //VoiceRecognitionV1 is VoiceRecognitionV1.0 shield //VoiceRecognitionV2 is VoiceRecognitionV2.1 module attachInterrupt(0,ExtInt0Handler,LOW); } void loop() { uint8 nAsrRes; nAsrStatus = LD_ASR_NONE; while(1) { switch(nAsrStatus) { case LD_ASR_RUNING: case LD_ASR_ERROR: break; case LD_ASR_NONE: { nAsrStatus=LD_ASR_RUNING; if (Voice.RunASR(SUM,80,sRecog)==0) // { nAsrStatus= LD_ASR_ERROR; Serial.println( "ASR_ERROR"); } Serial.println( "ASR_RUNING....."); break; } case LD_ASR_FOUNDOK: { nAsrRes =Voice. LD_GetResult();// finally(nAsrRes); nAsrStatus = LD_ASR_NONE; break; } case LD_ASR_FOUNDZERO: default: { nAsrStatus = LD_ASR_NONE; break; } }// switch delay(500); }// while }

Realize the functionDownload the program on the board card to conduct test. When we say “advance”, the vehicle will call “advance”()function, then moves forward. It is the same with other movements. When it is working satisfactorily, we can unplug the USB cable and install a lithium battery so that the vehicle is more mobile.

Step 3: Combine Voice Recognition With MP3 Module

Even with successful voice control, it seems like something is missing. What if the vehicle can respond to us? By adding an mp3 module to the setup, this will be possible. I used an mp3 player module – the DFRDuino player module.

One thing worth noticing is that you’d better put on a tape on the back of the module to prevent short circuit while using it. As for the wiring, mp3 module has a serial pin port, providing five pins including 5V, GND, RX, TX, OUT.

Wire the pins except for OUT to the mp3 wiring port of voice recognition module as Picture 2.

5V corresponds to 5V. GND corresponds to GND. RX should be connected with TX and TX should be connected with RX as shown as Picture 3.

We add a small speaker here.

Step 2: Programming

We need to program it after finishing the wiring. MP3’s player code will be added based on previous program. Audio files are stored on a micro SD card, you can use any that you want to correspond to each response. Perhaps you could record your own responses so that it sounds like you can chat with the robot). Please be noted that we are using serial port communication, so the button on the voice recognition module should point to UART instead of 12C.

The code I used is as follows:

void finally (unsigned char n)
{ switch(n) // { case 0: Serial.println( "qian jin"); Serial.println("\\qian"); advance (255,255); break; case 1: Serial.println( "hou tui"); Serial.println("\\hou"); back_off (255,255); break; case 2: Serial.println( "zuo zhuan"); Serial.println("\\zuo"); turn_L (100,100); break; case 3: Serial.println( "you zhuan"); Serial.println("\\you"); turn_R (100,100); break; case 4: Serial.println( "ting zhi"); Serial.println("\\zhi"); stop(); break; case 5: Serial.println( "chang ge"); Serial.println("\\bo"); Serial.println("\\2"); break; case 6: Serial.println( "zan ting bo"); Serial.println("\\:p"); break; case 7: Serial.println( "ji xu bo"); Serial.println("\\:s"); break; case 8: Serial.println( "xia yi shou"); Serial.println("\\:n"); break; case 9: Serial.println( "shang yi shou"); Serial.println("\\:u"); break; default: Serial.println( "error"); Serial.println( " "); break; } }

Step 3: Realize the function

I would like to explain the key codes listed above. Adding Serial.println("\\qian") to case 0 is to have MP3 play an audio named【qian】 in SD card. Similarly, adding Serial.println("\\hou") to case 1 is to have MP3 play an audio named【hou】. Serial.println("\\:p") means “stop” and Serial.println("\\:s") means “continue”. Serial.println("\\:n") signifies playing next one. Detailed introduction of these orders is available in online store.

Download the program then you can control this vehicle with voice in a comprehensive manner. When we send out the order of “advance”, mp3 will play “execute the order of advance”. It is the same with other orders. One thing worth noticing is that we add the function of “playing music” for this vehicle and it can recognize several orders such as “play”, “pause”, “continue”, previous one” and “next one”.

About This Instructable

498views

6favorites

License:

More by EmmaSong:How To Build a  Basic Arduino Robot How to Make a Pet Wearable How to Make a Terrifying Halloween Gadget (Arduino-Based) 
Add instructable to: