Components and supplies
Grove Speech Recognizer
Arduino UNO
Project description
Code
Lights + Random LEDs
arduino
Just a random LED sequence and Light voice controlled to know the module
1//A code to test with Grove Speech Recognizer 2//it turns on and off lights (LEDs) on pin 7 and the (Mode 1/2) commands the 3//other LEDs 4 5#include <SoftwareSerial.h> 6 7#define SOFTSERIAL_RX_PIN 2 8#define SOFTSERIAL_TX_PIN 3 9 10#define RED 8 11#define YEL 9 12#define GRE 10 13#define LIGHT 7 14 15short m=0; 16 17SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN); 18 19const char *voiceBuffer[] = //Vocie commands you can keep this list to 20{ //know your commands or remove it 21 "Turn on the light", 22 "Turn off the light", 23 "Play music", 24 "Pause", 25 "Next", 26 "Previous", 27 "Up", 28 "Down", 29 "Turn on the TV", 30 "Turn off the TV", 31 "Increase temperature", 32 "Decrease temperature", 33 "What's the time", 34 "Open the door", 35 "Close the door", 36 "Left", 37 "Right", 38 "Stop", 39 "Start", 40 "Mode 1", 41 "Mode 2", 42 "Go", 43}; 44 45void setup() 46{ 47 Serial.begin(9600); 48 softSerial.begin(9600); 49 softSerial.listen(); 50 pinMode(RED,OUTPUT); 51 pinMode(YEL,OUTPUT); 52 pinMode(GRE,OUTPUT); 53 pinMode(LIGHT,OUTPUT); 54} 55 56void loop() 57{ 58 int cmd; 59 if(softSerial.available()) //If something is received 60 { 61 cmd = softSerial.read(); //The number of the command is stored 62 Serial.println(voiceBuffer[cmd - 1]); //Shows the command name 63 } 64 if(cmd==1) //To turn on the lights by its command 65 digitalWrite(LIGHT,HIGH); //Turn on the lights which have "1" as number 66 67 if(cmd==2) //Turn them Off 68 digitalWrite(LIGHT,LOW); 69 70 if(cmd==20) //Mode 1 will execut once 71 Mode1(); 72 73 if(cmd==18){ //Turn off mode 2 by "Stop" 74 m=0; 75 digitalWrite(RED,LOW); 76 digitalWrite(YEL,LOW); 77 digitalWrite(GRE,LOW); 78 } 79 if(cmd==21) 80 m=1; 81 82 if(m==1) //Turn on mode2 and keep it as long m=1 83 Mode2(); 84 85} 86 87 88void Mode1(){ //Random LED sequence 89 digitalWrite(RED,HIGH); 90 digitalWrite(YEL,HIGH); 91 digitalWrite(GRE,HIGH); 92 delay(1000); 93 digitalWrite(RED,LOW); 94 delay(1000); 95 digitalWrite(YEL,LOW); 96 delay(1000); 97 digitalWrite(GRE,LOW); 98 delay(1000); 99 digitalWrite(RED,HIGH); 100 delay(1000); 101 digitalWrite(YEL,HIGH); 102 delay(1000); 103 digitalWrite(GRE,HIGH); 104 delay(2000); 105 digitalWrite(RED,LOW); 106 digitalWrite(YEL,LOW); 107 digitalWrite(GRE,LOW); 108} 109 110void Mode2(){ 111 digitalWrite(RED,HIGH); 112 digitalWrite(YEL,HIGH); 113 digitalWrite(GRE,HIGH); 114 delay(1000); 115 digitalWrite(RED,LOW); 116 digitalWrite(YEL,LOW); 117 digitalWrite(GRE,LOW); 118 delay(700); 119 digitalWrite(RED,HIGH); 120 digitalWrite(YEL,LOW); 121 digitalWrite(GRE,HIGH); 122 delay(500); 123 digitalWrite(RED,HIGH); 124 digitalWrite(YEL,LOW); 125 digitalWrite(GRE,LOW); 126 delay(300); 127}
Lights + Random LEDs
arduino
Just a random LED sequence and Light voice controlled to know the module
1//A code to test with Grove Speech Recognizer 2//it turns on and off lights (LEDs) on pin 7 and the (Mode 1/2) commands the 3//other LEDs 4 5#include <SoftwareSerial.h> 6 7#define SOFTSERIAL_RX_PIN 2 8#define SOFTSERIAL_TX_PIN 3 9 10#define RED 8 11#define YEL 9 12#define GRE 10 13#define LIGHT 7 14 15short m=0; 16 17SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN); 18 19const char *voiceBuffer[] = //Vocie commands you can keep this list to 20{ //know your commands or remove it 21 "Turn on the light", 22 "Turn off the light", 23 "Play music", 24 "Pause", 25 "Next", 26 "Previous", 27 "Up", 28 "Down", 29 "Turn on the TV", 30 "Turn off the TV", 31 "Increase temperature", 32 "Decrease temperature", 33 "What's the time", 34 "Open the door", 35 "Close the door", 36 "Left", 37 "Right", 38 "Stop", 39 "Start", 40 "Mode 1", 41 "Mode 2", 42 "Go", 43}; 44 45void setup() 46{ 47 Serial.begin(9600); 48 softSerial.begin(9600); 49 softSerial.listen(); 50 pinMode(RED,OUTPUT); 51 pinMode(YEL,OUTPUT); 52 pinMode(GRE,OUTPUT); 53 pinMode(LIGHT,OUTPUT); 54} 55 56void loop() 57{ 58 int cmd; 59 if(softSerial.available()) //If something is received 60 { 61 cmd = softSerial.read(); //The number of the command is stored 62 Serial.println(voiceBuffer[cmd - 1]); //Shows the command name 63 } 64 if(cmd==1) //To turn on the lights by its command 65 digitalWrite(LIGHT,HIGH); //Turn on the lights which have "1" as number 66 67 if(cmd==2) //Turn them Off 68 digitalWrite(LIGHT,LOW); 69 70 if(cmd==20) //Mode 1 will execut once 71 Mode1(); 72 73 if(cmd==18){ //Turn off mode 2 by "Stop" 74 m=0; 75 digitalWrite(RED,LOW); 76 digitalWrite(YEL,LOW); 77 digitalWrite(GRE,LOW); 78 } 79 if(cmd==21) 80 m=1; 81 82 if(m==1) //Turn on mode2 and keep it as long m=1 83 Mode2(); 84 85} 86 87 88void Mode1(){ //Random LED sequence 89 digitalWrite(RED,HIGH); 90 digitalWrite(YEL,HIGH); 91 digitalWrite(GRE,HIGH); 92 delay(1000); 93 digitalWrite(RED,LOW); 94 delay(1000); 95 digitalWrite(YEL,LOW); 96 delay(1000); 97 digitalWrite(GRE,LOW); 98 delay(1000); 99 digitalWrite(RED,HIGH); 100 delay(1000); 101 digitalWrite(YEL,HIGH); 102 delay(1000); 103 digitalWrite(GRE,HIGH); 104 delay(2000); 105 digitalWrite(RED,LOW); 106 digitalWrite(YEL,LOW); 107 digitalWrite(GRE,LOW); 108} 109 110void Mode2(){ 111 digitalWrite(RED,HIGH); 112 digitalWrite(YEL,HIGH); 113 digitalWrite(GRE,HIGH); 114 delay(1000); 115 digitalWrite(RED,LOW); 116 digitalWrite(YEL,LOW); 117 digitalWrite(GRE,LOW); 118 delay(700); 119 digitalWrite(RED,HIGH); 120 digitalWrite(YEL,LOW); 121 digitalWrite(GRE,HIGH); 122 delay(500); 123 digitalWrite(RED,HIGH); 124 digitalWrite(YEL,LOW); 125 digitalWrite(GRE,LOW); 126 delay(300); 127}
2WD Robot code
arduino
You can use this code to control a robot to advance, turn or stop, here the forward stops automatically after 2s you can remove it and stop it by "Stop" command
1//This code is to use with Grove Speech recognizer and 2WD robot with 2//l298n DC motor driver 3 4#include <SoftwareSerial.h> 5 6#define SOFTSERIAL_RX_PIN 2 7#define SOFTSERIAL_TX_PIN 3 8 9SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN); 10 11int in1 = 8; //L298n pins and here I didn't add the speed control 12int in2 = 9; 13int in3 = 10; 14int in4 = 11; 15 16void setup() { 17 18 pinMode(in1, OUTPUT); 19 pinMode(in2, OUTPUT); 20 pinMode(in3, OUTPUT); 21 pinMode(in4, OUTPUT); 22 23 softSerial.begin(9600); 24 softSerial.listen(); 25} 26 27void loop() { 28 int cmd; 29 if(softSerial.available()) 30 { 31 cmd = softSerial.read(); 32 33 } 34 35 if(cmd==19){ //I removed the command list here I used "Start" 36 Forward(); //Left Right and Stop and cmd==their number 37 delay(2000); //I added a delay to stop it you can remove it and use a 38 Stop(); //voice command to stop it 39 } 40 41 if(cmd==17){ 42 Right(); 43 delay(500); 44 Stop(); 45 } 46 47 if(cmd==16){ 48 Left(); 49 delay(500); 50 Stop(); 51 } 52 53 if(cmd==18) 54 Stop(); 55 56} 57 58//Classic L298n Driver functions 59void Forward(){ 60 digitalWrite(in1, LOW); 61 digitalWrite(in2, HIGH); 62 digitalWrite(in3, HIGH); 63 digitalWrite(in4, LOW); 64} 65 66 67void Left(){ 68 digitalWrite(in1, LOW); 69 digitalWrite(in2, HIGH); 70 digitalWrite(in3, LOW); 71 digitalWrite(in4, LOW); 72} 73 74void Right(){ 75 digitalWrite(in1, LOW); 76 digitalWrite(in2, LOW); 77 digitalWrite(in3, HIGH); 78 digitalWrite(in4, LOW); 79} 80 81void Stop(){ 82 digitalWrite(in1, LOW); 83 digitalWrite(in2, LOW); 84 digitalWrite(in3, LOW); 85 digitalWrite(in4, LOW); 86}
Basic code
arduino
Simple code to test your module and it shows the command on the Serial Monitor
1//Code from http://wiki.seeedstudio.com/Grove-Speech_Recognizer/ 2 3#include <SoftwareSerial.h> 4 5#define SOFTSERIAL_RX_PIN 2 6#define SOFTSERIAL_TX_PIN 3 7 8SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN); 9 10const char *voiceBuffer[] = 11{ 12 "Turn on the light", 13 "Turn off the light", 14 "Play music", 15 "Pause", 16 "Next", 17 "Previous", 18 "Up", 19 "Down", 20 "Turn on the TV", 21 "Turn off the TV", 22 "Increase temperature", 23 "Decrease temperature", 24 "What's the time", 25 "Open the door", 26 "Close the door", 27 "Left", 28 "Right", 29 "Stop", 30 "Start", 31 "Mode 1", 32 "Mode 2", 33 "Go", 34}; 35 36void setup() 37{ 38 Serial.begin(9600); 39 softSerial.begin(9600); 40 softSerial.listen(); 41} 42 43void loop() 44{ 45 char cmd; 46 47 if(softSerial.available()) 48 { 49 cmd = softSerial.read(); 50 Serial.println(voiceBuffer[cmd - 1]); 51 } 52}
2WD Robot code
arduino
You can use this code to control a robot to advance, turn or stop, here the forward stops automatically after 2s you can remove it and stop it by "Stop" command
1//This code is to use with Grove Speech recognizer and 2WD robot with 2//l298n 3 DC motor driver 4 5#include <SoftwareSerial.h> 6 7#define SOFTSERIAL_RX_PIN 8 2 9#define SOFTSERIAL_TX_PIN 3 10 11SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN); 12 13int 14 in1 = 8; //L298n pins and here I didn't add the speed control 15int in2 = 9; 16int 17 in3 = 10; 18int in4 = 11; 19 20void setup() { 21 22 pinMode(in1, OUTPUT); 23 24 pinMode(in2, OUTPUT); 25 pinMode(in3, OUTPUT); 26 pinMode(in4, OUTPUT); 27 28 29 softSerial.begin(9600); 30 softSerial.listen(); 31} 32 33void loop() { 34 int 35 cmd; 36 if(softSerial.available()) 37 { 38 cmd = softSerial.read(); 39 40 41 } 42 43 if(cmd==19){ //I removed the command list here I used 44 "Start" 45 Forward(); //Left Right and Stop and cmd==their number 46 delay(2000); 47 //I added a delay to stop it you can remove it and use a 48 Stop(); //voice 49 command to stop it 50 } 51 52 if(cmd==17){ 53 Right(); 54 delay(500); 55 56 Stop(); 57 } 58 59 if(cmd==16){ 60 Left(); 61 delay(500); 62 63 Stop(); 64 } 65 66 if(cmd==18) 67 Stop(); 68 69} 70 71//Classic 72 L298n Driver functions 73void Forward(){ 74 digitalWrite(in1, LOW); 75 digitalWrite(in2, 76 HIGH); 77 digitalWrite(in3, HIGH); 78 digitalWrite(in4, LOW); 79} 80 81 82void 83 Left(){ 84 digitalWrite(in1, LOW); 85 digitalWrite(in2, HIGH); 86 digitalWrite(in3, 87 LOW); 88 digitalWrite(in4, LOW); 89} 90 91void Right(){ 92 digitalWrite(in1, 93 LOW); 94 digitalWrite(in2, LOW); 95 digitalWrite(in3, HIGH); 96 digitalWrite(in4, 97 LOW); 98} 99 100void Stop(){ 101 digitalWrite(in1, LOW); 102 digitalWrite(in2, 103 LOW); 104 digitalWrite(in3, LOW); 105 digitalWrite(in4, LOW); 106}
Downloadable files
Basic Wiring
Here's how you can test your module with the basic code, the speaker is optional
Basic Wiring
Basic Wiring
Here's how you can test your module with the basic code, the speaker is optional
Basic Wiring
With LEDs
Here's my 1st examples just lighting LEDs with voice commands I considered the 2 Leds on 7 as my lights and the other ones just lights on and off with a random code
With LEDs
2WD Robot
To control a 2WD robot
2WD Robot
2WD Robot
To control a 2WD robot
2WD Robot
With LEDs
Here's my 1st examples just lighting LEDs with voice commands I considered the 2 Leds on 7 as my lights and the other ones just lights on and off with a random code
With LEDs
Comments
Only logged in users can leave comments
SurtrTech
0 Followers
•0 Projects
Table of contents
Intro
10
0