2018年5月1日 星期二

Control LEDs with Voice Command : good morning / good night














/*
HC-05 VCC → Arduino 5V
HC-05 GND → Arduino GND
HC-05 RXD → Arduino TXD pin1
HC-05 TXD → Arduino RXD pin 0
HC-05 KEY → Not Connected 
upload 時需先拔除 RXD / TXD 接線
*/
String voice;
#define led 13

void setup() {
  // put your setup code here, to run once:
  Serial.begin(38400);
  //Serial.begin(9600);
  pinMode(led,OUTPUT);

}

void loop() {                    // put your main code here, to run repeatedly:
  while (Serial.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable
  char c = Serial.read(); //Conduct a serial read
  if (c == '#') {break;} //Exit the loop when the # is detected after the word
  voice += c; //Shorthand for voice = voice + c
  }
  if (voice.length() > 0) {
    Serial.println(voice);
//-----------------------------------------------------------------------//
  //----------Control Multiple Pins/ LEDs----------//
       if(voice == "good morning")
       {
        digitalWrite(led,HIGH);
        }
       else if(voice == "good night")
       {
        digitalWrite(led,LOW);
        }

voice=""; //Reset the variable after initiating
}
}

1 則留言:

  1. Helllloo Admin,
    Woww Amazing Blog… Same Day Tours India, #Agra is the #famous #city of #India and #famous for #Tajmahal #wonder of #World. Taj Mahal is main tourist attraction of #Agra. Agra is known as #Tajcity of India in all over world, India is the #most popular #country in the World, has a lot to give visitors we have more

    packages like...
    Same Day Agra Tour By Car
    Same Day Agra Tour By Train
    Same Day Agra Tour By Gatiman Express from Delhi
    #Discovery #Taj #India
    Emails: info@discoverytaj.com | indiadiscoverytaj@gmail.com,
    | discoverytaj@hotmail.com
    Mobile: +91-9997783182 | 9837709602
    Website: www.discoverytaj.com | http://www.agraroutes.com

    回覆刪除