Connect a board via BLE with a app on MIT App Inventor
Expand the possibilities of your next project by connecting your smartphone and Arduino board by using BLE.
Expand the possibilities of your next project by connecting your smartphone and Arduino board by using BLE.
Project Supporter Team
Posted by
BLE (Bluetooth Low Energy) is often confused with classic Bluetooth. While MIT App Inventor provides components named BluetoothClient and BluetoothServer in the palette, these do not support BLE. Instead, to work with BLE, you need to import an extension.
Navigate to the Extensions category in the palette.
Click on Import Extension. You will be prompted to either upload an extension or provide a URL.
You can find a range of extensions at MIT App Inventor Extensions . For this project, we will use the BluetoothLE extension listed under the "Supported" category. Copy the URL for this extension and use it to add BLE functionality to your project.
Once imported, you’ll see BluetoothLE in the Extensions category. Drag and drop this component onto your app's component list.

Your UI and components will vary depending on your use case. For this demonstration, the UI includes a button for scanning devices and a ListViewer to display available BLE devices. The ListViewer is configured to be visible only when searching for devices. Additionally, a luminosity sensor component is added to fetch brightness data.

Initializing UUIDs: The service and characteristic UUIDs are set as global variables. These UUIDs ensure the correct BLE communication with your Arduino.

Blocks are created to scan for devices, list them in the ListViewer, and establish a connection when a device is selected. Once connected, the ListViewer becomes hidden.
Establishing the Connection: After setting up the device scanner and selecting a BLE device from the ListViewer, the app connects to the selected device. This is crucial, as data transmission can only occur once the connection is active.

The luxSense.LightChanged block captures changes in the luminosity sensor’s readings. The lux value is updated in a global variable and displayed on the user interface.

The timerblock periodically checks if the BLE device is connected. If so, the BluetoothLE1.WriteIntegers method sends the lux value to the Arduino using the predefined service and characteristic UUIDs.

Upload the provided sketch in this project to your board and it should start advertising right after upload. The data will be transferred after linking your phone and information will be displayed via serial terminal.

Support to get the Source Code for this project