Introduction

  • In this article, I will explain the voice-based light ON/OFF with the Android app In Arduino Mega 2560.
  • It can be fully controlled by voice.
  • It can be controlled by the app.
Parts Of Lists
  • Arduino Mega2560
  • Bluetooth
  • LEDs- 05
  • Hook-Up Wires
  • Bread Board
Connection
Step 1: Connection from Bluetooth To Arduino Mega 2560
Bluetooth Board
Vcc 5v
Gnd Gnd
Tx Rx
Rx Tx
Step 2: Connection for the LEDs
Leds Postive side Negative side
Led1 12 Gnd
Led2 13 Gnd
Led3 14 Gnd
Led4 15 Gnd
Led5 16 Gnd
Programming
  1. //Coded By: Angelo Casimiro (4/27/14)
  2. //Voice Activated Arduino (Bluetooth + Android)
  3. //Feel free to modify it but remember to give credit
  4. String voice;
  5. int
  6. led1 = 12, //Connect LED 1 To Pin #2
  7. led2 = 13, //Connect LED 2 To Pin #3
  8. led3 = 14, //Connect LED 3 To Pin #4
  9. led4 = 15, //Connect LED 4 To Pin #5
  10. led5 = 16; //Connect LED 5 To Pin #6
  11. //--------------------------Call A Function-------------------------------//
  12. void allon()
  13. {
  14. digitalWrite(led1, HIGH);
  15. digitalWrite(led2, HIGH);
  16. digitalWrite(led3, HIGH);
  17. digitalWrite(led4, HIGH);
  18. digitalWrite(led5, HIGH);
  19. }
  20. void alloff()
  21. {
  22. digitalWrite(led1, LOW);
  23. digitalWrite(led2, LOW);
  24. digitalWrite(led3, LOW);
  25. digitalWrite(led4, LOW);
  26. digitalWrite(led5, LOW);
  27. }
  28. void setup()
  29. {
  30. Serial.begin(9600);
  31. pinMode(led1, OUTPUT);
  32. pinMode(led2, OUTPUT);
  33. pinMode(led3, OUTPUT);
  34. pinMode(led4, OUTPUT);
  35. pinMode(led5, OUTPUT);
  36. }
  37. void loop()
  38. {
  39. while (Serial.available()) { //Check if there is an available byte to read
  40. delay(10); //Delay added to make thing stable
  41. char c = Serial.read(); //Conduct a serial read
  42. if (c == '#')
  43. {
  44. break;
  45. } //Exit the loop when the # is detected after the word
  46. voice += c; //Shorthand for voice = voice + c
  47. }
  48. if (voice.length() > 0)
  49. {
  50. Serial.println(voice);
  51. //----------Control Multiple Pins/ LEDs----------//
  52. if (voice == "*all on")
  53. {
  54. allon();
  55. } //Turn Off All Pins (Call Function)
  56. else if (voice == "*all off")
  57. {
  58. alloff();
  59. } //Turn On All Pins (Call Function)
  60. //----------Turn On One-By-One----------//
  61. else if (voice == "*TV on")
  62. {
  63. digitalWrite(led1, HIGH);
  64. } else if (voice == "*fan on")
  65. {
  66. digitalWrite(led2, HIGH);
  67. } else if (voice == "*computer on")
  68. {
  69. digitalWrite(led3, HIGH);
  70. } else if (voice == "*bedroom lights on")
  71. {
  72. digitalWrite(led4, HIGH);
  73. } else if (voice == "*bathroom lights on")
  74. {
  75. digitalWrite(led5, HIGH);
  76. }
  77. //----------Turn Off One-By-One----------//
  78. else if (voice == "*TV off")
  79. {
  80. digitalWrite(led1, LOW);
  81. } else if (voice == "*fan off")
  82. {
  83. digitalWrite(led2, LOW);
  84. } else if (voice == "*computer off")
  85. {
  86. digitalWrite(led3, LOW);
  87. } else if (voice == "*bedroom lights off")
  88. {
  89. digitalWrite(led4, LOW);
  90. } else if (voice == "*bathroom lights off")
  91. {
  92. digitalWrite(led5, LOW);
  93. }
  94. voice = "";
  95. }
  96. } //Reset the variable after initiating
Explanation
  • We can control the LEDs by the voice, through the Android app
  • If we want to turn ON the light, we set the voice as the "Light ON"
  • If we want to turn OFF the light, we set the voice as the "Light OFF"
  • We can also set the voice for "All on" and "All Off".
  • They can work on a one-by-one process.
  • We want to download the app from the play store.
Output