Best Android Data Transfer Apps Available on Google Play Store

Data transfer tools are essential for sharing data across devices through a secure medium. The process can be hectic if you are trying to transfer data from one device to another manually. You can also miss some important data files during the manual method. Moreover, data transfer apps ensure a successful transfer process with their integrated technology. 

You can also back up or restore your data files by using the features of transfer apps. Therefore, the need for Android-to-Android transfer apps is essential. This article will highlight the top four data transfer apps available on the Google Play Store. Thus, give this guide a quick read to discover the features and pros of the suggested apps.

1. MobileTrans: Data Transfer 

MobileTrans is a famous data transfer app many people use for a safe transfer process. Using this tool, you can transfer data between devices without disturbing the original quality. One of the best features of MobileTrans is that it does not require an internet connection. By scanning the QR code, you can connect your devices effortlessly. 

Furthermore, this Android-to-Android data transfer app gives huge versatility to the users. You can transfer data selectively across your devices with one tap. The fast transfer speed of this tool can also positively impact your productivity. It can also help you sync any data files in your iCloud on your Android devices. Thus, it's a complete tool for flawlessly transferring data between Android devices.

Pros 

  • This tool does not impose restrictions on the type of data files. You can efficiently transfer media files, schedules, apps, and other content. 

  • With its WhatsApp transfer feature, you can save your WhatsApp chats on your new phone. The WhatsApp feature allows you to transfer WhatsApp messages and media files from one Android to another. 

Con 

  • You must buy a suitable subscription plan to use its advanced features. 

2. Copy My Data: Transfer Content 

Copy My Data is an easy-to-use transfer tool that lets you share multiple files instantly. It can transfer your contacts, photos, and high-quality videos without decreasing their quality. Moreover, it shows high compatibility with every Android and iOS device. 

Connect your devices with the same Wi-Fi connection to transfer data using this tool. Afterward, the tool will guide you by giving on-screen instructions. Hence, you can transfer your data files without complications within a few taps.

Pros

  • This Android-to-Android transfer app supports wireless connectivity. By scanning a QR code, you can build a connection between your two devices. 

  • This tool also provides a quick data restore option. Restoring your data can eradicate the risks of permanent data loss. 

Con 

  • This tool does not support the transfer of audio or music files. 

3. Zapya – File Transfer, Share 

Do you want to know about another advanced data transfer app? Zapya is one of the advanced Android-to-Android data transfer apps containing various features. For example, you can enhance the storage capacity of your device by using a USB drive. 

Moreover, it supports app sharing that lets users share applications with their friends in .apk format. This data transfer tool's enhanced Android support ensures secure file transfer between devices.

Pros 

  • Zapya can boost your work productivity through the feature of bulk transfer. This option allows you to share multiple files at once without any restrictions. 

  • The “Install All” feature allows you to install all the applications from your old Android to the new one. 

Con 

  • Sometimes, this app shows glitches and crashes during the transfer process. 

4. Smart Transfer: File Sharing 

Smart Transfer provides the fastest transfer speed with cross-platform compatibility. It has a 40 Mb/s speed that allows you to send media files to your friends within seconds. The bulk file transfer feature lets you send and share multiple files simultaneously. 

Furthermore, it does not require a Wi-Fi connection, data usage, or USB cables. Along with media files, you can also transfer text and MMS messages to your new Android device without any difficulty. 

Pros 

  • The smartphone cloning feature lets you transfer all your data in one step. Moreover, it supports various languages such as German, Spanish, Chinese, etc. 

  • It also works as a file organizer, as you can move, delete, and rearrange files on your device. 

Con 

  • This Android-to-Android data transfer app contains tons of ads disrupting the user experience. 

Wrapping Up

Data transfer apps are necessary for this age to secure file transfer. To help you, this article has highlighted the top four data transfer tools. These transfer tools are available on Google Play Store, which you can easily download on Android. However, if you want the best user experience and multiple features, MobileTrans is the top-rated app.

Line Following Robotic Waiter using Arduino

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a new project which is Line Following Robotic Waiter. I hope you guys are gonna enjoy it. I have shared all the details below so that if you wanna design it then you can easily do it. I have designed this project for a client and it worked quite perfectly so I thought to share it with you guys as well.

I have designed this Line Following Robotic Waiter using Arduino UNO board. I have also shared the code below and have given all the instructions but still if you got into any problem then ask in comments and I will solve your problems. I have also shared a video below which will show you the working of Line Following robotic Waiter. So, let's get started with it:

