Menu Close

Arduino- Send and Receive data with Android App.

This tutorial explains how to control Arduino from a smart phone using a bluetooth module HC-05. 

1. Introduction:

In this tutorial we explains, how to send and receive data from Arduino to the Android app without using Serial monitor.

For this, we have taken a simple example of LED. We will send command to get LED on and off. And will also receive the status of LED from Arduino.

1.1 Default Setting of BT Module:

The default setting of HC_05 are:

Name- HC-05

Password- 1234

Baud Rate- 9600

All the modules have the same baud rate by default. Make sure to set Baud Rate to 9600 in your code. If you want to change the baud rate in your code, then you also need to change the baud rate of device by using AT Commands.

For this you can check Robo India’s tutorial: Configure Bluetooth Module HC-05 with AT Mode.

2. Hardware required

S.No.ItemQuantity
1.Arduino 1
2.Breadboard 1
3.BT Module HC-05 1
4.LED 1
5.Resistor 1K 1
6.Male to Female Jumper Wires 4
7Male to Male Jumper Wires 2

 3. Building Circuit

4. Programming:

Once the circuit part is done, Arduino is needed to be programmed.

You may download this code (Arduino Sketch) from here.

//Robo India tutorial on Controlling Arduino with Android
//https://www.roboindia.com/tutorials/

String BT_input;                          // to store input character received via BT.
int LED = 2;                              // device to control

void setup()  
{  
  Serial.begin(9600);                      //default baud rate of module
  pinMode(LED, OUTPUT);
  while (!Serial) 
  {
     // wait for serial port to connect. Needed for native USB port only
  }
}

void loop() 

 { 
  if (Serial.available())
    {   
        BT_input = Serial.readString();   // read input string from bluetooth 
        
        if (BT_input=="A")                
        {
          digitalWrite(LED, HIGH);
          Serial.println(BT_input);
          Serial.println("LED is ON");
        }
        else if (BT_input=="B")
        {
          digitalWrite(LED, LOW);
          Serial.println(BT_input);
          Serial.println("LED is OFF");
        }
        else 
        {
          Serial.println(BT_input);        
          Serial.println("Send 'A' to get LED ON");
          Serial.println("Send 'B' to get LED OFF");
        }
    }
 
}



Before uploading the code, remove the RX and TX wires from Arduino’s TX and RX pins. After uploading the code, connect them again and plug out the USB cable and supply external power using adaptor.

5. Mobile app

You may download the Android control App on Playstore from here.

Connecting the Android device to the HC-05 creates a serial communication channel very similar to the serial monitor in the Arduino IDE. This means we need a Bluetooth version of the serial monitor.

1. Download this Application.

2. Pair your phone with HC-05. for doing this go to Settings->Bluetooth->Scan device->select HC-05 and pair it. Pass code to pair is ‘1234’.

3. Now, open the app and connect the HC-05 module.

After Connection, the blinking LED on the HC-05 will change to a single short blink every 2 seconds.

6. Output:

If you send ‘A’ it will make to LED ON and if you send ‘B’ it will make the LED OFF. The Arduino code also sends the current state of LED also.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply