Speech Recognition Robot

by crafttech in Circuits > Robots

1892 Views, 20 Favorites, 0 Comments

Speech Recognition Robot

IMG_1600k.JPG
IMG_1598k.JPG
IMG_1593k.JPG
IMG_1595k.JPG

Simple Arduino Uno based speech recognizer robot with a few speech control options, using Grove Speech Recognizer module. By the help of the predifind voice commands of the module, the following functions are avaibale: drive forward ("Start"), drive backward ("Previous"), turn left and right ("Left", "Right"), turn on and off the light, led light effect ("Increase temperature" and "Decrease temperature"), handling the gripper ("Mode 1" - open gripper, "Mode 2" - close gripper), a series of beeps ("Play music"), and a free run function in obsctacle avoidance mode ("Go", "Stop").

Supplies

IMG_20220202_122123_1k.jpg

The used parts:

  • Arduino Uno Rev3
  • Grove - Base Shield V2
  • L298P motor shield
  • Grove LED bar V2
  • Grove - Speech Recognizer
  • HC-SR04 ultrasonic sensor
  • servo motor
  • 3D printed gripper set (source: https://www.instructables.com/How-to-Make-3D-Small-Gripper-With-RC-Servo-9G-SG90/)
  • 3D printed sensor holder
  • Feetech FT-DC-002-KIT - Aluminium 2WD Robot Chassis + 1 extra plate
  • steel fixing elements, cables etc.
  • speaker (recycled)
  • 6V power supply - 4 AA batteries (recycled)

Assembly

circuit.jpg

Assembly: building the chassis and installing the parts of the circuits.

The use of the digital pins of the Arduino Uno:

  • 2, 3 - Speech recognizer module (connected to D2 on the base shield)
  • 4 - Buzzer (fixed on the motor shield)
  • 5, 6 - Led bar (connected to D5 slot on the Base Shield)
  • 7 - trigger pin for the ultrasonic sensor (fix connection on the motor shield)
  • 8 - echo pin for the ultrasonic sensor (fix connection on the motor shield)
  • 9 - servo (fix servo connection on the motor shield)
  • 10, 11, 12, 13 - motor driver (Motor A & B - defined by the motor shield)


More information about:

  • Grove Speech Recognizer module: http://wiki.seeedstudio.com/Grove-Speech_Recognizer
  • Grove LED Bar: https://wiki.seeedstudio.com/Grove-LED_Bar/
  • Grove Base Shield: https://wiki.seeedstudio.com/Base_Shield_V2/
  • the motor shield: https://www.instructables.com/Tutorial-for-L298-2Amp-Motor-Driver-Shield-for-Ard/

Upload Code

/*Speech controlled robot - VI 2022*/

#include <SoftwareSerial.h>
#include <Motor.h>
#include <Servo.h>
#include <Grove_LED_Bar.h>

#define SOFTSERIAL_RX_PIN  2 //speech recognizer
#define SOFTSERIAL_TX_PIN  3 //speech recognizer

SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN); //speech recognizerhez
Grove_LED_Bar bar(6, 5, 0);            // Clock pin, Data pin, Orientation

const int TriggerPin = 7;              //Trig pin
const int EchoPin = 8;                 //Echo pin
const int BUZZER = 4;
long Duration = 0;
long t = 0;
int p = 0;

const char *voiceBuffer[] =
{
    "Turn on the light",
    "Turn off the light",
    "Play music",
    "Pause",
    "Next",
    "Previous",
    "Up",
    "Down",
    "Turn on the TV",
    "Turn off the TV",
    "Increase temperature",
    "Decrease temperature",
    "What's the time",
    "Open the door",
    "Close the door",
    "Left",
    "Right",
    "Stop",
    "Start",
    "Mode 1",
    "Mode 2",
    "Go",
};

int pos=0;                                  // variable to store the servo position
bool GripperOpen=false;

Servo myservo;                             // create servo object to control a servo
Motor motorA = Motor(12, 10);
Motor motorB = Motor(13, 11);

void Forward(int speedF){
  motorA.go(speedF);
  motorB.go(speedF);
  Serial.println("Forward");
}  

void Backward(int speedB){
  motorA.go(-speedB);
  motorB.go(-speedB);
  Serial.println("Backward");
}

int Turnleft(int speedL){
  motorA.go(speedL);
  motorB.go(0);
  Serial.println("Turn left");
}

void Turnright(int speedR){
  motorA.go(0);
  motorB.go(speedR);
  Serial.println("Turn right");
}  

void Stop(){
  motorA.go(0);
  motorB.go(0);
  Serial.println("Stop");
}  

void Ping(int t1, int t2){
  digitalWrite(BUZZER, HIGH);
  Serial.println("Sound");
  delay(t1);
  digitalWrite(BUZZER, LOW);
  delay(t2);
}

long Distance(long t){
  long DistanceCalc;                      // Calculation variable
  DistanceCalc = ((t * 0.034) / 2);       // Actual calculation in cm
  return DistanceCalc;                    // return calculated value
}