Line Following Robotic Waiter

First of all, let's have an overview of this Line Following Robotic Waiter:

Overview
  • In this project, I have designed an arena which has four tables on it as shown in below figure:
  • The robot will start from the Table 1 side and whenever someone call it from any table then it will reach that table and take the order.
  • After taking the order it will move back and will reach to the starting point again and wait for the next table call.
  • Now let's have a look at the components required to design thi Line Following Robotic Waiter:
Components
  • Let's have a look at the components list, which is required for designing this Robot. Here it is:
  • Arduino UNO
  • DC Motors
  • RF Module
  • 2 Relay Board
  • IR Sensors
  • These are the components required in order to design this Line following robotic waiter.
Mechanical Design
  • I have designed a three wheeler robot in which there were two wheels at the front side with DC motors while a free caster wheel at the back side.
  • I have used Acrylic Sheet as the body of the robot.
  • The DC Motor I have used for designing this project is shown in the below figure:
  • The caster wheel used is shown in below figure:
  • The coupled DC gear Motor with wheel is shown in below figure:
  • So I have designed two of such coupled motors and then combining all the above things together, we finally designed our Line Following Robotic Waiter as shown in below figure:
  • Now our mechanical Design is ready so let's design the electronic hardware:
Electronic Circuit Design
  • First of all, I have designed the DC Motor Driver which is also called 2 Relay Board.
  • This circuit diagram is shown in below figure:
  • Now in order to apply the signals to move the Motors I have used Arduino UNO board.
  • Moreover I have placed four IR sensors below this robot.
  • Two of these IR sensors are used for line tracking while the remaining two were placed on the sides for detecting the tables on both sides.
  • I have also designed a power supply to convert 12V into 5V.
  • The circuit diagram of power supply is as follows:
  • So, now let's have a look at the Arduino code required for Line Following Robotic Waiter:
Arduino Code
  • Here's the Arduino Code requried for Line Following Robotic Waiter.
#define motorL1 8
#define motorL2 9
#define motorR1 10
#define motorR2 11

#define PwmLeft 5
#define PwmRight 6

#define SensorR 2
#define SensorL 3
#define Sensor3 A0
#define Sensor4 A1

#define TableA A4
#define TableB A2
#define TableC A5
#define TableD A3

int OriginalSpeed = 200;
int TableCount = 0;
int TableCheck = 0;
int RFCheck = 10;

void setup() 
{
  Serial.begin (9600);
 
  pinMode(motorR1, OUTPUT);
  pinMode(motorR2, OUTPUT);
  pinMode(motorL1, OUTPUT);
  pinMode(motorL2, OUTPUT);
  
  pinMode(PwmLeft, OUTPUT);
  pinMode(PwmRight, OUTPUT);
  
  pinMode(SensorL, INPUT);
  pinMode(SensorR, INPUT);
  pinMode(Sensor3, INPUT);
  pinMode(Sensor4, INPUT);
  
  pinMode(TableA, INPUT);
  pinMode(TableB, INPUT);
  pinMode(TableC, INPUT);
  pinMode(TableD, INPUT);
  
  MotorsStop();
  
  analogWrite(PwmLeft, 0); 
  analogWrite(PwmRight, 0);
  delay(2000); 
 // Serial.println("fghfg");
  
}

void loop() {
  MotorsForward();
if((digitalRead(Sensor3) == LOW) && (TableCheck == 0)){TableCount++; TableCheck = 1;}
if((digitalRead(Sensor3) == HIGH) && (TableCheck == 1)){TableCheck = 2;}

if((digitalRead(Sensor3) == LOW) && (TableCheck == 2)){TableCount++; TableCheck = 3;}
if((digitalRead(Sensor3) == HIGH) && (TableCheck == 3)){TableCheck = 4;}
if((digitalRead(Sensor3) == LOW) && (TableCheck == 4)){TableCount++; TableCheck = 5;}
if((digitalRead(Sensor3) == HIGH) && (TableCheck == 5)){TableCheck = 0;}

if(digitalRead(TableA) == HIGH){RFCheck = 1;}
if(digitalRead(TableB) == HIGH){RFCheck = 2;}
if(digitalRead(TableC) == HIGH){RFCheck = 3;}
if(digitalRead(TableD) == HIGH){RFCheck = 4;}

if(RFCheck == TableCount){Table1();}
PIDController();
}

