Controlling Multiple LED Using Voice Recognition Module V3

Hi! Can anyone please help me identify the problem on my code. I am trying to do basic control with 3 LED using my voice recognition module V3 and Arduino UNO. I successfully trained and loaded my voice commands on the module. However, when I test it out, only the green LED is turning on and the 2 other LED is not. I am sure that my LEDs are working. Here's my code:

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

/**        
  Connection
  Arduino    VoiceRecognitionModule
   2   ------->     TX
   3   ------->     RX
*/
VR myVR(2,3);    // 2:RX 3:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

int green = 5;
int yellow = 6;
int red = 7;

#define go        (5)
#define wait      (6) 
#define stopp     (7) 

/**
  @brief   Print signature, if the character is invisible, 
           print hexible value instead.
  @param   buf     --> command length
           len     --> number of parameters
*/
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("]");
    }
  }
}

/**
  @brief   Print signature, if the character is invisible, 
           print hexible value instead.
  @param   buf  -->  VR module return value when voice is recognized.
             buf[0]  -->  Group mode(FF: None Group, 0x8n: User, 0x0n:System
             buf[1]  -->  number of record which is recognized. 
             buf[2]  -->  Recognizer index(position) value of the recognized record.
             buf[3]  -->  Signature length
             buf[4]~buf[n] --> Signature
*/
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()
{
  /** initialize */
  myVR.begin(9600);
  
  Serial.begin(115200);
  Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
  
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);
    
  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)go) >= 0){
    Serial.println("go loaded");
  }
  
  if(myVR.load((uint8_t)wait) >= 0){
    Serial.println("wait loaded");
  }

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

void loop()
{
  int ret;
  ret = myVR.recognize(buf, 50);
  if(ret>0){
    switch(buf[1]){
      case go:
        digitalWrite(green, HIGH);
        delay(2000);
        digitalWrite(green, LOW);
        break;
      
      case wait:
        digitalWrite(yellow, HIGH);
        delay(2000);
        digitalWrite(yellow, LOW);
        break;
      
      case stopp:
        digitalWrite(red, HIGH);
        delay(2000);
        digitalWrite(red, LOW);
        break;
      
      default:
        Serial.println("Record function undefined");
        break;
    }
    /** voice recognized */
    printVR(buf);
  }
}

Please use code tags it's the "</>" button.
What value are you seeing in buf[1] when each word is spoken?

where can I see that value?

Use the Serial Monitor. Make sure the baud rate matches what is in your code. 115200


here it is

Before the switch statement, add a serial.println(buf[1]);

This will tell you what command number it’s recognizing. If it outputs the same value for the different words then there is a problem. If it outputs the correct value then check your wiring. The led might be backwards.

Write a sketch to turn on Pin 6 and Pin 7 to make sure your other LEDs are working and wired correctly.

hello! could i ask what do you mean by "Write a sketch..."? thank you!

An Arduino program is called a 'sketch' so it means "Write an Arduino program."

we already tried to test the LEDs if they are working through multimeter and they are working

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