Home All Projects
Easy

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.

Connect a board via BLE with a app on MIT App Inventor
PS

Project Supporter Team

Posted by

Internet of Things, BT & Wireless
13,738 views
5 likes

Components, Tools and Machines

1x Arduino® Nano ESP32
🛒 Buy Now
1x Arduino USB Type-C® Cable 2-in1
🛒 Buy Now
1x Android phone
-

Apps and platforms

1x MIT App Inventor 2
Official Site
1x Arduino IDE 2.0 (beta)
Official Site

Project description

Understanding BLE vs. Classic Bluetooth

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.

Importing the BluetoothLE 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.

Setting Up the User Interface (Designer)

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.

Working with Blocks

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

Device Scanner Implementation

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.

Handling Luminosity Data

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.

Sending Data Over BLE

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.

Preparing the Arduino board

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.

Code

🔒 Unlock Code

Support to get the Source Code for this project

Project Reference Code: connect-a-board-via-ble-with-a-app-on-mit-app-inventor-03663e-en
1990 THB
PromptPay QR Code