void MotorsBackward()
{
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, LOW);
    digitalWrite(motorR1, HIGH);
    digitalWrite(motorR2, LOW);
}

void MotorsForward()
{
    digitalWrite(motorL1, LOW);
    digitalWrite(motorL2, HIGH);
    digitalWrite(motorR1, LOW);
    digitalWrite(motorR2, HIGH);
}

void MotorsStop()
{
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, HIGH);
    digitalWrite(motorR1, HIGH);
    digitalWrite(motorR2, HIGH);
}

void MotorsLeft()
{
    analogWrite(PwmLeft, 0); 
  analogWrite(PwmRight, 0);
    digitalWrite(motorR1, HIGH);
    digitalWrite(motorR2, HIGH);
    digitalWrite(motorL1, LOW);
    digitalWrite(motorL2, HIGH);
}

void MotorsRight()
{
      analogWrite(PwmLeft, 0); 
  analogWrite(PwmRight, 0);
    digitalWrite(motorR1, LOW);
    digitalWrite(motorR2, HIGH);
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, HIGH);
}

void Motors180()
{
    analogWrite(PwmLeft, 0); 
    analogWrite(PwmRight, 0);
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, LOW);
    digitalWrite(motorR1, LOW);
    digitalWrite(motorR2, HIGH);
}

void PIDController()
{
  if(digitalRead(SensorL) == HIGH){analogWrite(PwmRight, 250);analogWrite(PwmLeft, 0);}
  if(digitalRead(SensorR) == HIGH){analogWrite(PwmLeft, 250);analogWrite(PwmRight,0);}
  if((digitalRead(SensorL) == LOW) && (digitalRead(SensorR) == LOW)){analogWrite(PwmRight, 0);analogWrite(PwmLeft, 0);}
}

void Table1()
{
   TableCount = 0;
   MotorsRight();
   delay(4000);
   while(digitalRead(SensorR) == HIGH);
   while(digitalRead(SensorL) == HIGH);
   while(1)
   {
       MotorsForward();
       PIDController();
       if(digitalRead(Sensor3) == LOW){break;}
   }
   MotorsStop();
   delay(1000);
   Motors180();
   delay(2000);
   while(digitalRead(Sensor3) == HIGH);
   while(digitalRead(Sensor3) == LOW);
   while(digitalRead(SensorL) == HIGH);
   //delay(500);
   while(1)
   {
   MotorsForward();
   PIDController();
   if(digitalRead(Sensor3) == LOW){break;}
   }
   //delay(1000);
   MotorsLeft();
   delay(4000);
   while(digitalRead(SensorL) == HIGH);
   while(digitalRead(SensorR) == LOW);
   while(1)
   {
       MotorsForward();
       PIDController();
       if(digitalRead(Sensor3) == LOW){break;}
   }
   MotorsStop();
   delay(1000);
}
  • This code will not work for you exactly.
  • The robot is following the line so I have placed some value for IR sensors so that my robot can follow.
  • When right IR sensor is HIGH then right motor moves a little faster and left motor slows down.
  • In this way I am making it to follow the line so you have to change such values in the code.
  • If you got into any issue regarding this project then add us on Skype and we will help you out.
  • Here's our final robot looks like:
  • Here's the video of Line following Robotic Waiter which will give you the better idea of how it worked:
That's all for today, I hope you have enjoyed today's project. Will meet you guys in the next tutorial. till then take care and have fun !!! :)

How to Install Android Studio ???

Hello Friends, welcome back to the second tutorial of ‘Android Application Development’ by ‘The Engineering Projects’. I hope you guys are fine and enjoying your lives. In the previous tutorial, we have seen How to Get started with android studio. Today, we are going to have a look at How to install Android studio on your computers. Its a beginner level tutorial and is quite essential for beginners. Because when you plan to start learning some new software then its correct installation and environment setup is the main key. When you are going to start with the installation of any platform, first of all, what you need to do is to set up the environment in proper way. So that's why, today we are going to cover the installations of all the software required to start with Android application development.

