Introduction: Android Arduino Bluetooth PC Game Controller

Picture of Android Arduino Bluetooth PC Game Controller

This instructable is show You How to make Android Arduino PC Game Controller . Android Arduino PC Game Controller is One Kind of Android Application Based Embedded System. An Android Application which is developed by Me Name "ArduCon" can Interacts with This System. The ArduCon Send value to the HC-05 Bluetooth Module and Arduino Leonardo Process This Value as Keyboard Instructions because Arduino Leonardo Have Keyboard,Mouse Emulation.

Step 1: Materials

Hardware:

> An Arduino Leonardo

> A HC-05 Bluetooth Module

> Some Jumper Wire

Software:

> Android Studio

> Arduino IDE (Integrated Development Environment)

Step 2: Schematic and Assembly

Picture of Schematic and Assembly

> Connect HC-05 Bluetooth Module +5v to the Arduino Leonardo +5v

> Connect HC-05 Bluetooth Module GND to the Arduino Leonardo GND

> Connect HC-05 Bluetooth Module TX to the Arduino Leonardo RX

> Connect HC-05 Bluetooth Module RX to the Arduino Leonardo TX

HC-05 ------------------------------------------- Arduino Leonardo

+5v -------------------------------------------------- +5v

GND ------------------------------------------------ GND

TX ------------------------------------------------- RX

RX ------------------------------------------------- TX

Step 3: Upload Code to Arduino

Now Download Arduino IDE from https://www.arduino.cc/en/Main/Donate and Install it then Download My Arduino Keyboard Emulation Code From given Link then Upload it to your Arduino Leonardo.

Step 4: Android Code Explanation

> First of All You will create a New Project from File in Android Studio give Project Name BluetoothDeviceList and create ListView and Button . ListView Show Device List Data When Your Android is Connected To the Bluetooth and Button is Pressed

Button btnPaired;<br>ListView devicelist;
//Bluetooth
private BluetoothAdapter myBluetooth = null;
private Set pairedDevices;
public static String EXTRA_ADDRESS = "device_address";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    btnPaired = (Button)findViewById(R.id.button);
    devicelist = (ListView)findViewById(R.id.listView);
    myBluetooth = BluetoothAdapter.getDefaultAdapter();
    if(myBluetooth == null)
    {
        //Show a mensag. that the device has no bluetooth adapter
        Toast.makeText(getApplicationContext(), "Bluetooth Device Not Available", Toast.LENGTH_LONG).show();
        //finish apk
        finish();
    }
    else if(!myBluetooth.isEnabled())
    {
        //Ask to the user turn the bluetooth on
        Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(turnBTon,1);
    }
    btnPaired.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v)
        {
            pairedDevicesList();
        }
    });

>> Create a Function and Give Name pairedDevicesList() . this function is responsible to get Bluetooth Paired Device name and Device Address and we take ArrayList and Set ArrayAdapter to Containe all Paired Device List data and call the pairedDevicesList() function in show devices button onclickListener(); the paired Device is only work when we press the Show Devices Button

private void pairedDevicesList()<br>{
    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);
}

>> Now Add onItemClickListener to the Paired Device List. this is usefull when we press any device Like HC-05 Module from ListView List and then given function can take the MAC Address from Pressed Item/Device from List

<pre>private AdapterView.OnItemClickListener myListClickListener = new AdapterView.OnItemClickListener()<br>{
    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(getApplicationContext(), GameControllerActivity.class);
        //Change the activity.
        i.putExtra(EXTRA_ADDRESS, address);
        startActivity(i);
    }
};

Step 5: Android Application Link

This is My "ArduCon" Android Application You can Also Download and Install My Application From Google Playstore to Control Your PC Via Bluetooth and Arduino


>>> I will Upload My Updated Application Soon....


Step 6: Arduino Source Code

Step 7: Android Application Source Code

This is My Android Application Code You Can Modify My Code and Create Your Own Application

Comments