In this tutorial we will show how to create a simple Android app to connect to the BLE module. This is the 3rd part of the tutorial series Bluetooth Weather Station with Arduino with the 2nd part being .Bluetooth Weather Station with DHT Sensor.
By connecting the Adafruit BLE module, we open up avenues to: • Acquire hands-on experience with pre-existing open-source projects. • Deconstruct Java code and gain insights into the linkage between the Main activity and the layout files. • Customize the code to activate an LED through Bluetooth and ensure its functionality.
Our endeavor employs an open-source solution that seamlessly integrates with the Adafruit Bluetooth module and is finely tuned for employment within the Android Studio IDE.
In the course of this chapter, we will also comprehensively elucidate the purpose of various segments within the codebase.
For the successful execution of the project, it is imperative to have the requisite SDKs, which are outlined in Chapter 1, "Setting Up Your Workspace," properly installed. Access to the SDK can be attained through the SDK Manager, conveniently located under Tools > Android > SDK Manager.
The primary stride entails navigating to Tony Dicola's GitHub public repository, accessible via the following link: https://github.com/tdicola/BTLETest, as exemplified in the subsequent screenshot:
Here are the rewritten instructions:
To begin, give the extracted file a double-click (applicable for both Windows and Mac systems).
Launch Android Studio and proceed to select "Import Project." Then, opt for "Choose Extracted Folder," following the example illustrated below:
to the folder you need to choose, as shown in the following screenshot:
After making changes to the settings in the Gradle Settings menu, you'll receive a prompt to synchronize your project configuration. To perform the synchronization, simply click on the "Sync Now" button. With the Gradle settings successfully configured, you're ready to test the application on a physical Android device that is compatible with BLE. Ensure the device runs Android 4.3 or a more recent version. To run the app, navigate to the toolbar, click on "Run," then select "Run app." Finally, choose the appropriate physical device from the options, as illustrated in the screenshot below:
You have the option to transmit the subsequent messages to the Bluetooth module by touching the Text Field and subsequently selecting the Send command:
- /mode/7/o /
- /digital/7/1 /
- /digital/7/0 /
Once you observe that the aforementioned messages generate appropriate responses through the LED – turning on and off in accordance with the given sequence – we can then move forward with adjusting the layout file.