It is very important for you guys to follow each and every step carefully. But sometimes even by adopting the right methodology, you are not being able to set up the right environment for the development. This happens because of your product version or system configuration unexpected results. Before stepping up the installing phase, I would like to mention one important thing that Android Studio is a very strong development tool. So that's why, I would recommend you guys to use at least i3 with 4GB but preferable is 8GB RAM, otherwise your laptop or computer will struck again and again and takes a lot of time. Let’s start without wasting anymore time. As I recall, in the end of our previous tutorial, I mentioned all the software we required to start our first project. So let’s install Android studio and all of the related software one by one.

Installation of Java Development Kit (JDK)

In order to install Android studio, first what we need to install is Java Development Kit which is known as JDK. Java Development kit is essential to install before the installation of Android studio because our Android studio works on Java so that's why its essential to install JDK first. JDK contains libraries, compiler, Debugger, java virtual machine, user interface toolkit and all the other basic components required for Android Application and Applets Development. Let’s move to the Java Development Kit (JDK) installment, as I mentioned in my previous tutorial that all the software required for Android Application Development are free of cost, so you guys can simple download JDK from their official site, just by clicking on JDK and I will recommend you to install the latest version of it. After the installation of JDK, now we are ready to install Android Studio. So, let's get started with it.

How to install Android Studio ???

  • Android Studio is the actual development software we are going to use for the Android application development. We will do designing and will write all the codes in Android Studio.
  • Android Studio is also free of cost, so you guys should download it from the official site of Android.
  • The site would have the display as shown in below figure, click on the green button on the left bottom to download Android Studio.

  • Once you click the download button, Google will ask you to accept their ‘Term and Conditions’.
  • After reading all the ‘Terms and Conditions’ go to the end of the page, you will see the check box.
  • Click on the check box to accept all the Terms and Conditions of Google and then click on the button under the check box to download Android Studio.
  • Now the downloading will be started.
Installation of Android Studio
  • Once the downloading completes, double click on the downloaded file and execute it. Installation will start like the one given below:
  • It will take a few seconds and then it will move to the next step, as shown below:
  • Click on the ‘Next’ Button and then check the box for “Standard” and click ‘Next’.
  • And finally click on the ‘Finish’ as shown in below figure:
  • After clicking on ‘Finish’, it will take some time to complete the installment. You will also need to be connected with the internet.
  • Once everything done, then you will get to the below screen and simply click finish to complete the installation.
  • You will see the Welcome Screen after the installment would be completed. So now friends, you guys are ready to develop your first Android Application.
  • Here's the welcome screen of Android studio:

Software Development Kit (SDK)

In the previous section, we have seen How to Install Android Studio. Now, we are gonna install the SDK. Basically SDK is a set of tools which allows you to make applications, games, Applets for certain software package, computer system, software framework, video game console, hardware platform, operating system, or similar development platform. So it is pretty much important to install required SDK before developing your first application. So, let's get started with installation of software development kit (SDK).

  • First of all, click on the ‘Configure’ and it will take you to the window as shown in below figure:
  • Click on the SDK Manager. It will take a few seconds to check all the online SDK available right now and then it will show you all the installed, not installed, update available and partially installed SDK as shown in below figure:
  • Click on the pointed ‘Launch Standalone SDK Manager’ as shown in above figure.
  • Now when you click, it will open the window, where you can select the SDK, you want to install, as shown in below figure:
  • I will suggest you to install at least 3 of them which are very important and plays important role:
  1. Tools
  2. Android 4.4.2 (API 19)
  3. Extras

Unexpected Results or Errors:

Several users have to face some difficulties after completion of the Android Studio Installation on Windows 7 and windows 8. When they try to open Android Studio after installing it, they get errors.

  1. Fail to load JVM.DLL
  2. dll is missing
So here is the solution to these problems.
Fail to load JVM.DLL
When you open the Android studio, this error will pop up like the window given below:
  1. Go to the Control Panel and selectSystem.
  2. Click on “Advanced system settings” from the column on the left side and go to the “Advanced” tab.
  3. Click the “Environment Variables” button at the bottom. On the next screen, you will see two sections, User Variables and System Variables.
  4. Now add a system variable with the following values. Variable name:JAVA_HOME Variable Value: c:\program Files\Java\jdk1.7.0_21

May be you have different jdk version as compare to the one given in Variable Value. So before adding the value check your jdk version in this directory c:\program Files\Java\

MSVCR100.dll is missing

If this window comes up after adding the System Variable, then you need to install Visual Studio 32 or 64 bit.

