Control LEDs with Voice Command
Control LEDs with Voice Command
This is a very basic project for controlling LED (Red) using voice control. To accomplish this we have used the Bluetooth HC-05 module and android apps are available on the play store. LEDs will be On/Off on your voice command.
Procedure:-
- Make the connections as shown in the connection image. Don’t connect the RX & TX pins WHILE/BEFORE uploading the code!
- Copy the code given below.
- Download any app called BT Voice Control.
- Open the app (It will automatically turn on the device’s Bluetooth). Go to options. Click on “Connect”. Choose the device – HC 05.
- When you are connecting to the Bluetooth module for the first time, it will ask you for the password. Enter 0000 OR 1234.
- When the device gets successfully paired with the sensor, the LED lights on the sensor will start blinking at a slower rate than usual.
- DONE. Copy the code given below & test it out!
Source Code:-
String voice;
#define RED 8
void setup() {
Serial.begin(9600);
pinMode(RED,OUTPUT);
}
void RedOn(){
digitalWrite (RED, HIGH);
}
void RedOff(){
digitalWrite (RED, LOW);
}
void loop() {
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 =="red" || voice =="red on"){
RedOn();
}
else if(voice =="red off"){
RedOff();
}
voice=""; //Reset the variable after initiating
}
}
Connections:-
Bluetooth:- Arduino UNO:-
RxD ==> TxD
TxD ==> RxD
Vcc ==> 3.3V
Gnd ==> Gnd
Comments
Post a Comment