Alessandro Didonna
Published © GPL3+

Arduino can hear and understand your voice with 1Sheeld !

Use Arduino with 1Sheeld+ and your smartphone as a Voice Recognizer.. push a button, speak and you'll see what you said on the LCD screen

BeginnerFull instructions provided30 minutes8,403
Arduino can hear and understand your voice with 1Sheeld !

Things used in this project

Hardware components

1Sheeld
1Sheeld
×1
Arduino UNO
Arduino UNO
×1
1Sheeld
1Sheeld
×1
DFRobot 16x2 LCD Keypad Shield For Arduino
×1
Android device
Android device
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

1Sheeld fritzing

Code

VRSheeld

Arduino
Use the Voice Recognition shield of 1Sheeld to recognize words and print them on the LCD...
// LCD Shield declarations //////////////////////////////

#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

//////////////////////////////////////////////////////////

// 1Sheeld Declarations///////////////////////////////////

#define CUSTOM_SETTINGS
#define INCLUDE_VOICE_RECOGNIZER_SHIELD

//A Boolean flag to know if recognition have been started already
bool started = false;

/* Include 1Sheeld library. */
#include <OneSheeld.h>

//////////////////////////////////////////////////////////

void setup(){
   lcd.begin(16, 2);               // start the library
   lcd.setCursor(0,0);             // set the LCD cursor   position 
   lcd.print("Push select");  // print a simple message on the LCD
   /* Start Communication. */
   OneSheeld.begin();
   /* Error Commands handiling. */
   VoiceRecognition.setOnError(error);
   //This is a trigger for the newCommand void , 
   //It's called each time a new command is recognized by the phone
   VoiceRecognition.setOnNewCommand(newCommand);   
}
 
void loop(){            
   lcd_key = read_LCD_buttons();   // read the buttons

   switch (lcd_key){               // depending on which button was pushed, we perform an action

       case btnRIGHT:{             //  push button "RIGHT" to scroll the text
            lcd.scrollDisplayLeft();
            delay(300);
            break;
       }
       case btnLEFT:{
             lcd.scrollDisplayRight();//  push button "LEFT" to scroll the text
             delay(300);
             break;
       }    
       case btnUP:{
             break;
       }
       case btnDOWN:{
             break;
       }
       case btnSELECT:{
             if (!started){
             lcd.clear();
             lcd.setCursor(0,0);
             lcd.print("Listening...");  //  push button "SELECT" to trig recognition
             VoiceRecognition.start();
             started = true;}
             break;
       }
       case btnNONE:{
             //  No action on the KeyPad
             started = false;
             break;
       }
   }
   
}

void error(byte errorData)
{
  /* Switch on error and print it on the LCD. */
  switch(errorData)
  {
    case NETWORK_TIMEOUT_ERROR: lcd.setCursor(0,1);lcd.print("Network timeout");break;
    case NETWORK_ERROR: lcd.setCursor(0,1);lcd.print("Network Error");break;
    case AUDIO_ERROR: lcd.setCursor(0,1);lcd.print("Audio error");break;
    case SERVER_ERROR: lcd.setCursor(0,1);lcd.print("No Server");break;
    case SPEECH_TIMEOUT_ERROR: lcd.setCursor(0,1);lcd.print("Speech timeout");break;
    case NO_MATCH_ERROR: lcd.setCursor(0,1);lcd.print("No match");break;
    case RECOGNIZER_BUSY_ERROR: lcd.setCursor(0,1);lcd.print("Busy");break;
  }
}

int read_LCD_buttons(){// read the buttons
    
    // read the value from the keypad since only one analog pin is used
    adc_key_in = analogRead(0);       
     

    if (adc_key_in > 1000) return btnNONE; 

    //For V1.1 of the LCD/Keypad Shield enable this threshold
    /*
    if (adc_key_in < 50)   return btnRIGHT;  
    if (adc_key_in < 250)  return btnUP; 
    if (adc_key_in < 450)  return btnDOWN; 
    if (adc_key_in < 650)  return btnLEFT; 
    if (adc_key_in < 850)  return btnSELECT;  
    */
   // For V1.0 comment the other threshold and use the one below:
   
     if (adc_key_in < 50)   return btnRIGHT;  
     if (adc_key_in < 195)  return btnUP; 
     if (adc_key_in < 380)  return btnDOWN; 
     if (adc_key_in < 555)  return btnLEFT; 
     if (adc_key_in < 790)  return btnSELECT;   
   

    return btnNONE;  // when all others fail, return this.
}

void newCommand(String command){
    //Clear the text on the LCD Screen
    lcd.clear();
    lcd.setCursor(0,0);// set the LCD cursor   position 
    lcd.print("You said");
    lcd.setCursor(0,1);
    //print last command received
    lcd.print(VoiceRecognition.getLastCommand());
}

Credits

Alessandro Didonna

Alessandro Didonna

1 project • 2 followers
Mechanical Engineering Student , Robotics lover , Geek...

Comments