This is it for now. I hope you now have got the idea about How to install Android studio in windows. In the next tutorial we’ll develop our first Android Application and discuss some of the basics of Android Studio. If you guys have any questions or suggestions, feel free to comment about them. So Stay tuned and have fun. See you guys later.

Getting Started with Android

Hello Friends, My name is Syed Daniyal Nasir. I hope you guys are fine and enjoying your lives with passion. Today, we are going to start the new series of tutorials related to Android Development and here's my first tutorial in thie series which is, Getting Started with Android. This is gonna be my first tutorial of Android Development for “The Engineering Projects”. As we all know, Android Development is enhancing vigorously day by day, Google Play Store is flooded with tons of new mobile applications each day. So a lot of people want to understand the basics of Android Development, so that they could develop their own applications. But some people find it very difficult due to certain reasons. That’s why we are going to make these tutorials as simple as possible, so that most of the people can find it useful. Now let’s get started with today's tutorial which is Getting started with Android.

In today's tutorial, we are not gonna cover anything technical. Instead, we are gonna stick to the basics of Android, like why we need Android and why we need to getting started with android. I will also share some useful theoretical knowledge in this post. So, my suggestion is to must read it once. Anyways, let's have a look on Android. :)

Note:

  • This tutorial is written by my brother SyedDaniyal Nasir, as he mentioned above, I am just posting it here on my blog as he was not free to do it on his own.
  • Welcome bro to my blog. :)

Getting Started with Android

Android Platform was developed by Open Handset Alliance which is then led by Google and they gave it a very attractive look and now a days, Android has been the most selling OS on Smart Phones and Tablets. Android is basically a touch screen mobile open source operating system based on Linux Kernel. In 2007, Google released the first beta version of the Android Software Development kit (SDK) and later in the next year, first commercial version by the name “Android 1.0” was finally released in September, 2008 by Google.

Android Programming

Android Programming style is based on Java Language. So for Android Development, you need to have a little bit knowledge of Java Language. Sun Microsystems released the first version of Java language in 1995. Most of the devices support Java language like, smart phones, Tablets, Raspberry Pi, laptops, desktop computer and many more. There is a little complication, to run Java code on any platform, needs to have a Virtual Machine implementation. But you don’t need to worry about it right now, we’ll cover this in our upcoming tutorials. So if you have some knowledge of Java Language then I am sure that you will find it very interesting.

Why Android?

If you are taking your first step towards the Mobile Application Development. You should definitely start with Android. Some of the key points are shown in the following figure.

Android Versions
Android versions were named in alphabetical order. This first android version was named as Aestro while the latest one is Marshmallow. So, we have Android versions from A to M, which are shown as follows:
  • Aestro.
  • Blender.
  • Cupcake.
  • Donut.
  • Eclair.
  • Froyo.
  • Gingerbread.
  • Honeycomb.
  • Ice Cream.
  • Sandwitch.
  • Jelly Bean.
  • KitKat.
  • Lollipop.
  • Marshmallow.
What is API?
API stands for Application Programming Interface and API is used to interact with different systems, libraries and applications. API level is a value which shows the API version. Here's a small table for different versions of Android with respect to their API versions.
Android Applications

As of July, 2015, more than 1.6 million applications have been published on Google play store and the number are increasing day by day. If we categorized the Android Applications, the top categories will be:

Operating System Requirement for Android Development

This is one of the beauties of Android that you have a lot choices for Operating Systems. Some of the commonly used operating systems are:
  • Microsoft Windows XP or later version.
  • Mac OS X 10.5.8 or later version with Intel chip.
  • Linux including GNU C Library 2.7 or later.

Development Tools

Second beauty of Android is that all the development tools are free of cost. You just simple go to their website and download them as requirement. Some the important tools you will probably be needed for the Android Development are:
  • Java JDK5 or later version
  • Android SDK
  • Java Runtime Environment (JRE) 6
  • Android Studio
  • Eclipse IDE for Java Developers (optional)
  • Android Development Tools (ADT) Eclipse Plug-in (optional)
This is it for now. In the next tutorial we’ll discuss about the Development Tools qualities and their installation process. If you guys have any questions or suggestions, feel free to comment about them. So Stay tuned and have fun. See you later guys.

USB Communication between Android and Arduino

Hello friends, hope you all are fine and having fun with your lives. In today's post, I am going to share How to do  USB Communication between Android and Arduino. I have designed many projects before in which I have interfaced Android and Arduino and communicated between them but in those projects I have used either Wifi or Bluetooth as a mode for communication. But recently I got a project in which I have to do USB Communication between Android and Arduino, they have this restriction of using USB. So, I have to work on it and I got it working successfully. You should also have a look at How to Install Android Studio. and Getting Started with Android.

