Gravity: Offline Language Learning Voice Recognition Sensor Not Working When Trying to Control 2 Motors

Hello again,

I am using the Gravity: Offline Language Learning Voice Recognition Sensor to try and control 2 motors on the nano 33 IoT, I have assured that the circuit works correctly when just running the motors as well as just to turn on/off an LED with the Gravity: Offline Language Learning Voice Recognition Sensor. However, when using them together they are not working for some reason. Below is the code, photo of the circuit, and link to Gravity: Offline Language Learning Voice Recognition Sensor documentation. Thank you all for your help!
SKU_SEN0539-EN_Gravity_Voice_Recognition_Module_I2C_UART-DFRobot .

/*!
 * @file  i2c.ino
 * @brief Control the voice recognition module via I2C
 * @n  Get the recognized command ID and play the corresponding reply audio according to the ID;
 * @n  Get and set the wake-up state duration
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence  The MIT License (MIT)
 * @author  [qsjhyy](yihuan.huang@dfrobot.com)
 * @version  V1.0
 * @date  2022-04-02
 * @url  https://github.com/DFRobot/DFRobot_DF2301Q
 */

 // MUST USE EXTERNAL POWER SOURCE FOR DC MOTOR
// EVERYTHING IN CIRCUIT MUST SHARE A COMMON GROUND (USE GROUND RAIL AND ENSURE ALIGNED WITH POWER SUPPLY)
/* PIN1 ON L293D STARTS TO LEFT OF NOTCH(SIDE CIRCLE INDENTION IS ON) PINS LOOP AROUND TO WHERE 
PIN DIRECTLY ACROSS FROM PIN 1 IS PIN 16 */
//PINS ON LEFT OF L293D CONTROL 1 MOTOR PINS ON RIGHT CONTROL OTHER
// FOR EN1(L293D PIN 1) AND EN2(L293D PIN 9) PINS ON L293D MUST USE PWM PIN (~) (ANALOG)
// L293D PINS 4,5,12,13 ARE GND PINS AND MUST BE CONNECTED TO RAIL IF USED ON EITHER SIDE
#include "DFRobot_DF2301Q.h"



int desiredTime;  
int motor1speedpin=2; // L293D PIN 1 (EN1: CONTROLS MOTOR SPEED) MUST BE PWM PIN(~)(ANALOG); ARDUINO PIN 5(~);
int M1directionpin1=4;// L293D pin 2 (IN1) on motor controller ; ARDUINO PIN 4 (DIGITAL PIN); 
int M1directionpin2=7; // L293D pin 7 (IN2) on motor controller ; ARDUINO PIN 2 (DIGITAL PIN)
int motor1speed=250;//MAX 255 MIN 0 (MAY NOT RUN AT ZERO) (LOWEST SELF STARTING RUNNING SPEED =~ 90)
int motor2speedpin=16; //L293D PIN 9 (EN2: CONTROLS MOTOR SPEED) MUST BE PWM PIN(~)(ANALOG); ARDUINO PIN 11(~);
int M2directionpin1=14; // L293D pin 10 (IN3) on motor controller ; ARDUINO PIN 7 (DIGITAL PIN);
int M2directionpin2=15; // L293D pin 15 (IN4) on motor controller ; ARDUINO PIN 8 (DIGITAL PIN)
int motor2speed=250; //MAX 255 MIN 0 (MAY NOT RUN AT ZERO) (LOWEST SELF STARTING RUNNING SPEED =~ 90)
int startTime;
// RED WIRE ON MOTOR 1 TO L293D PIN 3 (OUT 1)
// BLACK WIRE ON MOTOR 1 TO L293D PIN 6 (OUT 2)
// RED WIRE ON MOTOR 2 TO L293D PIN 11 (OUT 3)
// BLACK WIRE ON MOTOR 2 TO L293D PIN 14 (OUT 4)
// GND FROM MOTOR CONTROLLER TO GND RAIL; L293D PIN 4 for motor 1 & PIN 12 for motor 2
// L293D PIN 8 CONNECTED TO EXTERNAIL POWER SUPPLY RAIL (+); FOR MOTOR 2 WE DO SAME WITH PIN 16
//I2C communication
DFRobot_DF2301Q_I2C asr;

