There are two sides to analyze in this situation: the Arduino side and the Android side.
Arduino
On the Arduino side, you have several options, but the most common are:
Use the class Serial
, to send and receive data via terminals RX
and TX
of the plate. Then you couple an adapter Bluetooth to these terminals, and he will be in charge of making the transmission/ reception (there are several models, brands and sizes of Bluetooth adapters for Arduino, it remains to choose one of them).
If you own one Wifi Shield, then you can connect the Shield to the Arduino, and use the class WiFi
to communicate via HTTP, or TCP or UDP (depending on your need). This solution is usually a little more expensive than the Bluetooth, in terms of cost $. However, there are already several examples that accompany the Arduino IDE to assist in getting started (menu File > Examples > WiFi
).
Android
On the Android side, depends on which of the two solutions you chose on the Arduino side.
Bluetooth
If you have chosen Bluetooth, your solution will be to pair the Arduino on your Android device, and use the services of the classes Bluetoothadapter and Bluetoothsocket to initiate a communication using SPP (Serial Port Profile).
There’s a pretty complete example of how to do this on that website.
Wifi - Socket
If you have chosen to use Wifi Shield on the Arduino side, then it remains for you to decide which mode of communication you will use.
You can choose to simply send and receive raw data through a socket TCP, using the class Socket android. There are several tutorials teaching how to use sockets, here’s an interesting.
Wifi - HTTP
Still, you can choose to send the data via the HTTP protocol.
With this type of solution you don’t even need to effectively create an Android application, because communication can be done through a common browser, any operating system. There is a great example, very simple, for this along with the Arduino IDE: File > Examples > WiFi > SimpleWebServerWiFi
.
Now, if you really want to create an Android application and communicate via HTTP, you can use several classes, among them Androidhttpclient
There’s a small example of how to do that in this other OS question: How do I use the Simple HTTP client in Android?
As for my personal experiences, I usually make the communication in that order (order of preference in my day-to-day life):
Bluetooth: The adapter Bluetooth is cheaper, and you don’t need a monitor, or a display, to find out which IP was obtained by Wifi Shield Arduino, every time he connects to Wifi
Wifi Shield via socket: Send and receive raw data, through a TCP connection between the two, usually speed up the response of Arduino, because he does not have to worry about the HTTP protocol, and all extra data that is sent because of the protocol
Wifi Shield via HTTP: Although it causes more data to travel on both sides, and the response is not always as fast on the Arduino side, by using this solution you can connect the Arduino not only to one device, but to several devices, including without need to create an Android application as this communication can be done through a conventional browser of any operating system
@DBX8, it is recommended to wait the 5 minutes in which the user has the right to modify the post without it being in the history (grace period, in English)
– brasofilo