So, today I thought to share it with you guys. It isn't much difficult but will need a little patient. When I started working on it I couldn't find any data on it online and I have to work a lot to make it work. So that's why I am sharing it so that others can get it work easily. When I was starting this project then I have a bit confusion that whether to use the USB Host shield of Arduino or to use the usb cable through which we connect Arduino with computer. After a little research I got the idea that simple USB will work fine so I go with it. I have explained this tutorial in detail. First I have done the Arduino side because that one is quite easy and after that I touched the Android side that's a bit complex and you must have the prior knowledge of it if you wanna make it work. So, let's start this project. :)

Circuit designing for Monitoring Incoming Data

  • First of all, I have used the OTG cable for interfacing Android with Arduino, which is shown in below figure:
  • From the above figure, you have clearly got the idea that why I have used this cable, one side of this cable, which is mini usb, will be inserted in the Android mobile while the other side, which is the female usb port, will be plugged with the usb cable of Arduino, as shown below:
  • I have connected the two cables in the above figure, now one end of this cable is gonna inserted in the Android mobile while the other side will be plugged in Arduino and in this way we will do the USB communication between Android and Arduino.
  • But there's some problem, we need some way to display the data in Arduino, which we are getting from Android. So for that reason I have interfaced another Arduino with this Arduino and I am doing serial communication between these two Arduinos.
  • So, in simple words, Android is plugged with first Arduino via USB and the first Arduino is connected with second Arduino via serial port. so, when Android will send the data to first Arduino then first Arduino will send that data to second Arduino, which we can easily see on the Serial Terminal. So here's the circuit diagram of two Arduinos.
  • Now you can have the idea in above figure that the two arduinos are communicated via pin # 2 and 3 which I have made Software Serial, now with the pins they are sending data from first Arduino to second Arduino. Now let's have a look at the coding of both Arduinos.

Programming Code for Arduino

  • As in the above section, we have connected two Arduinos via Serial communication in which we used software serial.
  • Next thing we need to do is to write the code for both of them, so simply copy the below code and upload it in both of your Arduino boards.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3);

void setup()
{
  Serial.begin(9600);
  Serial.println("www.TheEngineeringProjects.com");

  mySerial.begin(9600);
  mySerial.println("www.TheEngineeringProjects.com");
}

void loop() 
{
  if (mySerial.available())
    Serial.println(mySerial.read() - 48);
  if (Serial.available())
    mySerial.println(Serial.read() - 48);
}
  • Above code is quite simple and I am simply sending any data I am receiving on the Serial port to software serial, so when I get the data from Android via USB, I will receive that data and then will forward it to Software Serial on which my second Arduino is connected, which will receive that data and then show it over to Serial Terminal.
  • Now let's have a look at Android side code, which is a bit complicated.

Programming Code for Android

  • You must have the prior knowledge of Android, if you wanna make it work so if you know the basics of Android then you know that there are two main files designed in Android, which are Java file and XML file.
  • So, first of all create a project in Android and place the below code into its XML File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.androidusbhostarduino.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://www.TheEngineeringProjects.com/"
        android:textStyle="bold" />

    <ToggleButton
        android:id="@+id/arduinoled"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textOn="ON"
        android:textOff="OFF" />

</LinearLayout>
  • Next thing we need to do is to add the USB permission in the manifest file, so paste this  code in your manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.theengineeringprojects.dani" >


    <uses-feature android:name="android.hardware.usb.host" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            </intent-filter>

            <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                android:resource="@xml/device_filter" />
        </activity>
    </application>

</manifest>
  • Now the last thing, you need to do is to add the code in java file so copy the below code and paste it in your jave file:
package com.theengineeringprojects.dani;

import java.nio.ByteBuffer;

