kotlinuuidandroid-bluetoothhc-05

How to get UUID for Android to HC-05 Bluetooth connection


I am attempting to create an Android app that will connect to an HC-05 Bluetooth module connected to an Arduino Uno. I have been using example code as the base for my project so I am lacking complete understanding of the code. My code uses the UUID and I am wondering where you get that from. Is it from the Android phone, HC-05, or the Arduino Uno? How do you go about finding this?

I have tried looking online but have not found an answer which works for me. Any help would be greatly appreciated.


Solution

  • Reading up on the BluetoothDevice class from the Android Documentation.

    If you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. However if you are connecting to an Android peer then please generate your own unique UUID.

    Therefore, for HC-05, you need need to connect to the Bluetooth serial board:

    private val NAME = "HC-05"
    private val KNOWN_SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");