void UHsensing(){
  digitalWrite(TriggerPin, HIGH);          // Trigger pin to HIGH
  delayMicroseconds(10);                   // 10us high
  digitalWrite(TriggerPin, LOW);           // Trigger pin to HIGH
                 
  Duration = pulseIn(EchoPin,HIGH);        // Waits for the echo pin to get high - returns Duration in microseconds
  long Distance_cm = Distance(Duration);   // Use function to calculate the distance
                 
  Serial.print("Distance = ");             // Output to serial
  Serial.print(Distance_cm);
  Serial.println(" cm");
  
  if (Distance_cm>=20){
     Forward(255);
  }               
  else if (Distance_cm<20){
     Stop();
     delay(1000);
     Backward(255);
     delay(1000);
     Turnleft(255);
     delay(750);
     Stop();
  } 
}

void GripperOpening(){
  if (GripperOpen == false) {
    pos = 70;
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 10ms for the servo to reach the position
    GripperOpen = true;
    Serial.println("Open gripper");
  }  
}  

void GripperClosing(){
  if (GripperOpen == true) {
    pos=110;
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 10ms for the servo to reach the position
    GripperOpen = false;
    Serial.println("Close gripper");
  }  
}  

void Speach_visual(int p){            // Led bar bit coding: 0b00000 + digits for the 10 pins: 1=on or 0=off
  bar.setBits(0b000000000110000);
  delay(p);
  bar.setBits(0b000000001111000);
  delay(p);
  bar.setBits(0b000000011111100);
  delay(p);
  bar.setBits(0b000000111111110);
  delay(p);
  bar.setBits(0b000001111111111);
  delay(p);
  bar.setBits(0b000001111111111);    // all leds are on
  delay(p);
  bar.setBits(0b000000111111110);
  delay(p);
  bar.setBits(0b000000011111100);
  delay(p);
  bar.setBits(0b000000001111000);
  delay(p);
  bar.setBits(0b000000000110000);
  delay(p);
  bar.setBits(0b000000000000000);   // all leds are off
  delay(p);
}  

void setup()
{
  Serial.begin(9600);
  softSerial.begin(9600);
  softSerial.listen();
  pinMode(BUZZER, OUTPUT);
  pinMode(TriggerPin,OUTPUT);              // Trigger is an output pin
  pinMode(EchoPin,INPUT);                  // Echo is an input pin
     
  digitalWrite(TriggerPin, LOW);
  myservo.attach(9);                       // attaches the servo on pin 9 to the servo object
  myservo.write(90);
  bool GripperOpen=false;                  // gripper állása
  bar.begin();
}

void loop(){
    char cmd;
    if(softSerial.available()){
        cmd = softSerial.read();
        Serial.println(voiceBuffer[cmd - 1]);
        if (voiceBuffer[cmd - 1] == "Start"){
          Speach_visual(30);
          Speach_visual(30);
          Forward(255);                    //useing servo too, the motor have to run on full speed (255)
          delay(1000);
          Stop();  
        }
        else if (voiceBuffer[cmd - 1] == "Left"){
          Speach_visual(50);
          Turnleft(255);
          delay(300);
          Stop();  
        }
        else if (voiceBuffer[cmd - 1] == "Right"){
          Speach_visual(50);
          Turnright(255);
          delay(300);
          Stop();  
        }
        else if (voiceBuffer[cmd - 1] == "Stop"){
          Speach_visual(50);
          Stop();
        }
        else if (voiceBuffer[cmd - 1] == "Play music"){
          Speach_visual(50);
          Speach_visual(50);
          Ping(200,50);
          Ping(200,50);
          Ping(400,50);
          Ping(200,50);
          Ping(200,50);
          Ping(400,1000);
        }
        else if (voiceBuffer[cmd - 1] == "Previous"){
          Speach_visual(50);
          Speach_visual(30);
          Backward(255);
          delay(500);
          Stop();  
        }
        else if (voiceBuffer[cmd - 1] == "Mode 1"){
          Speach_visual(50);
          Speach_visual(30);
          GripperOpening();
        }
        else if (voiceBuffer[cmd - 1] == "Mode 2"){
          Speach_visual(50);
          Speach_visual(50);
          GripperClosing();
        }
        else if (voiceBuffer[cmd - 1] == "Turn on the light"){
          bar.setBits(0b000001111111111);
        }
        else if (voiceBuffer[cmd - 1] == "Turn off the light"){
          bar.setBits(0b000000000000000);
        }
        else if (voiceBuffer[cmd - 1] == "Increase temperature"){
          for (int i = 10; i >= 1; i--){
            bar.setLed(i, 1);
            delay(50);
          }
        }
        else if (voiceBuffer[cmd - 1] == "Decrease temperature"){
          for (int i = 1; i <= 10; i++){
            bar.setLed(i, 0);
            delay(50);
          }
        }
        else if (voiceBuffer[cmd - 1] == "Go"){
           Speach_visual(30);
           while(voiceBuffer[cmd - 1] == "Go"){
            if(softSerial.available()){
                cmd = softSerial.read();
            }        
            UHsensing();
            delay(100);
           }
        }  
     }
}

Finished

IMG_1601k.JPG
IMG_20220203_003800_0k.jpg