How to Create Android App for Arduino Sensor Monitoring over Bluetooth

(Last Updated On: August 10, 2019)

Create Android App

Description:

How to Create Android App for Arduino Sensor Monitoring over Bluetooth- I have been using Android applications for monitoring  Arduino sensors over Bluetooth. I will share the links of all the projects in which I have used the android applications. Due to a lot of requests from my subscribers and followers on my YouTube channel “Electronic Clinic” to explain how to create your own android application. Finally, I decided to share with you the knowledge, how to develop your own Android app to monitor any sensor which is connected with the Arduino.

In this tutorial, you will learn how to create your own android cell phone application for monitoring any Sensor using Arduino, HC-05 Bluetooth module and an Android cell Phone. For the best understanding, I am using a variable resistor as the sensor. Later this variable resistor can be replaced with any sensor you want. This sensor monitoring application is designed using Android Studio. This is version 2 of the Android cell phone application designing.

While in version 1 of the android cell phone application designing, I created an application to control an LED using only two buttons.


 

In this tutorial, we will cover

  1. Complete circuit diagram explanation
  2. Interfacing
  3. Arduino programming
  4. Step by Step android cell phone App designing using Android Studio and finally
  5. Testing

without any further delay, let’s get started!!!

The components and tools used in this project can be purchased from Amazon, the components purchase links are given below:

Bluetooth Module: Hc-05: https://amzn.to/2CMHNiN
Arduino Uno: https://amzn.to/2tVz1vu
Mega 2560: https://amzn.to/2ze1kdu
GSM sim900A: https://amzn.to/2LLeFzy
Neo 6m GPS module: https://amzn.to/32XCYiX
Mq-2 gas/smoke sensor: https://amzn.to/313Sx6O
Nodemcu esp8266 wifi module: Best price https://amzn.to/2NAvmiB
LM7805 Voltage Regulator: https://amzn.to/2IZEl5x
Potentiometer: https://amzn.to/2JSLbfg
330 ohm resistors pack: https://amzn.to/2NtlAeh
5v 2A adaptor: https://amzn.to/2GsNfcw
2n2222 npn transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
LDR pack: https://amzn.to/2m2khGR
female DC power jack socket: https://amzn.to/2KEo1gt
470 uf capacitors: https://amzn.to/2xDCOzf
5×7 cm vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / strip board: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wire cutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF


The software’s used:

  1. The Software used for the Android app development
    • Android Studio
  2. Arduino IDE

About the Android Studio:

Android studio is one of the most commonly used software used for android app development which includes designing and programming. Before you follow this tutorial you should have some basic knowledge of how to use the Android studio. Otherwise It can be really confusing for you. My recommendation is first you should follow some basic tutorials and then you can resume from here.

Before we start the android app development, first of all, I would like to explain the circuit diagram and Arduino programming. Because we can only design a good android application if we know exactly for what purpose we are making this application.


Circuit Diagram:

Create Android App

This is a very basic circuit diagram designed in CadeSoft Eagle 9.1.0 version. If you want to learn how to make a schematic and PCB then watch my tutorial.

 

 

For the demonstration purposes, I am using a variable resistor. This variable resistor can be easily replaced with any sensor you want. As you can see the middle leg of the variable resistor is connected with the Arduino’s Analog pin A0. While the other two legs of the variable resistor are connected with the Arduino’s 3.3v and GND.



On the left side, you can see a Bluetooth module, you can use HC-05 or HC-06 Bluetooth Module. If you are using a Bluetooth for the first time then you can watch my getting started tutorial on the Bluetooth module, which completely explains how to change the name of the Bluetooth module and how to change the pairing code.

The Bluetooth module Tx and Rx pins are connected with the Arduino’s pin number 2 and pin number 3. Pin number 2 and pin number 3 will be used as the Serial Port, which will be defined in the programming. While the VCC and GND pins are connected with the Arduino’s 5v and GND.

Arduino Bluetooth Module Programming:

Arduino Program explanation:

As you know my friends in Arduino we have only one Serial port which is available on pin number 0 and pin number 1. As I always say never use these pins for communication with other devices. The Arduino’s default Serial Port should only be used for debugging purposes. You can always define other Serial Ports using the SoftwareSerial library. So that’s the reason I added the SoftwareSerial.h header file.

I defined a Serial Port with the name Blue on pin number 2 and pin number 3 of the Arduino. Pin number 2 is the Rx while Pin number 3 is the Tx.

On the third line, I defined a pin for the Variable Resistor which is connected with the Analog pin A0 of the Arduino.

Then I defined a variable Vdata of the type integer, this variable will be used to store the value of the variable resistor.



As you know my friends every Arduino and Mega program has at least two functions which are the void setup and void loop functions. This is inside the void setup function that we tell the controller what are the input pins and what are the output pins. As in this tutorial, I am using a variable resistor as the sensor so that’s why I set it as the input using the pinMode function.

