Turn LED ON/ OFF In Bluetooth Using Android Apps In Arduino Mega 2560

Introduction:

In this article I will explain how to turn LED ON/ OFF in Bluetooth using Android Apps In Arduino Mega 2560. In the setup we can easily connect it through Android app. LED turns on when the ON button is pressed, and off when the Off button is pressed.
 
Parts of list
  • Arduino Mega2 560
  • Bluetooth (HC05) 
  • Breadboard
  • Hookup wires
Software required

MIT App Inventor 2
 
Connection:

Step 1: 
Connection from the Bluetooth (HC05) to the Arduino Mega 2560.

 
Figure1: Bluetooth(HC05)
  • In the Bluetooth the Vcc can be connected to the 5v supply of the Arduino Mega board.
  • In the Bluetooth the Gnd can be connected to the Gnd supply of the Arduino Mega board. 
  • In the Bluetooth the Tx can be connected to the Rx of the Arduino Mega board. 
  • In the Bluetooth the Rx can be connected to the Tx of the Arduino Mega board. 
Step2: Connection from the LED to the Arduino Mega2560. 
  • The positive pin of the LED can be connected to the digital pin 13 to the Arduino Mega board.
  • The negative pin of the led can be connected to the Gnd to the Arduino Mega board.
Software steps:
  • Open the MIT App Inventor
  • Click Start, then new project
  • Design the Bluetooth connection in the app inventor.
  • Click the tool bar and add the buttons and set the device of the Bluetooth.
  • In the program set the code and click the connect, THEN Al companion.
  • Scan the code and see the output in the board.

MIT App Window


                                    Figure 2: MIT App window
 
Programming
  1. int led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin = 13;  
  2. String readString;  
  3. void setup()  
  4. {  
  5.     Serial.begin(9600); // Baud Rate    
  6.     pinMode(led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin, OUTPUT);  
  7. }  
  8.   
  9. void loop()   
  10. {  
  11.     while (Serial.available()) //Send data only when you receive data    
  12.     {  
  13.         delay(4); //delay time    
  14.         char c = Serial.read();  
  15.         readString += c;  
  16.     }  
  17.     if (readString.length() > 0)  
  18.     {  
  19.         Serial.println(readString);  
  20.         if (readString == "ON")  
  21.         {  
  22.             digitalWrite(led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin, HIGH); // LED ON    
  23.         }  
  24.         if (readString == "OFF")  
  25.         {  
  26.             digitalWrite(led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin, LOW); //LED OFF    
  27.         }  
  28.         readString = "";  
  29.     }  
  30. }  
Explanation
  • In this article it can work through the Android and Bluetooth set up.
  • The LED turns on  clicking the ON button. 
  • The LED turns off clicking the OFF button.
  • In another case we can see the LED on/off in the serial monitor also.  
Output

                                                                         Figure 3: Output  
 
Read articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all