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 !

Connections Of Bluetooth module HC05 :-

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

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

Make the connections as shown in the above image. Don’t connect the RX & TX pins WHILE/BEFORE uploading the code !

Copy the code given below.

Download the app called BT Voice Control/AMR Voice(It’s free). Here is the link

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.

When you are connecting to the Bluetooth module for the first time, it will ask you the password. Enter 0000 OR 1234.

When the device gets successfully paired with the sensor, the LED lights on sensor will start blinking at a slower rate than usual.

DONE. Copy the code given below & test it out !

Code for controlling a common anode RGB LED

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

Stringvoice;

#define GREEN 10

#define BLUE 11

#define RED 9

voidsetup()

{// 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);

}

intredVal;

intgreenVal;

intblueVal;

voidloop(){

while(Serial.available())//Check if there is an available byte to read

{

delay(10);//Delay added to make thing stable

charc=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);

}

elseif(voice=="*green")// FOR GREEN COLOUR OF THE LED !

{

analogWrite(GREEN,0);

analogWrite(RED,255);

analogWrite(BLUE,255);

}

elseif(voice=="*blue")// FOR BLUE COLOUR OF THE LED !

{

analogWrite(RED,255);

analogWrite(BLUE,0);

analogWrite(GREEN,255);

}

elseif(voice=="*white")// FOR WHITE COLOUR OF THE LED !

{

analogWrite(RED,0);

analogWrite(GREEN,0);

analogWrite(BLUE,0);

}

elseif(voice=="*good night")// FOR TURNING OFF LED !

{

analogWrite(RED,255);

analogWrite(GREEN,255);

analogWrite(BLUE,255);

}

elseif(voice=="*chameleon")// FOR FADING/CHANGING COLOURS !

{

redVal=255;// choose a value between 1 and 255 to change the color.

blueVal=0;

greenVal=0;

for(inti=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(inti=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(inti=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 :-

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

Code :-

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

Stringvoice;

#define led 9

voidsetup(){

// put your setup code here, to run once:

Serial.begin(9600);

pinMode(led,OUTPUT);

}

voidloop(){// 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

charc=Serial.read();//Conduct a serial read

if(c=='#'){break;}//Exit the loop when the # is detected after the word