Introduction: SOS Daemon With Voice Recognition!

The concept is to create a Security Alarm program. When there is a danger, user will shout  “heeelp!” and Arduino will start an alarm, signaling in Morse code via the led. When danger is gone, user can say “Abort” and Arduino will stop signaling for danger.


Step 1:

Required Hardware:

1x Arduino Board (Uno/Duemillianove)
1x USB Cable
1x PC/Mac

Required Software:

1x Arduino IDE
1x C# IDE

Step 2:

We want to build a program that will read bits from a serial port and will enable the alarm. The led will blink in a certain order, that of Morse code for "SOS".

“SOS”  (Save Our Ships) was used to search for help and its signal was send via the below Morse code:

                                                   . . . _ _ _ . . .                                      .   short signal
                                                                                                             _   long signal



We are going to represent  “SOS” in Morse code via led lighting, in duration of 250ms and 500ms for short and long signals.

More information regarding “SOS” code:
http://en.wikipedia.org/wiki/SOS

Step 3:

We open Arduino IDE and create the following code to be uploaded to Arduino.

const int ledPin =  13;      // the number of the LED pin
char val;
int cont = 0;
void sos () {
  for(int i=0; i<3; i++)
  {
    digitalWrite(ledPin,HIGH);
    delay(250);
    digitalWrite(ledPin,LOW);
    delay(250);
  }
  for(int i=0; i<3; i++)
  {
    digitalWrite(ledPin,HIGH);
    delay(500);
    digitalWrite(ledPin,LOW);
    delay(250);
  }
  for(int i=0; i<3; i++)
  {
    digitalWrite(ledPin,HIGH);
    delay(250);
    digitalWrite(ledPin,LOW);
    delay(250);
  }
}
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
//initialize serial connection via USB
Serial.begin(9600);
}
void loop()
{
  if (Serial.available())
  {
    val=Serial.read();
    if (val == '1')
    {
      sos();
      cont = 1;
    }
    if(val == '0')
    {
      digitalWrite(ledPin,LOW);
      cont = 0;
    }
    
    Serial.flush();
  }
  else
  {
    if (cont == 1)
    {
      sos();
      cont = 1;
    }
    if(cont == 0)
    {
      digitalWrite(ledPin,LOW);
      cont = 0;
    }
  }
}

Step 4:

As we open a Visual C# IDE, i.e. Visual Studio 2010, we create an new project in Visual C#, using windows form.

Using the properties panel and the toolbox we make the form as we like it, and we just put a button that will enable monitoring and some labels guiding the user to control the program.

To make the communication PC-Arduino possible we must drag&drop from the toolbox, a serialPort object and set the correct port from its properties.

Also we must add the reference of speech recognition to our project:
Project > Add Reference. Add there "System.Speech".

Ending with the UI designing, it's time to get things working!
Double click the button we made and put the following code in the event:

private void button1_Click(object sender, EventArgs e)
        {
            rec = new SpeechRecognitionEngine();
            rec.SetInputToDefaultAudioDevice();
            // Specify the exact words that the engine will try to recognize.
            Choices choices = new Choices("help", "abort");
            // Create and load a Grammar using the Choices above.
            GrammarBuilder grBuilder = new GrammarBuilder(choices);
            Grammar grammar = new Grammar(grBuilder);
            rec.LoadGrammar(grammar);
          
            // Create the event handler
          
            if (button1.Text == "Disable" )
            {
                button1.Text = "Enable";
                label5.Text = "Unsecured";
            }
            else
            {
                rec.SpeechRecognized += newEventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
                rec.RecognizeAsync(RecognizeMode.Multiple);
                button1.Text = "Disable";
                label5.Text = "Secured";
            }


void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {       
            foreach (RecognizedWordUnit word in e.Result.Words)
            {
                switch (word.Text)
                {
                    case "help":
                        if (button1.Text == "Disable")
                        {
                            label6.Text = "help";
                            USB.Write("1");
                        }
                        break;
                    case "abort":
                        if (button1.Text == "Disable")
                        {
                            label6.Text = "abort";
                            USB.Write("0");
                        }
                        break;
                    default:
                        USB.Write("1");
                        break;
                }
            }
        }


Step 5:

The whole project can be found here.