Skip to content
MechStuff

MechStuff

''Making stuff… Simpler''

  • Home
  • MechStuff
  • News
  • How Stuff Works
  • Engines
  • Mech-Tech
  • TechStuff
  • Robotics
    • Robot Stuff
    • Tutorials
  • Engineering Marvels
  • For Mechanical Engineers
    • Games for Mechanical Engineers
    • Movies for Mechanical Engineers
    • Projects for Mechanical engineers
  • Contact Us
  • About us

Control LEDs with Voice Command | Arduino-Bluetooth module tutorial

6

At first, I had a notion that it must be such a difficult job – controlling things just by giving voice commands ! Uhh… it seemed that only the experts & nerds could do it ! But believe me, this turned out to be one of the easiest things I’ve come across related to Arduino. So without wasting our time lets know how to control LEDs with voice commands with this Arduino-Bluetooth module tutorial !

Requirements :-

  1. Arduino board
  2. Breadboard
  3. Jumpers/single stranded wires
  4. RGB led
  5. Bluetooth module HC-05
  6. Android
  7. A can of beer to celebrate after you do it ! ?

Video tutorial down below !

Connections Of Bluetooth module HC05 :-

  • VCC – to VCC of Arduino.
  • GND – to GND of Arduino.
  • RX – to digital pin 0(TX pin) of Arduino.
  • TX – to digital pin 1(RX pin) of Arduino. (connect RX & TX pin after uploading the code)

Of LED –

Note that you connect the terminals to PWM pins only !

  • Longest terminal (2) – VCC
  • Terminal 1  – Pin 9
  • Terminal 3 – Pin 10
  • Terminal 4 – Pin 11
Arduino-bluetooth module tutorial
Connections of Arduino with BT module HC05 & RGB LED.

NOTE :-

2 types of RGB led are available in the market – common anode & common cathode. Here I’m using common anode . If you are using common cathode, connect the longest terminal to GND pin of Arduino; rest all the connections are same.

Procedure :-

  1. Make the connections as shown in the above image. Don’t connect the RX & TX pins WHILE/BEFORE  uploading the code !
  2. Copy the code given below.
  3. Download the app called BT Voice Control/AMR Voice(It’s free). Here is the link
  4. Open the app AMR Voice app (It will automatically turn on the device’s Bluetooth). Go to options. Click on “Connect to Robot”. Choose the device – HC 05.
  5. When you are connecting to the Bluetooth module for the first time, it will ask you the password. Enter 0000 OR 1234.
  6.  When the device gets successfully paired with the sensor, the LED lights on sensor will start blinking at a slower rate than usual.
  7. DONE. Copy the code given below & test it out !
String voice;

#define GREEN 10
#define BLUE 11
#define RED 9

void setup() 
{                                            // put your setup code here, to run once:
  Serial.begin(9600);
   pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(RED, OUTPUT);
   analogWrite(RED,255); 
   analogWrite(GREEN,255);                    // Since LED must be off in the beginning
   analogWrite(BLUE,255);
}

  int redVal;
  int greenVal;
  int blueVal;


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")//                                FOR RED COLOUR OF THE LED 
     {
     analogWrite(RED,0); 
     analogWrite(GREEN,255);
     analogWrite(BLUE,255);
     }  
  else if(voice == "*green")//                              FOR GREEN COLOUR OF THE LED !
     {
    analogWrite(GREEN,0);
    analogWrite(RED,255);
    analogWrite(BLUE,255);
     }
  else if(voice == "*blue")//                                FOR BLUE COLOUR OF THE LED !
     {
    analogWrite(RED,255);
    analogWrite(BLUE,0);
    analogWrite(GREEN,255);
     }
  
  else if(voice == "*white")//                               FOR WHITE COLOUR OF THE LED !
     {
    analogWrite(RED,0);
    analogWrite(GREEN,0);
    analogWrite(BLUE,0);
     }
   else if(voice == "*good night")//                          FOR TURNING OFF LED !
     {
    analogWrite(RED,255);
    analogWrite(GREEN,255);
    analogWrite(BLUE,255);
     }
    
    else if(voice == "*chameleon") //                           FOR FADING/CHANGING COLOURS !
     {
     redVal = 255; // choose a value between 1 and 255 to change the color. 
     blueVal = 0;
     greenVal = 0;
     for(int i = 0; i < 255; i += 1) // fades out of red and into full (i = 255) green
    {
    greenVal += 1;
    redVal -= 1;
    analogWrite(GREEN, 255 - greenVal);
    analogWrite(RED, 255 - redVal);
    delay(10);
  }
 
  redVal = 0;
  blueVal = 0;
  greenVal = 255;
  for(int i = 0; i < 255; i += 1)
  {
    blueVal += 1;
    greenVal -= 1;
    analogWrite(BLUE, 255 - blueVal);
    analogWrite(GREEN, 255 - greenVal);
    delay(10);
  }
 
  redVal = 0;
  blueVal = 255;
  greenVal = 0;
  for(int i = 0; i < 255; i += 1)
  {
    redVal += 1;
    blueVal -= 1;
    analogWrite(RED, 255 - redVal);
    analogWrite(BLUE, 255 - blueVal);
    delay(10);
  }
   }
voice="";                                                       //Reset the variable after initiating
}
}

Here is a video tutorial for you. This will surely make your job easy !

Connections & Code for controlling normal LED with Voice commands :-

Connections :- Control led or any other stuff with android

Just replace RGB led with normal LED & connect the positive terminal to any PWM pin(here 9)

Code :-

String voice;
#define led 9

void setup() {
  // put your setup code here, to run once:
  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);}
  else if(voice == "*fade")


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

Done.

Comment down the problems faced by you. I’ll be very glad to help you 🙂

Share this Stuff :

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • More
  • Click to email a link to a friend (Opens in new window)
  • Click to print (Opens in new window)

Related

Robotics, Tutorials android, Arduino, beginner, blutooth, code, commands, common anode, common cathode, connections, diy, hc-05, mini-project, pdf, philips hue, program, recognition, RGB, video tutorial, voice

6 comments on “Control LEDs with Voice Command | Arduino-Bluetooth module tutorial”

  1. Zunair Ahmed says:
    July 7, 2020 at 12:36 AM

    hi, when i call ”good morning” led is glowing but when i call ”good night” it’s not working. What should i do?

    Reply
    1. Jay Baviskar says:
      August 10, 2020 at 4:56 PM

      Check the code Ahmed. Definitely a misplaced.

      Reply
  2. Naman says:
    July 17, 2020 at 7:59 PM

    Bhai c jo hai vo declare ho rha kya kiya jaaaye
    Or aapne codes ko alag alag kyu dala hai

    Reply
    1. Jay Baviskar says:
      August 10, 2020 at 4:55 PM

      Hello! The first code is for RGB led – multi-coloured LED, shown in the tutorial. If you are following the tutorial on a simple LED, the 2nd code is for you.

      Reply
  3. Bibhas Makhal says:
    July 31, 2020 at 7:49 AM

    Very good

    Reply
  4. harshan says:
    August 18, 2020 at 4:39 PM

    very nice

    Reply

Leave a Reply to Bibhas Makhal Cancel reply

Your email address will not be published. Required fields are marked *

Idealist by NewMediaThemes