Ahmed Hammad MoustafaMohamed aliAhmed Khalid
Published © CC BY-SA

Controlling Arduino by Voice (Say open to light the LED)

This project is to control Arduino by voice to light a LED.

BeginnerFull instructions provided1 hour4,769
Controlling Arduino by Voice (Say open to light the LED)

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
LED (generic)
LED (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
1Sheeld
1Sheeld
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×2

Story

Read more

Schematics

The Circuit

Code

voice_control.ino

C/C++
/* Project: Voice controlled led
 * Description: You can turn an LED on or off when you say "open" or "close"
 * Created by: Ahmed Khaled, Ahmed Hammad, Mohammed Ali
 * Modified on March 7 2016
 */
#include <OneSheeld.h>

const char on[] = "open";
const char off[] = "close"; // Make preset commands
int led = 13; // Variable for the led pin

void setup()
{
  OneSheeld.begin(); // Initialize 1Sheeld library
  VoiceRecognition.setOnError(error); // Handles any errors
  VoiceRecognition.start();  // Start voice recognition
  pinMode(led, OUTPUT);  // Set pin 7 as an output pin
  digitalWrite(led, HIGH);  // Active Low
}

void loop () 
{
  if(VoiceRecognition.isNewCommandReceived()) // Check if a new command is recieved
  {
    if (!strcmp(off,VoiceRecognition.getLastCommand())) // Compare the recieved command with the first preset command
    {
      digitalWrite(led, LOW);  // Turn the LED off
    }
    else if(!strcmp(on,VoiceRecognition.getLastCommand()))  // Compare the recieved command with the second one
    {
      digitalWrite(led, HIGH);  // Turn the LED on
    }

  }
}

void error(byte errorData) // Error messages in case anything goes wrong
{
  switch(errorData)
  {
  case NETWORK_TIMEOUT_ERROR: 
    Terminal.println("Network timeout");
    break;
  case NETWORK_ERROR: 
    Terminal.println("Network Error");
    break;
  case AUDIO_ERROR: 
    Terminal.println("Audio error");
    break;
  case SERVER_ERROR: 
    Terminal.println("No Server");
    break;
  case SPEECH_TIMEOUT_ERROR: 
    Terminal.println("Speech timeout");
    break;
  case NO_MATCH_ERROR: 
    Terminal.println("No match");
    break;
  case RECOGNIZER_BUSY_ERROR: 
    Terminal.println("Busy");
    break;
  }
}

Credits

Ahmed Hammad Moustafa

Ahmed Hammad Moustafa

1 project • 4 followers
Student in Freshman year in Faculty of Engineering Assiut University . The Blue Hybrid
Mohamed ali

Mohamed ali

1 project • 3 followers
Ahmed Khalid

Ahmed Khalid

1 project • 4 followers
A freshman in faculty of Engineering and a tech enthusiast :)

Comments