Arduino Bluetooth controlling application development using Android Studio

Description:

Arduino Bluetooth controlling application development using android studio- in this article, I am going to show you to design and develop an android application that controls anything over Bluetooth. in this article, I am covering only the android side. for Arduino programming and  circuit diagram visit my article, Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth


Arduino Bluetooth controlling Application Designing and Development:

First of all, open the Android Studio.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Click on Start a new Android Studio project

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

While Choose your project form is open.

Select the empty activity and click on the Next button

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

After you click on the Next button, then configure your project form is opened, over here you set the project name, package name and you can select a directory where you want to store the application. Make sure the language is set to Java. So after you are done then you can click on the Finish button.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Wait for app synchronization

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

When your project is fully synchronized, as you can see the green dots in the following picture which is an indication that the synchronization is completed and we are ready for the next step.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Before starting app design there are two main classes which are PreferencesActivity.java and ActivityHelper.java

Now create a java class

Arduino Bluetooth controlling

Enter name as the ActivityHelper and click ok

Arduino Bluetooth controlling


And past below code

ActivityHelper.java code

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Now create the second java class

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Enter the class name as the preferrencesActivity and click ok

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth


PreferrencesActivity.java code


Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Now we will make a layout for the Search and connect buttons. The search button will be used for searching the Bluetooth module and the connect button will be used to connect with the paired Bluetooth module.

For this click on the small arrow symbol given with the bluetoothlight and find the Res and click on the small arrow to expand it, under the res then click on the layout to expand it and click on the activity_main.xml this will open the design screen.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Now change the layout form constraint layout to linearlayout

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

As you can see in the picture below.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Now we make another linear layout within the main linearlayout

To create a button in XML we use the button attribute having some property that you can adjust as per your requirements.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

To check the design layout for this change from text mode to the design. As you can see at the end of the coding there are two button with captions Design and Text. You can click on the Design button. As you can see the mouse cursor.

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

It’s a good programming practice to keep checking your design layout as you continue to program. So now we are done with two buttons with captions search and connect. Now we will add the code for the paired device, for this, we use the listview attribute. Click on the Design button to check.Copy the below code in your activity_main.xml

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

activity_main.xml code

Now open the mainActivity.java class and paste the below code

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

MainActivity.java code



To remove this error just click on the red bulb and select create id value resource And then click ok

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

So now you can see the list_item.xml is created

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Open list_item.xml file and paste this code

Now we build the main controlling window, click on the package folder right now

Then New

Then Activity

And click on the Empty Activity

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Open activity_controlling.xml

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Now change the layout form constraint layout to RelativeLayout

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Open the activity controlling.xml and switch the text type to the design mode

 

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Before creating a toggle button first of all copy these two images in drawable folder which is giving below

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

 

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

right-click on drawable and click on the android resource file

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

The resource file name is on_off and press ok and paste the below code

 

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

Now open activity_controlling.xml and paste the below code



Finally, open the Controlling.java file

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

and paste the below in your Controlling.java file

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

We are done with designing and programming. Now the next step is to create the APK file.

Creating Arduino Bluetooth controlling application .apk file:

Click on the Build menu then hover the mouse on build bundle/(apk) and click on the build apk

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

And then wait for around one minute depending on your laptop or computer processing speed.

 

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth

After generating the apk file then click on locate and transfer the app-debug.apk to the phone and install

Arduino Bluetooth controlling system for Home Automation using Arduino & Bluetooth


Bluetooth enabling permission

You must claim two permissions to use Bluetooth features in your software. BLUETOOTH is the first of these. To perform some Bluetooth communication, you need this permission, such as requesting a link, accepting a connection, and transferring data.

ACCESS FINE LOCATION is the other permission to be declared. Your device requires this permission because you can use a Bluetooth scan to collect information about the user’s location. This data can come from the user’s own phones, as well as from Bluetooth beacons used at places like shops and transit facilities.

You will declare the BLUETOOTH ADMIN permission in addition to the BLUETOOTH permission if you want your app to trigger network discovery or modify Bluetooth settings. Many applications only need this permission for local Bluetooth devices to be discovered. Unless the program is a “power manager” which modifies Bluetooth settings upon user request, the other features provided by this permission should not be used. Declare permission(s) for Bluetooth in your manifest application file. Don’t forget to add the Bluetooth permission in manifest.xml before you create the APK file.


 

Download apk file: home automation app



Final Design of Home Automation Android Bluetooth App:

Arduino Bluetooth controlling

Recommended For You

About the Author: Fawad

My name is Shahzada Fawad and I am a Programmer. Currently, I am running my own YouTube channel "Expertstech", and managing this Website. My Hobbies are * Watching Movies * Music * Photography * Travelling * gaming and so on...

Leave a Reply

%d bloggers like this: