Bluetooth connection with HC06 requiring a pincode


I have an application that connects to a HC06, and send a text depending on what button is pressed on the screen.
My problem is just at the very first step, the bluetooth connection step, with the "recent" HC-06 modules that require a pin code to be paired (the application runs perfectly with the HC06 modules not requiring a pincode).

My app uses the following blocks to connect to the HC06 (the 2 first ones, the rest is just useless, it is just an example):

The HC06 modules requiring a pincode are not detected by my app, whereas they are detected by the common Bluetooth Terminal applications,, such as "Bluetooth Terminal HC-05 1.20" edited by mightyIT for example.
They are detected by my application only after having being paired tusing a common Bluetooth terminal application.

What should I do to be able to detect them prior being paired, and what should I do to get a dialog box for entering a pin code ?

Thank you,
P.S.: there are a lot of examples of bluetooth applications, but I have not found one regarding the pincode.

You need to pair your hc06 modules outside the app. When pairing, you must enter a pin code. After pairing, you can use the app to connect to the module.

1 Like

Or you can use an extension, which is able to do the pairing like this one
.App Inventor Extensions: Bluetooth | Pura Vida Apps


This is what i have understood just after I had posted my question !
You are right : this is the simplest way .

Regarding the extension suggested by Taifun, is there any ".aia" example somewhere ? I confess that I have not used MIT Appinventor for a while...

Thank you very much,

No, because it is a paid extension
A test project is available in Google Play


Thank you Taifun, but I do not need it: I just have to pair outside the app, this is a perfect approach for me.