import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbRequest;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class MainActivity extends ActionBarActivity implements Runnable{

    private static final char CMD_LED_OFF = '1';
    private static final char CMD_LED_ON = '2';

    SeekBar bar;
    ToggleButton buttonLed;

    private UsbManager usbManager;
    private UsbDevice deviceFound;
    private UsbDeviceConnection usbDeviceConnection;
    private UsbInterface usbInterfaceFound = null;
    private UsbEndpoint endpointOut = null;
    private UsbEndpoint endpointIn = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        buttonLed = (ToggleButton)findViewById(R.id.arduinoled);
        buttonLed.setOnCheckedChangeListener(new OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if(isChecked){
                    sendCommand(CMD_LED_ON);
                }else{
                    sendCommand(CMD_LED_OFF);
                }
            }});

        usbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
    }

    @Override
    public void onResume() {
        super.onResume();

        Intent intent = getIntent();
        String action = intent.getAction();

        UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
            setDevice(device);
        } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
            if (deviceFound != null && deviceFound.equals(device)) {
                setDevice(null);
            }
        }
    }

    private void setDevice(UsbDevice device) {
        usbInterfaceFound = null;
        endpointOut = null;
        endpointIn = null;

        for (int i = 0; i < device.getInterfaceCount(); i++) {
            UsbInterface usbif = device.getInterface(i);

            UsbEndpoint tOut = null;
            UsbEndpoint tIn = null;

            int tEndpointCnt = usbif.getEndpointCount();
            if (tEndpointCnt >= 2) {
                for (int j = 0; j < tEndpointCnt; j++) {
                    if (usbif.getEndpoint(j).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                        if (usbif.getEndpoint(j).getDirection() == UsbConstants.USB_DIR_OUT) {
                            tOut = usbif.getEndpoint(j);
                        } else if (usbif.getEndpoint(j).getDirection() == UsbConstants.USB_DIR_IN) {
                            tIn = usbif.getEndpoint(j);
                        }
                    }
                }

                if (tOut != null && tIn != null) {
                    // This interface have both USB_DIR_OUT
                    // and USB_DIR_IN of USB_ENDPOINT_XFER_BULK
                    usbInterfaceFound = usbif;
                    endpointOut = tOut;
                    endpointIn = tIn;
                }
            }

        }

        if (usbInterfaceFound == null) {
            return;
        }

        deviceFound = device;

        if (device != null) {
            UsbDeviceConnection connection =
                    usbManager.openDevice(device);
            if (connection != null &&
                    connection.claimInterface(usbInterfaceFound, true)) {
                usbDeviceConnection = connection;
                Thread thread = new Thread(this);
                thread.start();

            } else {
                usbDeviceConnection = null;
            }
        }
    }

    private void sendCommand(int control) {
        synchronized (this) {

            if (usbDeviceConnection != null) {
                byte[] message = new byte[1];
                message[0] = (byte)control;
                usbDeviceConnection.bulkTransfer(endpointOut,
                        message, message.length, 0);
            }
        }
    }

    @Override
    public void run() {
        ByteBuffer buffer = ByteBuffer.allocate(1);
        UsbRequest request = new UsbRequest();
        request.initialize(usbDeviceConnection, endpointIn);
        while (true) {
            request.queue(buffer, 1);
            if (usbDeviceConnection.requestWait() == request) {
                byte rxCmd = buffer.get(0);
                if(rxCmd!=0){
                    bar.setProgress((int)rxCmd);
                }

                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            } else {
                break;
            }
        }

    }

}
  • Now hit the Enter button on your Android Studio and if everything goes fine then you will get a screen as shown below on your mobile:
  • Here's a simple button, when you press this button, it will show ON and will send the data which you wanna send for example, in my case I am sending character "1" and "2" on button press.

USB Communication Between Android and Arduino

  • Now let's do the usb communication between Android and Arduino, I hope till now you have configured your Android Mobile and both the Arduinos so their overall picture will look something like:
  • You can clearly see in the above figure that the Android Mobile is connected with Arduino, which is further connected with second Arduino and US of Second Arduino is connected with computer, where I am checking the coming data from Android in Serial Terminal.
  • Now when I press the button on Android app, it will send 1 or 2 to Arduino, which is shown in below figure:
  • I have pressed the toggle button on Android many times thats why I have got many 1 and 2 in Serial Terminal.
  • So, that's how I am receving data from Android to Arduino. Now instead of sending 1 and 2, you can send any kind of data from Android to Arduino. I will post more tutorials on it in which I will be sending some data like GPS coordinates from Android to Arduino plus I will also post the 2 way communication i.e. receving data in Android from Arduino.

The Arduino part is easy but the Android part is bit difficult so if you need help then ask in comments and I will help you out. That's all for today, will meet you guys in coming tutorials. Take care !!! :)

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir