Introduction: SOS Daemon With Voice Recognition!

Picture of 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:

Picture of

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.

Comments

Kiteman (author)2012-02-19

So... this flashes an SOS when it hears the word "help", but I don't see "microphone" on your hardware list.

Is there a microphone built into the Arduino board already, or is it the computer's microphone you're using?

(PS, I think you need to check the timings of your SOS, it doesn't look very clear to me.)

Brainstorms (author)Kiteman2012-02-19

Right, it uses the computer microphone and through the program we have made, using Microsoft Speech Recognition, we send "1" or "0" to the serial port.

The timings are up to you, we chose 250ms and 500ms just to make a discrete signal for short and long Morse code.

Kiteman (author)Brainstorms2012-02-19

Are you going to try for a portable, self-contained model?

You could add a speaker to sound three sharp whistle-blasts as well, the standard hill-walking distress signal.

(And I meant that the sequences are running together, obscuring the code.)

Brainstorms (author)Kiteman2012-02-19

This is a little hard to be done, because we use speech recognition library and we are sending data via the serial port. If you are suggesting that we could use a "built-in microphone" on the Arduino, i don't know if it is possible to execute the C# code from an SD-card (Arduino Shield).
The main idea of the project was to have the Arduino communicate with the pc, using Speech Recognition. :)

About This Instructable

1,872views

2favorites

License:

More by Brainstorms:SOS Daemon with Voice Recognition!
Add instructable to: