loading

This is a step-by-step tutorial for making an android apk using bluetooth.

Before start coding,

  • Download Android Studio IDE and update Java.
  • Java and C programming skills will help.
  • This tutorial will not explain Java Programming.
  • If you want to code using Eclipse IDE, it is almost the same.
  • The apk will send commands to turn on/turn off a LED and controls the brightness.
  • You can download everything in the last step.

Step 1: Android Studio: New Project

  • Open Android Studio and create a new Project: File > New Project.
  • A pop up Windows will appear. Change the Application Name and Company Name.
  • Click next to choose the target of the application. The default is Android 4.0 (IceCream Sandwich)
  • Click next and choose a Blank Activity.
  • Click next and rename the Activity Name to “DeviceList”.
  • Now click “finish” and the Project will be create.

Step 2: Android: Layout Part 1.

When the build is finished, a “Hello world!” screen will be open. To create the layout of the apk, we need to add:

  • TextView to display some hint to the user;

Click twice the TextView to change the text. A box will appear:
Text = The text to be displayed.
Id = the id of this widget

  • Button to show the paired devices.

Click twice the Button to change the text. A box will appear:
Text = The text to be displayed.
Id = the id of this widget.

  • ListView to show the paired devices;

Now the main activity is finished, you can see that all widget used are shown on Components Tree.

Step 3: Android: .Class Code Part 1.

On the left side there’s a folder called “app “, open it and you’ll see other folder called “java”.
Java folder contains the package of the apk (com.led.led), and all the source code.

  • Open DeviceList class;

Import the followings packages:

import android.widget.Button;
import android.widget.ListView;

Create widgets variables to “call” the widgets used to create the layout:

Button btnPaired;
ListView devicelist;

Initialize the variables.

btnPaired = (Button)findViewById(R.id.button);
devicelist = (ListView)findViewById(R.id.listView);

Import the following packages:

import java.util.Set;
import java.util.ArrayList;
import android.widget.Toast;
import android.widget.ArrayAdapter;
import android.widget.AdapterView
import android.widget.AdapterView.OnClickListener
import android.widget.TextView;
import android.content.Intent;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

Create variables to control bluetooth:

private BluetoothAdapter myBluetooth = null;
private Set pairedDevices;

Writing a stable code avoids weird erros, so it’s good to check if the device has bluetooth adapter and whether it’s activated.

myBluetooth = BluetoothAdapter.getDefaultAdapter();
if(myBluetooth == null)
{
//Show a mensag. that thedevice has no bluetooth adapter
Toast.makeText(getApplicationContext(), "Bluetooth Device Not Available", Toast.LENGTH_LONG).show();
//finish apk
finish();
} else
{
if (myBluetooth.isEnabled())
{ }
else
{ //Ask to the user turn the bluetooth on Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(turnBTon,1);
}
}

According to Android documents, an Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use-cases:

  • To start an activity:

An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data.

  • To start a service:

A Service is a component that performs operations in the background without a user interface. You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService(). The Intent describes the service to start and carries any necessary data.

  • To deliver a broadcast:

A broadcast is a message that any app can receive. The system delivers various broadcasts for system events, such as when the system boots up or the device starts charging. You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

We need to “listen” when the button is clicked to show paired devices. So OnClickListener Api will handle it

       
btnPaired.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
pairedDevicesList(); //method that will be called
}
});

The PairedDevicesList method:

private void pairedDevicesList()
{ pairedDevices = myBluetooth.getBondedDevices(); ArrayList list = new ArrayList();

if (pairedDevices.size()>0) { for(BluetoothDevice bt : pairedDevices) { list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the address } } else { Toast.makeText(getApplicationContext(), "No Paired Bluetooth Devices Found.", Toast.LENGTH_LONG).show(); }

final ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, list); devicelist.setAdapter(adapter); devicelist.setOnItemClickListener(myListClickListener); //Method called when the device from the list is clicked

}

Step 4: Android: Class Code Part 1.

There is other method called myListClickListener. It allow the ListView to be clicked.

private AdapterView.OnItemClickListener myListClickListener = new AdapterView.OnItemClickListener()
{
    public void onItemClick (AdapterView av, View v, int arg2, long arg3)
    {
        // Get the device MAC address, the last 17 chars in the View
        String info = ((TextView) v).getText().toString();
        String address = info.substring(info.length() - 17);
        // Make an intent to start next activity.
        Intent i = new Intent(DeviceList.this, ledControl.class);
        //Change the activity.
        i.putExtra(EXTRA_ADDRESS, address); //this will be received at ledControl (class) Activity
        startActivity(i);
    }
};

Step 5: Android: Layout Part 2.

Go to app > java > com.led.led, Right click, New Activity > Blank Activity

Name it to ledControl and finish. A “Hello world!” screen will be seen.

This second layout will have three buttons, one TextView and a seekbar:

  • Turn On = Turns the LED On;
  • Turn Off = Turns the LED Off;
  • Disconnect = Closes Bluetooth Connection;
  • Indicator;
  • Brightness = control the brightness.

Step 6: Android: .Class Code Part 2.

Open ledControl class and import the following packages:

import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.AsyncTask;
import java.io.IOException;
import java.util.UUID;

Create the following widget variables:

Button btnOn, btnOff, btnDis;
SeekBar brightness;
String address = null;
private ProgressDialog progress;
BluetoothAdapter myBluetooth = null;
BluetoothSocket btSocket = null;
private boolean isBtConnected = false;
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

We have to initialize the variables and retrieve the bluetooth device address got in DeviceList class.

//receive the address of the bluetooth device
Intent newint = getIntent();
address = newint.getStringExtra(DeviceList.EXTRA_ADDRESS); //view of the ledControl layout
setContentView(R.layout.activity_led_control);
//call the widgtes
btnOn = (Button)findViewById(R.id.button2);
btnOff = (Button)findViewById(R.id.button3);
btnDis = (Button)findViewById(R.id.button4);
brightness = (SeekBar)findViewById(R.id.seekBar);

Let’s create a class to start the connection:

private class ConnectBT extends AsyncTask<Void, Void, Void> // UI thread
{ private boolean ConnectSuccess = true; //if it's here, it's almost connected

@Override protected void onPreExecute() { progress = ProgressDialog.show(ledControl.this, "Connecting...", "Please wait!!!"); //show a progress dialog }

@Override protected Void doInBackground(Void... devices) //while the progress dialog is shown, the connection is done in background { try { if (btSocket == null || !isBtConnected) { myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); btSocket.connect();//start connection } } catch (IOException e) { ConnectSuccess = false;//if the try failed, you can check the exception here } return null; } @Override protected void onPostExecute(Void result) //after the doInBackground, it checks if everything went fine { super.onPostExecute(result);

if (!ConnectSuccess) { msg("Connection Failed. Is it a SPP Bluetooth? Try again."); finish(); } else { msg("Connected."); isBtConnected = true; } progress.dismiss(); } }

We need to “listen” when the button is clicked to write a command to turn on/turn off the led, disconnect and the control of the brightness.

btnOn.setOnClickListener(new View.OnClickListener()
{ @Override public void onClick(View v) { turnOnLed(); //method to turn on } });

btnOff.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { turnOffLed(); //method to turn off } });

btnDis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Disconnect(); //close connection } });

brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser==true) { lumn.setText(String.valueOf(progress)); try { btSocket.getOutputStream().write(String.valueOf(progress).getBytes()); } catch (IOException e) {

} } }

@Override public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override public void onStopTrackingTouch(SeekBar seekBar) {

} });

There is a method called msg(); This method calls Toast.maketext(); There's the method Called Disconnect(); turnOffLed(); and turnOnLed();

private void msg(String s)
{
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}
private void Disconnect()
{ if (btSocket!=null) //If the btSocket is busy { try { btSocket.close(); //close connection } catch (IOException e) { msg("Error");} } finish(); //return to the first layout
}
private void turnOffLed()
{
    if (btSocket!=null)
    {
        try
        {
            btSocket.getOutputStream().write("TF".toString().getBytes());
        }
        catch (IOException e)
        {
            msg("Error");
        }
    }
}
private void turnOnLed()
{
    if (btSocket!=null)
    {
        try
        {
            btSocket.getOutputStream().write("TO".toString().getBytes());
        }
        catch (IOException e)
        {
            msg("Error");
        }
    }
}

