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
- int led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin = 13;
- String readString;
- void setup()
- {
- Serial.begin(9600);
- pinMode(led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin, OUTPUT);
- }
-
- void loop()
- {
- while (Serial.available())
- {
- delay(4);
- char c = Serial.read();
- readString += c;
- }
- if (readString.length() > 0)
- {
- Serial.println(readString);
- if (readString == "ON")
- {
- digitalWrite(led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin, HIGH);
- }
- if (readString == "OFF")
- {
- digitalWrite(led - turn - on - off - in -bluetooth - using - android - apps - in -arduinompin, LOW);
- }
- readString = "";
- }
- }
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: