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

Controlling Arduino by Voice (Say open to light the LED) © CC BY-SA

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

  • 4,414 views
  • 0 comments
  • 12 respects

Components and supplies

About this project

My project is a simple project to get start using Arduino with 1Sheeld.

I want to make it easy for anyone who want to start learning Arduino.

In this project we will control the Arduino by voice to turn a LED (ON) by saying "Open" and turn it (OFF) by saying "Close".

Step 1 : The Tools

1- Arduino Uno

2- Usb Cable

3- Male Jumpers

4- 220 ohm Resistor

5- Bread Board

6- 1Sheeld

7- LED 5MM

Step 2 : Make the Circuit

Make the circuit like on these pictures.

Note:-

       We use pin 13.

Step 3 : Write and Load the Code

You can find the code Here.

A copy of the code.

/* 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 
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;
 }
}

How it Works?

1- After making the circuit and loading the code you should connect your phone with 1Sheeld by Bluetooth.

2- Then choose voice recognizer.

3- Tap speak then say "Open" and it will light (ON).

4- Tap speak again and say "Close" and it will turn (OFF). 

Finally : Try it and Enjoy!

A sample video to know how it works 

Enjoy!

Created By:

Ahmed Khaled , Ahmed Hammad , Mohammed Ali .

Code

voice_control.inoC/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;
  }
}

Schematics

The Circuit
2

Comments

Similar projects you might like

Controlling LED light intensity using smartphone light senso

Project tutorial by Nikola Travis

  • 2,660 views
  • 0 comments
  • 1 respect

Control your light system with your voice

Project tutorial by Maha Raafat

  • 39,714 views
  • 22 comments
  • 159 respects

Control your Light System Using Smart Phone

Project tutorial by Ahmed Yassin

  • 43,497 views
  • 5 comments
  • 63 respects

4x4x4 LED cube with Arduino Uno and 1sheeld

Project tutorial by Hassan Ibrahim

  • 34,276 views
  • 7 comments
  • 64 respects

Control LED Using Your Voice Command

by Team IoTBoys

  • 27,053 views
  • 4 comments
  • 30 respects

LED as a Light Sensor

Project tutorial by WolfxPac

  • 9,655 views
  • 9 comments
  • 23 respects
Add projectSign up / Login