Step 7: Android Manifest

Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory.

The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code.

This apk uses Bluetooth Adapter and it is not available in emulator, you must test it in a running device, but before you have to add some users-permissions, otherwise the apk will crash.

In App folder, open manifests > AndroidManifest.xml

  • Add the following code to allow user-permision to use Bluetooth Device
<uses-permission android:name = "android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name = "android.permission.BLUETOOTH"/>
  • Rebuild the project at: Build Menu > Rebuild Project

    Now you can run it in your device.

Step 8: Aruino Code

The arduino C code is very simple, no need to explain it:

char command;
String string;
boolean ledon = false;
#define led 5
char command;
String string; boolean ledon = false; #define led 5 void setup() { Serial.begin(9600); pinMode(led, OUTPUT); } void loop() { if (Serial.available() > 0) {string = "";} while(Serial.available() > 0) {command = ((byte)Serial.read()); if(command == ':') { break; } else { string += command; } delay(1); } if(string == "TO") { ledOn(); ledon = true; } if(string =="TF") { ledOff(); ledon = false; Serial.println(string); //debug } if ((string.toInt()>=0)&&(string.toInt()<=255)) { if (ledon==true) { analogWrite(led, string.toInt()); Serial.println(string); //debug delay(10); } } } void ledOn() { analogWrite(led, 255); delay(10); } void ledOff() { analogWrite(led, 0); delay(10); }

Step 9: Download


The .rar file:

  • Android Studio Project;
  • Arduino .ino;
  • Android Bluetooth Control LED .pdf;

If there's some error, please comment.

Thanks.

<p>I want output data in android app</p><p>how can i solve it?</p>
<p>The class ConnectBT is never used. How can I solve it?</p>
<p>I put new ConnectBT().execute();</p><p>in onCreate method</p>
<p>i am using hm10 Bluetooth module, app doesn't allow to connect to Bluetooth.</p><p>Showing the toast &quot;Connection Failed. Is it a SPP Bluetooth? Try again.&quot;</p><p>What should i do now? </p>
<p>yeah dude same with me, please tell to us, how fix &quot;Connection Failed. Is it a SPP Bluetooth? </p>
Tanks You
Hi chief<br>thank u so much. this very great but i dont have Arduino and i shoud use it with AVR controler. <br>con you put program with codVision or basic (bascom Avr) to help me. <br>please help me if you can.
<p>+ 2 channel relays</p>
<p>added two toggle buttons:</p><p>android ledcontrol.java:</p><p>protected void onCreate(Bundle savedInstanceState){</p><p>btnCam = (ToggleButton)findViewById(R.id.toggleButton);</p><p>btnCam2 = (ToggleButton)findViewById(R.id.toggleButton2);</p><p>btnCam.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { </p><p> public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { </p><p> if (isChecked) { </p><p> // The toggle is enabled</p><p>turnOffLed(); //method to turn off} </p><p>else { </p><p> turnOnLed(); //method to turn on </p><p> // The toggle is disabled</p><p>} </p><p> }</p><p>});</p><p>btnCam2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { </p><p> public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { </p><p> // The toggle is enabled</p><p>turnOffLed2(); //method to turn off} </p><p>else { </p><p> turnOnLed2(); //method to turn on </p><p> // The toggle is disabled</p><p>} </p><p> }</p><p>});</p><p>..........</p><p>public class ledControl extends ActionBarActivity { </p><p> Button btnOn, btnOff, btnDis; </p><p> ToggleButton btnCam, btnCam2;</p><p>..............</p><p>private void turnOffLed2(){ </p><p> if (btSocket!=null) </p><p> { </p><p> try</p><p>{ btSocket.getOutputStream().write(&quot;2F&quot;.toString().getBytes());</p><p> } </p><p> catch (IOException e)</p><p> { </p><p> msg(&quot;Error&quot;); </p><p> } </p><p> }</p><p>}</p><p>private void turnOnLed2()</p><p>{ </p><p> if (btSocket!=null) </p><p> { </p><p> try</p><p>{ btSocket.getOutputStream().write(&quot;2O&quot;.toString().getBytes());</p><p> } </p><p> catch (IOException e)</p><p> { </p><p> msg(&quot;Error&quot;);</p><p> }</p><p> }</p><p>}</p><p>Arduino:</p><p>char command;</p><p>String string;</p><p>boolean ledon = false;</p><p>boolean ledon2 = false;</p><p>#define led 7</p><p>const int ledPin = 7; // the number of the LED pin</p><p>#define led2 6</p><p>const int ledPin2 = 6; // the number of the LED pin</p><p> void setup()</p><p> {</p><p> Serial.begin(9600);</p><p> pinMode(7, OUTPUT);</p><p> pinMode(6, OUTPUT);</p><p> //Serial.println(&quot;ready&quot;);</p><p> }</p><p> void loop()</p><p> {</p><p> delay(10);</p><p> if (Serial.available() &gt; 0) </p><p> {string = &quot;&quot;;}</p><p> while(Serial.available() &gt; 0)</p><p> {</p><p> command = ((byte)Serial.read());</p><p> if(command == ':')</p><p> {</p><p> break;</p><p> }</p><p> else</p><p> {</p><p> string += command;</p><p> }</p><p> delay(1);</p><p> }</p><p> if(string == &quot;TO&quot;)</p><p> {</p><p> ledOn();</p><p> ledon = true;</p><p> }</p><p> if(string ==&quot;TF&quot;)</p><p> {</p><p> ledOff();</p><p> ledon = false;</p><p> //Serial.println(string);</p><p> }</p><p> if(string == &quot;2O&quot;)</p><p> {</p><p> ledOn2();</p><p> ledon2 = true;</p><p> }</p><p> if(string ==&quot;2F&quot;)</p><p> {</p><p> ledOff2();</p><p> ledon2 = false;</p><p> //Serial.println(string);</p><p> }</p><p>/*</p><p> if ((string.toInt()&gt;=0)&amp;&amp;(string.toInt()&lt;=255))</p><p> {</p><p> if (ledon==true)</p><p> {</p><p> analogWrite(led, string.toInt());</p><p> Serial.println(string);</p><p> delay(10);</p><p> }</p><p> }</p><p>*/</p><p> }</p><p>void ledOn()</p><p> {</p><p> digitalWrite(7, HIGH);</p><p> delay(10);</p><p> //Serial.println(&quot;on&quot;);</p><p> }</p><p> void ledOff()</p><p> {</p><p> digitalWrite(7, LOW);</p><p> delay(10);</p><p> //Serial.println(&quot;off&quot;);</p><p> }</p><p>void ledOn2()</p><p> {</p><p> digitalWrite(6, HIGH);</p><p> delay(10);</p><p> //Serial.println(&quot;on&quot;);</p><p> }</p><p> void ledOff2()</p><p> {</p><p> digitalWrite(6, LOW);</p><p> delay(10);</p><p> //Serial.println(&quot;off&quot;);</p><p> }</p>
<p>Great tutorial thanks so much for posting! However, like some others I have an issue where the Bluetooth stops responding after a while. It must be an issue with the android app as when using a terminal application it does not drop the link. Does anyone know what could be causing that? </p>
<p>i solved my 120 second timeout problem by extending the android tablets display timeout to 5 minutes, and inserting a 10ms delay right at the beginning of void loop. It just needs a little time rest each cycle of void loop </p><p> void loop()</p><p> {</p><p> delay(10);</p><p> if (Serial.available() &gt; 0) </p>
<p>using </p><p>void setup()</p><p> {</p><p> Serial.begin(9600);</p>
<p>I had the same problem, but after changing the baud rate of the Arduino Serial Communication from 9600 to 38400 (this is the baud rate of my HC, you can check yours using https://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/ and the command 'AT+UART?) the problem was solved. </p>
<p>Hey Every one.. All the things work well but when click on <strong>LedOn</strong> button it responds nothing, i have tried like this;</p><p>public void turnOnLed(View view)</p><p>{ </p><p>if (btSocket!=null) </p><p>{ try</p><p>{ </p><p>btSocket.getOutputStream().write(&quot;TO&quot;.toString().getBytes()); Toast.makeText(getApplicationContext(), &quot;Led off&quot;, Toast.LENGTH_SHORT).show();</p><p> } </p><p>catch (IOException e) { msg(&quot;Error&quot;); }</p><p> }</p><p><strong>else</strong></p><p><strong>{</strong></p><p><strong> msg(&quot;Operation Failed&quot;); }</strong></p><p><strong>}</strong></p><p>This is executing the bold/else body.. Plz any help me for this issue. thanks.</p>
<p>Please teach me how to solve the &quot;action settings&quot; problems, I copy the identical code from the tutorial but it shows two problems, and it didn't create the menu file automatically I create it by myself please help me </p>
please tell how to remove this DeviceList class error
<p>You have named your first Activity &quot;MainActivity&quot;..</p><p>But it's supposed to be named &quot;DeviceList&quot; :D</p>
<p>I am trying to enable BT communication in another activity, I try to use btSocket.xxxx in the 3rd activity but it doesn't work.(even I change private to public static)</p><p>How can I make it with your code?<br>Then I try re-connect it in the 3rd activity like this </p><p>/*****************************************************/<br>try{ <br> if (!flagBtConnected) { <br> myBluetooth = BluetoothAdapter.getDefaultAdapter();<br>BluetoothDevice dispositivo=myBluetooth.getRemoteDevice(address);</p><p>btSocket=dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);<br>BluetoothAdapter.getDefaultAdapter().cancelDiscovery();<br>btSocket.connect();<br>BtConnected = true;}<br>/*****************************************************/<br>and onButtonClick send the data:</p><p>/*****************************************************/</p><p>try{ btSocket.getOutputStream().write(data_to_send1.toString().getBytes());}<br>catch (IOException e){msg(&quot;Error&quot;);}</p><p>/*****************************************************/</p><p>but when I run the app, it always goes to Error</p>
<p>I am trying to enable BT communication in another activity, I try to use btSocket.xxxx in the 3rd activity but it doesn't work.(even I change private to public static)</p><p>How can I make it with your code?</p>
<p>Thanks for this awesome tutorial! :D<br>Is there any way to receive data send by Serial.println(string);?</p>
<p>What if I want to pair the devices in 1 activity, and send data at a different activity? Is there any way to pass the bluetooth socket between activities?</p>
<p>Thanks for the great tutorial. How could it be done with WLAN? Like P2p?</p>
<p>And if I want to turn on several lights example of my house as I do the android code, but I have the design of the app I lack the code main</p>
<p>Thank You so much for the tutorial!</p>
<p>I have a mistake while compiling the code:</p><p>for (BluetoothDevice bt : pairedDevices){</p><p>...//Get the device's name and the address</p><p>}</p><p>It says that for loop has incompatible types. Can I rewrite the statement inside the brackets in other way?</p><p>And also here i.putExtra(DeviceList.EXTRA_ADDRESS, address);</p><p>EXTRA_ADRESS - cannot resolve symbol. the same mistake is in ledControl class.</p><p>Do I have to initialize a variable for that?</p><p>Can someone help me?</p>
<p>I just had the same problem. Up above the for loop &amp; if statement, i changed</p><p>pairedDevices= myBluetooth.getBondedDevices();</p><p>to</p><p>Set&lt;pairedDevices&gt; = myBluetooth.getBondedDevices();</p><p>It looks like it's working for me now.</p>
<p>I still have EXTRA_ADDRESS issue (cannot resolve symbol..)</p><p>someone can help me?</p>
<p>You need to put this line in the beginning of the DevicesList Class:</p><p>public static String EXTRA_ADDRESS = &quot;device_address&quot;;</p>
<p>hey can u help??</p>
<p>you should specify the data type of the set:</p><p>private Set&lt;BluetoothDevice&gt; pairedDevices;</p>
<p>Solution:<br>I. Download the .rar file<br>II. Open the LED project with Android Studio<br>III. Change these pieces of code<br>IV. Open Arduino IDE and write this code in a blank file</p><p>V. Upload the file on Arduino and run the apk on your Android device.<br><br>This worked with me.</p>
<p>may i ask where is the rar file is ?</p>
<p>Page nine </p><p>https://www.instructables.com/id/Android-Bluetooth-Control-LED-Part-2/step9/Download/</p>
<p>Hi, do you know how to make a input text box, so the app can send whatever you type on the app to the arduino, like a serial monitor in the app?</p>
<p>Hello Everybody!</p><p>Please can you help me? I have a problem with code in AndroidStudio.</p><p>I have red underline &quot;myBluetooth.isEnabled()&quot; I dont know what, i am beginner in android studio.</p><p>Thank you very much.</p>
<p>You have to add permission in AndroidManifest, if you click over the error will appear a red buld, if you click it there is an option like &quot;ADD PERMISSION BLUETOOTH&quot; or something like that. This worked with me</p>
<p>Hi, i have some problem, im using arduino /genuino uno, how can i receive data from android to my hc-06, i tried your code and i connected to bt module, but i cannot turn on/off led 13, could you help me? Thank you!</p>
<p>Hey, i have tried this. Everthing ok but when i upload the code into the phone. It will come up with 'unfortunately project has stop'. Why it happened?</p>
<p>Hey everyone</p><p>I just have a problem, everything works perfectly but it drops connection after a while, only way to make it work again is if i reset the arduino/bt module...</p><p>i read in comments below that it establishes connection for only 120 sec.</p><p>is there a fix for this?</p><p>thanks</p>
<p>Hi,</p><p>Can anybody help me please?<br>I'm stucked a bit... So i need to have a 3rd activity as well... On the second which is here the LedControl() everything is fine, I can send commands to the bluetooth. But I have to create another activity, what code should I implement to send commands from that activity as well? I tried to put everything from the LedControl() to my 3rd activity, but it just doesn't send the command.</p><p><br>Thanks in advance!</p>
<p>Hello,</p><p>May I know if you have managed to make it work already? I can connect to the bluetooth but when I clicked &quot;ON&quot; on the app, the rx on arduino board responded but the LED is not lighted up.. Can you help me please? Thank you. </p><p>-Xin</p>
<p>Hello,</p><p>I just properly followed the steps. Hard to help you because I use this for other thing, but first I would check that did you put the LED to the right pin on the arduino, because if the RX pin is lighted up, then the connection should work fine? Or did you put in the right way? I use different activites and different pins, but the connection on my second activity works fine. I just cannot find out how to use the data transfer on 2 other activities as well.</p><p>Hope U can find the problem :)<br>- Zsolt</p>
<p>Hello Zsolt,</p><p>Thank you so much for your reply, I really appreciate it. (-: </p><p>I was wondering if you connected the rx and tx pins of bluetooth module to pin 0 and 1 of the arduino board? I can't upload the code to the board when I use those pins so I included SoftwareSerial in my code in order to use other pins.</p><p>- Xin</p>
<p>Hi Xin,</p><p>I use the TX RX pins of the arduino, TX-to Bluetooth RX, RX to TX... While you upload the code you have to unplug these two pins, when it's uploaded you can plug it back again and it'll work</p><p>- Zsolt</p>
<p>Okay sure, I will give it a try. Thank you so much for your assistance Zsolt </p><p>-Xin</p>
<p>Hi Xin,</p><p><br>Hope U can manage it ;)</p>
<p>Hello Zsolt, just to let you know I have tried it out and it really did solve my problem (-: So glad it finally worked. </p><p>Once again, thank you so much for your help! ^^</p><p>- Xin</p>
<p>Good news! Youre welcome Xin! ;)</p><p>-ZS</p>
<p>hello</p><p>are you have done with your problem?</p><p>actually I'm facing a same problem with you, I want to send data from 3rd activity but when I turn to 3rd activity the app is stop working.</p>
<p>The connection stops working after a While, is there any solution ?</p>

About This Instructable

405,893views

218favorites

License:

Bio: Dude!
More by Deyson:How To: Create An Android App With Android Studio to Control LED LED Control using Arduino Bluetooth and Android. (Part 1) Arduino and LabVIEW 
Add instructable to: