Reputation: 390
So, recently I follow these series of tutorial http://www.youtube.com/playlist?list=PL2cK5QO_pN1gfEcWZ8tCWUb-WyxAiMyIK To connect Arduino with Android using Bluetooth module HC-05
I did exactly on his scheme, the bluetooth module detected as HC-05 on my android, but won't get paired. The red LED keep blinking. as http://mcuoneclipse.com/2013/06/19/using-the-hc-06-bluetooth-module/ said the red LED on the module indicates the status: blinking: ready to pair steady on: paired
here is the code that I should get output "(Paired)" beside my device name
receiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)){
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
devices.add(device);
String s = "";
for(int a=0;a<pairedDevices.size();a++){
if (device.getName().equals(pairedDevices.get(a))){
//append
s = "(Paired)";
break;
}
}
listAdapter.add(device.getName()+" "+s+" "+"\n"+device.getAddress());
}else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
}else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
}else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
if (btAdapter.getState() == btAdapter.STATE_OFF){
turnOnBT();
}
}
}
};
instead i got a toast saying that the device is not paired
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
if (btAdapter.isDiscovering()){
btAdapter.cancelDiscovery();
}
if (listAdapter.getItem(arg2).contains("(Paired)")){
BluetoothDevice selectedDevice = devices.get(arg2);
ConnectThread connect = new ConnectThread(selectedDevice);
connect.start();
}else {
Toast.makeText(getApplicationContext(), "device is not paired", 0).show();
}
}
what did I miss? note: I am using, external power supply Module HC-05 with two chip (on video there is only one chip) Arduino UNO (on videos used Android Pro Mini)
Upvotes: 2
Views: 7228
Reputation: 35
You can also make your hc 05 to be connected by your code instead of pairing it from settings. You just made one mistake in your code: Inside onItemClick method you are checking if devices is already paired then you call connect thread and if not paired you are showing toast saying device not paired , but it does not make any sense .. You should connect it if it does not contain "paired" else you make an object of connectThread and call connect method. Hope this works! Let me know if it does not.
Upvotes: 0
Reputation: 390
i find my own answer, before connecting using our own apps in android, we have to pair it first from system settings>bluetooth> input password of our bluetooth module (in my case 1234)
Upvotes: 2