void stopMotors() {
  digitalWrite(M1directionpin1, LOW);
  digitalWrite(M1directionpin2, LOW);
  digitalWrite(M2directionpin1, LOW);
  digitalWrite(M2directionpin2, LOW);
  analogWrite(motor1speedpin, 0);
  analogWrite(motor2speedpin, 0);
}

void setup() {
  Serial.begin(9600);

  pinMode(motor1speedpin, OUTPUT);
  pinMode(M1directionpin1, OUTPUT);
  pinMode(M1directionpin2, OUTPUT);
  pinMode(motor2speedpin, OUTPUT);
  pinMode(M2directionpin1, OUTPUT);
  pinMode(M2directionpin2, OUTPUT);
 


  // Init the sensor
  while (!(asr.begin())) {
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");

  /**
   * @brief Set voice volume
   * @param voc - Volume value(1~7)
   */
  asr.setVolume(4);

  /**
     @brief Set mute mode
     @param mode - Mute mode; set value 1: mute, 0: unmute
  */
  asr.setMuteMode(0);

  /**
     @brief Set wake-up duration
     @param wakeTime - Wake-up duration (0-255)
  */
  asr.setWakeTime(20);

  /**
     @brief Get wake-up duration
     @return The currently-set wake-up period
  */
  uint8_t wakeTime = 0;
  wakeTime = asr.getWakeTime();
  Serial.print("wakeTime = ");
  Serial.println(wakeTime);

  // asr.playByCMDID(1);   // Wake-up command

  /**
     @brief Play the corresponding reply audio according to the ID
     @param CMDID - command word ID
  */
  //asr.playByCMDID(23);  // Command word ID
}

void loop() {
  /**
     @brief Get the ID corresponding to the command word 
     @return Return the obtained command word ID, returning 0 means no valid ID is obtained
  */
  uint8_t CMDID = asr.getCMDID();
  

  if (CMDID == 5) //Go Forward (Command 1)
  {
    startTime = millis();
    desiredTime = 3000;
    digitalWrite(M1directionpin1,HIGH);
    digitalWrite(M1directionpin2,LOW);   // FOR RIGHT WHEEL BACKWARDS M1D1 = HIGH, M1D2 = LOW
    digitalWrite(M2directionpin1,LOW);
    digitalWrite(M2directionpin2,HIGH);   // FOR LEFT WHEEL BACKWARDS M2D1 = LOW, M2D2 = HIGH
    analogWrite(motor1speedpin,motor1speed); //**THIS ACTUALLY GOES FORWARD**
    analogWrite(motor2speedpin,motor2speed);
  }

  if (millis() - startTime == desiredTime) {
    stopMotors();
    millis() == 0;
    }
}

Precisely define "not working", please. Detail is everything; we can't see what you see. What exactly is it not doing?

Most of the motor problems described on this forum end up being due to an inadequate motor power supply, like trying to use the Arduino 5V output for motor power. Ignore any tutorial that suggests doing so is OK.

Improper wiring is also a common mistake, but the photo you posted gives no useful details. Post a wiring diagram (hand drawn is fine).

Not working as in when I give the command nothing happens, motors don’t turn on/rotate.

I am using external power supply for the motors

Did the motors ever run?

If not, start over, using simple code to turn the motors on and off, forward and reverse, control the speed, etc. When that is working, add the voice recognition.

Does the DF2301Q recognize the command? Does the ASR LED light up? Details!

Yes I tested the motors before using an IR remote and worked fine, only change to the circuit was removing the IR decoder, same with testing the voice recognition module with an LED

When you get around to posting the wiring diagram, people will be happy to help.

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