Then I activated the Serial communication and I selected 9600 as the baud rate. One more thing about the void setup function. It executes only one time when the Arduino or Mega board is powered up.

Then starts the void loop function.

Using the analogRead function we read the analog pin A0 to which a variable resistor is connected and store the value in variable vdata.

And lastly we send the data to the Android cell phone application. After every 1 second data is sent to the Android cell phone sensor monitoring application. So that’s all about the Arduino programming.



Android app development:

First of all, open the Android Studio.

Create Android App

Click on Start a new Android Studio project

Create Android App

While the Choose your project form is open.

Select empty activity and click on the next button

Create Android App

After you click on the next button, the 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.


Create Android App

Wait for app synchronization

Create Android App

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.

Create Android App

After synchronization is completed the MainActivity.java and activity_main.xml open automatically

Create Android App

Before i start the main programming I want to tell you that there are two main classes which we first need to add

one is ActivityHelper.java

and the second is PreferencesActivity.java

now create ActivityHelper.java

right click on the package folder, then in new select java class.

Create Android App

Enter name as the ActivityHelper and click ok

Create Android App

Create Android App

ActivityHelper.java code:

Create Android App

Now create the second java class and follow the same steps as explained above.

Create Android App


Enter class name as the preferrencesActivity and click ok

Create Android App

Create Android App

preferrencesActivity.java code:


Create Android App

now you can see that we made two main classes one is ActivityHelper and the other is preferrencesActivity

Create Android App

Now we can start our main application  programming

Now we design our first launcher screen in which there will be two buttons search and connect and  listview

Open the activity_main.xml

Create Android App

Now change the layout form constraint layout to linearlayout

Create Android App

As you can see in the picture below.

Create Android App

Now we make another linear layout within the main linearlayout

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

Create Android App

Create Android App

To check how the design look like just click on design button as you can see in below picture

Create Android App

Create Android App


Now again click on the text button to open the coding. As in this App I am going to use only two buttons. So I can simply copy and paste the code and will change the caption of the button from search to connect.

Create Android App

Create Android App

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.

Create Android App

It’s a good programming practice to keep checking your desing 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 pair device, for this we use the listview attribute.

Create Android App

Create Android App

activity_main.xml code:

Now click on MainActivity.java tab as you can see

Create Android App

Change the appcompatActivity to Activity

Create Android App

Create Android App

MainActivity.java  code:

 

To remove these error just click on red bulb and click on create layout resource file “list_item”

Create Android App

And press ok

Create Android App

As you can see list_item.xml file is create open it and paste the code

Create Android App

list_item.xml  code:

 

So the list_item error is removed

Create Android App

To remove this errer just click on red  bulb and then click on  id value resource “action_sitting”

Create Android App


And press ok

Create Android App

Create Android App

Now we create the main controlling screen, for this right click on package folder

Then New

Then Activity

And click on the Empty Activity

Create Android App

Enter the activity name which you want  and click finish

Create Android App

Now open  activity_monitoring_screen.xml and change the layout form constraint layout to

LinearLayout

Create Android App

Create Android App

activity_monitoring_screen.xml code:

Create Android App

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.

Create Android App

Now open  MonitoringScreen.java

Create Android App

MonitoringScreen.java code:

 

And finally open the AndroidManifest.xml and add Bluetooth permission

Create Android App

AndroidManifest.xml  code:

For testing the app create apk file.so for apk file  click on build menu and then then click on build bundle(s)/apk and then build apk

Create Android App

Wait for generating apk file after generating the file a popup dialog will show as dialog shown just click on locate as you can see in the below picture

Create Android App

After clicking  on locate a folder will open where the apk is stored then just copy the app-debug.apk file and paste in the phone and install

Create Android App


Download:

Download apk file: sensor app apk file

For the Android app testing and explanation watch video tutorial is given below

Watch Video Tutorial:

 

Arduino Android App Related Projects:

Android app development to control Arduino over Bluetooth using Android Studio

 

12v Battery Efficiency Monitoring using Arduino and Cell App with Database

 

Unlock my car with my phone, Start engine, Start A/C, Anti theft using Arduino

 

Android HMI development- control HMI touch screen using Bluetooth “TFT touch screen”

 

Arduino Bluetooth controlled Robot using L298n Motor Driver Android App

 

Pulse Sensor/ Heartbeat Rate/ Heart rate measurement using Arduino & Bluetooth

 

Arduino Bluetooth Smart Lock using Android cell phone application

 

How to use GSM and Bluetooth Together To monitor Any Sensors wirelessly using Arduino

 

Wireless battery voltage monitor using Arduino and Bluetooth

 

Arduino Bluetooth Pin Code and Name changing using AT commands

 

Wireless Temperature monitoring system using Bluetooth

 

8×8 LED Matrix MAX7219 Control using Bluetooth and Arduino

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

1 Comment

  1. Your guides are great! The step by step walkthough for Android Studio is very good and helped me go from zero to having a functioning app. Thanks so much!!

Leave a Reply