Problem in using Voice recognition module v3 to run four DC motors with two TB6612FNG motor driver and Arduino uno

#include "VoiceRecognitionV3.h"
#include <SoftwareSerial.h>

// Define RX and TX pins for connecting to Voice Recognition Module
VR myVR(12,13); // RX, TX
uint8_t records[7]; // save record
uint8_t buf[64];
// Define motor control pins and other configurations
int standBy = 11;

// Motor A
int PWMA = 10; // PWM Speed Control
int AIN1 = 2; // Direction pin 1
int AIN2 = 3; // Direction pin 2

// Motor B
int PWMB = 6; // PWM Speed Control for Motor B
int BIN1 = 4; // Direction pin 1
int BIN2 = 5; // Direction pin 2

int CIN1 = 6;
int CIN2 = 7;

int DIN1 = 8;
int DIN2 = 9;

// Feedback LED
//int feedbackLED = A0; // Assuming an LED is connected to pin A0
//***********************************************************

#define forwardRecord (0)
#define reverseRecord (1)
#define turnleftRecord (2)
#define turnrightRecord (3)
#define stopRecord (4)

//******************************************************
void printSignature(uint8_t *buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf[i]>0x19 && buf[i]<0x7F){
Serial.write(buf[i]);
}
else{
Serial.print("[");
Serial.print(buf[i], HEX);
Serial.print("]");
}
}
}

//************************************************************
void printVR(uint8_t *buf)
{
Serial.println("VR Index\tGroup\tRecordNum\tSignature");

Serial.print(buf[2], DEC);
Serial.print("\t\t");

if(buf[0] == 0xFF){
Serial.print("NONE");
}
else if(buf[0]&0x80){
Serial.print("UG ");
Serial.print(buf[0]&(~0x80), DEC);
}
else{
Serial.print("SG ");
Serial.print(buf[0], DEC);
}
Serial.print("\t");

Serial.print(buf[1], DEC);
Serial.print("\t\t");
if(buf[3]>0){
printSignature(buf+4, buf[3]);
}
else{
Serial.print("NONE");
}
Serial.println("\r\n");
}

//*************************************************************

void setup() {
myVR.begin(9600);
Serial.begin(115200);
Serial.println("System Ready");
Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
pinMode(standBy, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
//pinMode(feedbackLED, OUTPUT);

//Serial.begin(115200);
//voiceModule.begin(9600); // Initialize voice module at appropriate baud rate
if(myVR.clear() == 0){
Serial.println("Recognizer cleared.");
}else{
Serial.println("Not find VoiceRecognitionModule.");
Serial.println("Please check connection and restart Arduino.");
while(1);
if(myVR.load((uint8_t)forwardRecord) >= 0){
Serial.println("forwardRecord loaded");
}

if(myVR.load((uint8_t)reverseRecord) >= 0){
Serial.println("offRecord loaded");
}

if(myVR.load((uint8_t)turnleftRecord) >= 0){
Serial.println("turnleftRecord loaded");
}

if(myVR.load((uint8_t)turnrightRecord) >= 0){
Serial.println("turnrightRecord loaded");
}

if(myVR.load((uint8_t)stopRecord) >= 0){
Serial.println("stopRecord loaded");
}
}
}
void loop()
{
int ret;
ret = myVR.recognize(buf, 50);
if(ret>0){
while(1)
{
int i=0;
Serial.println(buf[i]);
i++;

}
switch(buf[1]){
case forwardRecord:
/** turn on LED /
forward(125); // Move forward
break;
case reverseRecord:
/
* turn off LED*/
reverse(125); // Move forward
break;
case turnleftRecord:
/** turn off LED*/
turnleft(100); // Move forward
break;
case turnrightRecord:
/** turn off LED*/
turnright(100); // Move forward
break;
case stopRecord:
/** turn off LED*/
stop(); // Move forward
break;
default:
Serial.println("Record function undefined");
break;
}
/** voice recognized */
printVR(buf);
}

}

// Define motor control functions
void turnleft(int spd)
{
runMotor(0, spd, 0);
runMotor(1, spd, 1);
}

void turnright(int spd)
{
runMotor(0, spd, 1);
runMotor(1, spd, 0);
}

void forward(int spd)
{
runMotor(0, spd, 1);
runMotor(1, spd, 1);
}

void reverse(int spd)
{
runMotor(0, spd, 0);
runMotor(1, spd, 0);
}

void runMotor(int motor, int spd, int dir)
{
digitalWrite(standBy, HIGH); // Turn on Motor

boolean dirPin1 = LOW;
boolean dirPin2 = HIGH;

if(dir == 1) {
dirPin1 = HIGH;
dirPin2 = LOW;
}

if(motor == 1) {
digitalWrite(AIN1, dirPin1);
digitalWrite(AIN2, dirPin2);
digitalWrite(BIN1, dirPin1);
digitalWrite(BIN2, dirPin2);
analogWrite(PWMA, spd);

}
else{

digitalWrite(DIN1, dirPin1);
digitalWrite(DIN2, dirPin2);
digitalWrite(CIN1, dirPin1);
digitalWrite(CIN2, dirPin2);
analogWrite(PWMA, spd);

}
}

void stop() {
digitalWrite(standBy, LOW);
}

I tried uploading the code, code is uploading but module is not recognizing the voice. I have trained the module. May I know what would be the reason.

Hello

before we even try to understand what you did, do yourself a favour and please read How to get the best out of this forum and post accordingly (including code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).


PS/ this sounds like a very bad idea

while (1)
{
  int i = 0;
  Serial.println(buf[i]);
  i++;
}
1 Like

Just I wanted to see what’s happening. So I tried that at last stage.

Could you fix the first post and add the code tags please...

1 Like

Okay!

While you are uploading the code using code tags also upload an annotated schematic showing how this is wired. Be sure to show all connections, devices, power sources, ground connections and note any leads over 10"/25cm.

Waiting…

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.