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

2

6

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?

Acquaint answered 23/3, 2012 at 0:19 Comment(0)
W
3

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();
Whole answered 23/3, 2012 at 0:28 Comment(4)
Well i actually sorted the Wifi connection to arduino. I can make the LED turn on and off with my phone's browser. I just add a string at the end of the ip address in my phone's browser and in the arduino i tell what to do when that string is received. So this is pretty much ok. I just don't understand how to use this concept (or maybe a different suitable concept) in my Android app.Acquaint
if all information is sent over http then simply load the desired URL from within you appWhole
erm.. kind of figured it out but there is one problem. I press the button in my app and the led lights on but a webpage opens, since i send the signal over http. I need to click the back button to go back to my app. Is there anyway i can prevent the opening of the webpage but just sending the information over the url?Acquaint
Bit of relief now.. When i press the button, the webpage doesn't open. The command is being sent but when i press another button, it doesn't respond. I think the previous http command is not being over-written. Is there any way to stop the previous command when a new command is being sent?Acquaint
V
1

To avoid re-inventing the wheel, take a look at www.pfod.com.au, which has a general purpose Android app to control micro devices via bluetooth or wifi with optional 128 bit security. Control via SMS is under development. What is displayed on your mobile is completely determined by the micro code. No Android coding required at all.

Lots of example projects and a free pfodDesigner app which lets you design your own menus and then generates the Arduino code for you that will display the menu on the pfodApp. The one pfodApp handles every menu you design. No Android coding required.

pfodApp will also capture and plot data send from your micro in CSV format. Again the plots are controlled completely by the code in your micro. No changes needed in the pfodApp.

Vambrace answered 9/12, 2014 at 22:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.