Control Arduino using an Android App

Hi,

I'd like to connect Arduino to an Android App I'm creating.

The purpose is to control a machine using an Android Tablet acting as its user interface.

Is there any Java SDK that goes hand in hand with Android Studio?

What's the best approach? Are there things I need to know before starting?

How do I pick an Arduino Board to best suit my project's needs? I'd be needing internet access, and the ability to move a crane and shelves.

How do you propose to communicate between the Android device and the Arduino?

If this question

Is there any Java SDK that goes hand in hand with Android Studio?

is about "how to program an Android device" then you are asking in the wrong place. This Forum is about programming Arduinos. Some people use MIT App Inventor to program Android devices.

On the other hand if you are asking if you can program an Arduino using a JavaSDK and Android Studio then the answer is a simple "No".

How do I pick an Arduino Board to best suit my project's needs? I'd be needing internet access, and the ability to move a crane and shelves.

You need to provide a lot more detail about the crane and shelves. An Arduino can't move anything. It can only control things - for example a motor driver.

As a general comment I suggest that you put your grand plan on hold for a little while, get yourself an Arduino Uno and learn the basics. Then you will have much better background knowledge from which to figure out the components needed for your project.

...R

Thanks for the response.

How do you propose to communicate between the Android device and the Arduino?

If I understand correctly I can simply connect them via a USB.

As for the actual reading and writing from/to Arduino in the Android app - that's exactly what I'm trying to figure out.

This is what I meant -

On the other hand if you are asking if you can program an Arduino using a JavaSDK and Android Studio then the answer is a simple "No".

What would be the best way then to communicate with Arduino using an Android app?

You need to provide a lot more detail about the crane and shelves.

You're right, this is something I can't do yet.

An Arduino can't move anything. It can only control things - for example a motor driver.

Yes I understand that.

As a general comment I suggest that you put your grand plan on hold for a little while, get yourself an Arduino Uno and learn the basics. Then you will have much better background knowledge from which to figure out the components needed for your project.

I definitely intend to do that, I'd just like to make sure I'm doing things in the right context and that they'll eventually lead me to where I want.
I'm trying to get a good grasp of my project's requirements and feasibility before diving in.

Okay interesting, I see I can communicate by opening a bluetooth socket:

It looks like I have somewhere to start now.

royibernthal:
If I understand correctly I can simply connect them via a USB.

Most Arduinos are USB client only, a few (Due, Yun?) should also be able to offer USB host mode.

Likewise most Android devices are USB client only.

To communicate over USB one of them must be a USB host. A typical desktop or laptop computer acts as USB host only; typical peripherals such as mobile phones, mice, printers, USB drives and Arduinos act as client only.

I find Reply #2 very confusing - almost contradictory in places. For example

f I understand correctly I can simply connect them via a USB.

[....]

What would be the best way then to communicate with Arduino using an Android app?

The question does not seem logical in the context of the statement

and

As for the actual reading and writing from/to Arduino in the Android app - that's exactly what I'm trying to figure out.

This is what I meant -

On the other hand if you are asking if you can program an Arduino using a JavaSDK and Android Studio then the answer is a simple "No".

Reading and writing to the Arduino is a very different concept than programming the Arduino.

As @wvmarie has said I don't think you can connect an Arduino to an Android device - certainly not to my Android phone. You could use Bluetooth for communication with a Bluetooth module attached to the Arduino. Or, if you are already familiar with web programming you could use WiFi with an ESP8266 WiFi module attached to the Arduino. However if you are not familiar with web programming I reckon you will find Bluetooth very much easier.

...R

Okay, let's separate this into 2 different points:

  1. The medium in which the data is transferred - e.g. USB, Bluetooth.

If I understand correctly I can simply connect them via a USB.

  1. The actual API used to transfer that data (e.g. a Bluetooth java library).

What would be the best way then to communicate with Arduino using an Android app?

I should've been clearer, I hope we're on the same page now.

Reading and writing to the Arduino is a very different concept than programming the Arduino.

Could you help me understand the difference between reading and writing to the Arduino vs programming the Arduino?

As @wvmarie has said I don't think you can connect an Arduino to an Android device - certainly not to my Android phone. You could use Bluetooth for communication with a Bluetooth module attached to the Arduino. Or, if you are already familiar with web programming you could use WiFi with an ESP8266 WiFi module attached to the Arduino. However if you are not familiar with web programming I reckon you will find Bluetooth very much easier.

I happen to be a web developer. Are there any examples of such an implementation? What would be the pros and cons of that approach versus Bluetooth?

royibernthal:
Could you help me understand the difference between reading and writing to the Arduino vs programming the Arduino?

Let's start here, because then the earlier questions might go away.

When you take it out of the box an Arduino can do nothing. It may contain a program that blinks an LED but it won't have any user program that can send or receive data from anything.

In order to get the Arduino to do anything you need to write a suitable program using the Arduino IDE and the C++ programming language. There are lots of example programs included with the Arduino IDE. To illustrate with a trivial incomplete program snippet the following will send "hello world" once per second.

void loop() {
   Serial.println("Hello World");
   delay(1000);
}

If you want to see a more extensive example have a look at Planning and Implementing a Program

You write the Arduino program code using the editor in the Arduino IDE and there is a "upload" button that sends the program to the Arduino (assuming it is connected to the PC).

As far as the Arduino is concerned Bluetooth is essentially serial-by-wireless.

If you are familiar with web programming then you will probably understand all about web servers and browsers / clients and creating a program in which an Arduino acts either as a small server or a small client should be straightforward. Of course you will need a WiFi module. Whether the extra effort is justified by the project you want to create is a matter for you to decide.

I don't know if there are WiFi examples in the Arduino IDE but there are probably some examples that work with the Arduino Ethernet shield which should give you the flavour of the process. Also, browse through the Resources tab at the top of this page.

And Googling arduino your item of interest site:arduino.cc usually brings up lots of resutls

...R

Thank you for the detailed explanation :slight_smile:

Also, FWIW, there is an Android version of the Arduino IDE on Google Play - it's called ArduinoDroid. I have it on my Samsung tablet. Since typing on the tablet is a PITA, I don't use it for writing code, but I do use it occasionally to upload code to an Arduino that is difficult to bring to my PC. (I really should replace that Arduino with an ESP8266..for the Over-The-Air programming capability...but that's another story.) Presumably the ArduinoDroid's serial monitor can also be used to communicate with (and control) an Arduino, tho' a stand-alone BT or other wireless app may allow a better user interface and untethered comms.

Did you know that you can interface a PS2 keyboard/mouse to regular Arduino? Would it be hip to DIY a full size BT KB for the tablet? Yeah I know, it'd take a good bit of work at the Arduino end to make it work exactly as a BT KB.

I have written a few (lame) Android apps using MIT App Inventor 2 web based application.

Quick and dirty:

  • Arduino w/ HC-05 bluetooth module
  • ensure you have this set up correctly by following tutorials (everywhere)
  • MIT App Inventor 2
  • create the application you want (that does whatever it is you are after)

Once you load this app to your phone.. it will be able to have access to the hardware/data on your phone that you coded it for.

Your Mobile app can scan/search and connect (pair) with this HC-05 bluetooth module that is connected to your Arduino.

From that point.. its more or less.. simple serial communication back and forth..

What you do with this incoming serial data (on either side) is up to you.. and depends on the parsing routine you write.

ie:

  • a '1' is sent form phone to Arduino
  • Arduino receives this '1'.. and needs to do 'something' once that action/command (data packet) is received.