How to create an Android app to control Arduino over Wi-Fi?

Anish picture Anish · Mar 23, 2012 · Viewed 18.2k times · Source

I have an Arduino Mega board. I've connected the WiFly module to it and established connection with my Android phone. Now I want to make a simple app for my Android, where I press a button and the LED on the Arduino board turns on.

In fact, I've already made an app (in Eclipse) with a button, and if I press it, I get a toast message saying the button is pressed. Now, how do I implement the Wi-Fi functionality to it and enable it to light up the Arduino's LED?

Answer

slayton picture slayton · Mar 23, 2012

It really depends on the types of inputs the Arduino board is expecting. What do the Arduino documentation say about communication over a Wi-Fi connection? I imagine reading those would be a good place to start.

It looks like you communicate with the Arduino via HTTP. This makes things really easy. One quick way you might do this (I haven't tested this) is to do something like the following:

URL url = new URL(arduinoCommandURl);
InputStream is = new InputStreamReader(url.openStream(), "UTF-8"));
is.read();