Introduction: ArduDroid: a Simple 2-Way Bluetooth-based Android Controller for Arduino
UPDATES:
- Nov 19. 2031: OPINION: The Amazing Synergy Between Arduino & Android.
- October 30, 2013: Andruino is now officially ARDUDROID and will be available on Google Play shortly. This name change to avoid conflict with another app on Google Play.
- August 31, 2013: I have published a guide on how to modify the default settings for the HC-05 module.
- July 10, 2013: Featured on MAKEZINE http://makezine.com
- July 8, 2013: Featured on Hackaday http://goo.gl/Lim0W
- July 4, 2013: Featured on Dangerous Prototypes http://goo.gl/HZatN
REQUIREMENTS
- Breadboard wiring and electronics skills.
- Arduno Uno.
- HC-05 Bluetooth serial module.
INTRODUCTION
ArduDroid (formerly Andruino) is a simple tool to help you control your Arduino (or clone) from your Android phone. It's both an Android app and an Arduino program. ArduDroid has a simple Android user interface to 1) control Arduino's digital and PWM pins 2) send text commands to Arduino 3) and receive data from Arduino over Bluetooth serial using the ever popular and really cheap (less than $10 from ebay) HC-05 Bluetooth over serial module. This app has been tested and designed for the HC-05 Serial Bluetooth module. Other Bluetooth modules may or may not work. Please see comments section for users who tried other Bluetooth modules with this app.
INSTALL FROM GOOGLE PLAY
https://play.google.com/store/apps/details?id=com.techbitar.android.Andruino
ArduDroid should work with other Bluetooth modules with some tweaking but I have only tested it with the HC-05. This is an alpha version that's running fine on my Samsung Galaxy S2 Plus. Please share your experience running ArduDroid on your phone. Also, while I used Arduino Uno in this prototype, feel free to experiment with other models of Arduino. Please share your experience to help me improve this app.
I have published a guide before on building and programming a circuit with the HC-05 Bluetooth module and Arduino but I will briefly describe again in this guide how to wire the circuit using a breadboard and jumper wires.
ArduDroid is an app that evolved during one of my development projects. Special thanks to engineer Jafar Quttaineh for testing the app and for his invaluable input.
Step 1: How to Use ArduDroid
Step 2: ArduDroid Components & Downloads
1) Install ArduDroid from Google Play:
MD5 : BA:80:C2:6A:68:31:8F:21:D6:FC:08:8E:09:D8:F5:CF
SHA1: 04:EA:2E:47:80:71:BE:D9:D2:ED:86:5F:15:1F:1E:9E:77:62:DB:85
HARDWARE
- Android device running version 2.3.3 or higher with Bluetooth.
- Arduino Uno or clone.
- CD4050 level shifter IC or 2K Ohms & 1K Ohms resistors as voltage dividers.
- HC-05 Bluetooth module. Other Bluetooth over serial modules should work with some modifications.
- Breadboard & jumper wires.
- Power source.
Step 3: Wiring the Circuit
I used 2K and 1K ohms resistors in my circuit diagram to drop 5V to 3.3V but you can use different resistor values. Google "voltage divider calculator" and use the myriad calculators to determine what other resistor values work best for you.
Step 4: How to Modify the ArduDroid Companion Program
ArduDroid is an Android app that sends/receives data from Arduino with the help of an Arduino sketch named ardudroid.ino In this sketch, there are four code blocks supporting the four key functions of ArduDroid. You can modify these code blocks to suit your requirements.
The blocks are labeled according to their functions in a comment line at the start of each code block. I inserted a comment "// add your code here" to help you find and place your code, but you can decide how you wish to modify the functional code blocks.
Step 5: Control AnalogWrite Pins
// 3) GET analogWrite DATA FROM ARDUDROID
if (ard_command == CMD_ANALOGWRITE) {
analogWrite( pin_num, pin_value );
// add your code here
return; // Done. return to loop();
}
Step 6: Control DigitalWrite Pins
// 2) GET digitalWrite DATA FROM ARDUDROID
if (ard_command == CMD_DIGITALWRITE){
if (pin_value == PIN_LOW) pin_value = LOW;
else if (pin_value == PIN_HIGH) pin_value = HIGH;
else return; // error in pin value. return.
set_digitalwrite( pin_num, pin_value); // call function to process digital pin#
return; // return from start of loop()
}
// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
switch (pin_num) {
case 13:
pinMode(13, OUTPUT);
digitalWrite(13, pin_value);
// add your code here
break;
. . .
. . .
. . .
case 2: pinMode(2, OUTPUT);
digitalWrite(2, pin_value);
// add your code here
break;
// default:
// if nothing else matches, do the default
// default is optional
} }
I have excluded pin 0 and pin 1 because they are used for Arduino Uno serial communication by default. I might enable those two pins in future releases of the app and leave it up to the user to determine which pins will be used for the Arduino serial communications.
Step 7: Send Text/command From Android to Arduino
// 1) GET TEXT COMMAND FROM ARDUDROID
if (ard_command == CMD_TEXT){
inText =""; //clears variable for new input
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
delay(5);
if (c == END_CMD_CHAR) { // if we the complete string has been read
// add your code here
break;
}
else {
if (c != DIV_CMD_CHAR) {
inText += c;
delay(5);
} } } }
Step 8: Get Text/command From Arduino
// 4) SEND DATA TO ARDUDROID
if (ard_command == CMD_READ_ARDUDROID) {
// char send_to_android[] = "Place your text here." ;
// Serial.println(send_to_android); // Example: Sending text
Serial.print(" Analog 0 = ");
Serial.println(analogRead(A0)); // Example: Read and send Analog pin value to Arduino
return; // Done. return to loop();
}}
Step 9: Things to Consider
There are a quite a few solutions to enable Android-Arduino integration. The more expensive and complex ones involve specialized and costly hardware such as Google's ADK, but by far the cheapest and in my opinion the simplest is the Bluetooth integration using the HC-05 transceiver. I expect WiFi to eventually replace Bluetooth with the help of WiFi Direct (point to point WiFi communications without a router) but his is a couple of years down the road.
As for Bluetooth-based solution for Android to Arduino communication, you can find a few approaches to pick from depending on your project needs and the degree of abstraction you are looking for. Some approaches use a terminal app on the Android such as Blueterm to send and receive raw text data from Arduino over Bluetooth SPP. Others solutions employ a comprehensive library such as Amarino. My ArduDroid sits in the middle.
Notes on support and updates
I will do my best to support ArduDroid and I am hoping that those of you who find this tool useful to share your expertise with other users. Please let me know if you run into any bugs or problems running ArduDroid on your device. Kindly note the device model and OS version as well as other useful info.
Please feel free to leave a comment if you have any technical questions.