Introduction: ArduDroid: a Simple 2-Way Bluetooth-based Android Controller for Arduino

UPDATES:

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

You can use ArduDroid to send commands to Arduino to control a relay to turn electric gadgets on/off, control a robot servo, increase/decrease speed of a motor and reverse direction, dim a light, speed up a fan, and so on.  Furthermore, you can read Arduino pins and sensors then transmit the data back to your android phone.

Step 2: ArduDroid Components & Downloads


1) Install ArduDroid from Google Play: 



 
For previous version downlowded from my website, this is the certificate fingerprints:
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
 
2) Download the Arduino program: ardudroid.ino (requires Arduino IDE 1.05 or later)

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

Please note that while my actual prototype as shown in the video and photo uses the CD4050 IC to level shift from 5V to 3.3V, in the wiring diagram I am using a voltage divider because I believe it will be simpler for most people to acquire the resistors than the IC.  You only need to drop the Arduino's TX voltage to 3.3V to match the RX of the HC-05. The Arduino's RX pin can handle the HC-05 incoming TX signal which is 3.3V.

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

On the Arduino side I have included a skeletal program (ardudroid.ino) that intercepts and processes the ArduDroid commands issued from your Android device.  You can update the Arduino code according to your project needs.

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

This is the code block that receives the PWM value from 0 to 255 that you send from Android to control the PWM designated Arduino Uno pins 11,9,10,5,4,3. You can add code to control a motor for a robot or fan, for example, to speed it up or slow it down. Or you can send a command to dim a light.

  // 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

This is the code block that receives from Android the pin number and the ON/OFF (HIGH/LOW) value to toggle the corresponding pin.  You can turn a relay on /off to switch an electrical device.  Please note that this code block calls a function set_digitalwrite() which has a Switch/Case structure to give you room to write code to act on each pin separately.

// 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

This is the code block that handles the text you type in the field next to Send Data button.  For example, you can send a password to activate/login into a system. Or you can send text to an LCD connected to Arduino to display something.

// 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

This code block sends anything you want from Arduino to your Android.  In my sample code below, I send the value of analog pin 0 whenever I press the Get Data button. Since analog pin is not connected to anything in the demo video, I was getting ambient noise values.  Please note that there is no error detection/correction in my code block. If accuracy is critical to your app, make sure you add error detection such as visual markers to enclose the data being sent or a checksum.

// 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

Alternatives to ArduDroid

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.

Comments

author
Yasunari GEN (author)2017-07-21

Dear.

I would like to customize the keys and add few things to the app.

Can you please share the source code for the app?

email :tabu512@yahoo.co.jp

author
Xatabr (author)2017-04-15

Hi! I would like to customize the keys and add few things to the app. Can you please share the source code for the app? email id: anatolii_ice@list.ru

author
mdogu (author)2017-04-06

Hello, really good work! I am curious about how these work, could you please send me the source code via my email,
roboticsatkal@gmail.com
Thanks!

author
BhimashankarS (author)2017-03-26

Could you please send me the source code of the android app my email Id is bhimashankarspatil@gmail.com... thnkz so much...

author
MushafA (author)2017-02-02

Hi, great job! can I get the source code for the Android App. I need to customize buttons and layout for my purposes.

Thank you in advance, my email is: munawar.muteen@gmail.com

author
venkycool (author)2017-01-05

Hi, it is a great project. I am student and I am planning to use this for my project , Can you please send me the source code so I could customize it ? my emali-id is koppisettiprajnesh@gmail.com

author
martins999 (author)2016-11-01

Hi, thanks for the great project! would it be possible to port it to Digispark? I only need to control a single PWM channel so an Arduino Uno would be a bit overkill.

author
john_choi (author)2016-10-26

Hi, great job! can I get the source code for the Android App. I need to customize buttons and layout for my purposes.

Thank you in advance, my email is: choijw1024@empas.com!

author
Srivats7 (author)2016-10-15

Hi! I would like to customize the keys and add few things to the app. Can you please share the source code for the app? email id: stavirs@gmail.com

author
MikhailaE (author)2016-07-14

hi! i'm a college student and i'm planning on using this for my project can you please send me the source code so i could customize it? thanks here is my email mikhaila1597@gmail.com

author
GianlucaG12 (author)2016-07-06

Hi, great job! can I get the source code for the Android App, me too? I need to customize buttons and layout for my purposes.

Thank you in advance, my email is: gianluca.genga@gmail.com!

author
alexcst11 (author)2016-06-22

Hi! I am new in Arduino and programming. Anyone can help me, please?
At 6-th Step, what i need to write where is // add your code here, to turn ON/OFF a LED?

I tried to wrote: if (pin_value=HIGH) { digitalWrite (13, HIGH); } and didn't works, i wrote just DigitalWrite (13, HIGH); and didn;t work also.


// 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;

author
AndrewC230 (author)2016-06-21

thank you, Techbitar for making this available to the general public. It's a wonderful app, and I appreciate the ready to go code you included. I've used this successfully on an autonomous boat to get it started on a given program.

Andrew

author
himu2511 (author)2016-06-05

Ardudroid App works very smoothly. And this guide helped me a lot. I am doing a project using Ardudroid. But I can't understand the sketch of Ardudroid without the source code of the App. Could you please send me the source code of the Ardudroid App ?

I will be indebted to you. Thank you very much. My mail address: himu2511@gmail.com

author
roosbot (author)2016-05-26

Hey, great App and great writeup. This has really helped me develop my bluetooth project, can I get the source code for the Android App? I am developing an app in Visual Studio and running into some issues getting the bluetooth communication to work, if you have any advice I'd appreciate it
Thanks

jsroos89@gmail.com

author
s3382137 (author)2016-05-23

This guide is definitely what I was looking for. I'm just wondering if it's possible for you to send me the Android source code.

Thank you very much. My email address is s3382137@student.rmit.edu.au

author
HussM (author)2016-05-11

can you please send me source code for this project.my mail id is hussmarsidi@gmail.com

author
JhonJS (author)2016-05-01

Hello, I really like your project. Is it possible to have the source code of your android app. It would be so nice to work with it. My contact is js560797@gmail.com

Many thanks for your time!

author
claw8 (author)2016-04-24

HC-06 pairs fine. I can connect to it with another application (that has a connect button). However my Galaxy S5 sport has no menu button that allows me to connect to HC-06 from ArdruDroid. I am so close, I cannot give up ...... Any suggestions?

author
claw8 (author)claw82016-04-25

I found the answer. Press and hold the left bottom button (application list button?) and the menu (3 dot) button activates.

author
ArunK187 (author)2016-04-10

I have connected/wired the circuit perfectly well, and if I send the commands from my Laptop, the 'digital_write' or 'analog_write' commands work very well.But I find no actions when trying thru paired HC05 and ArduDroid app. How can I test BT module ?

author
vsandhu (author)2016-03-20

hc05 is blinking once after 2 sec or so but the project is not working.... help me out

author

check your transmitting and receiving section on both arduno uno bord and bluetooth module..and also while uploading the program bluethooth module pin should kept out and then enjoyyy......

author
vsandhu (author)2016-03-20

it is not working, i have connected everything but the led wont glow

author
marciokoko (author)2016-03-18

Hi, could I get the ArduDroid app source code for tweaking? Thanks. quique123@yahoo.com

author
CraigA29 (author)2016-03-07

Hi, i have installed ArduDroid on my android device phone with Android version 4.4.2

On opening ArduDroid app, there is no action menu, therefore I cannot connect with the BT module through ArduDroid..

I tried another app, Arduino Bluetooth to verify BT connection capability, connection works, blink light goes steady.

I deleted and reloaded ArduDroid app, but still no Action Menu, can somebody help?

Cheers,

Craig A

author
fjarabaa (author)2016-02-26

Hi, a very good project. Am wondering if I could get the android source code.

fjaraba@gmail.com

Thanks you very much!

author
GregorS10 (author)2016-02-20

Hey, it would be very nice to have a look on your android code. I actually have the problem, that I dont understand how you managed it to send PWM data and normal digitalWrite (high/low) data from the phone, so that the arduino knows, what kind of data the android device sends.

My mail adress is gregsto1998@gmail.com

It would be very nice if you can help me with this problem.

author
navyathanavya (author)2016-02-17

can you please send me source code for this project.my mail id is navyatha.nellore@gmail.com

author
navyathanavya (author)2016-02-17

can you please send me source code for this project.my mail id is navyatha.nellore@gmail.com

author
navyathanavya (author)2016-02-17

can yoy please provide source code for this project

author
viswa.nathan.5473 (author)2016-02-04

hi really a great project , i have only developed basic android apps bluetooth apps are beyond my knowledge. can you please mail the source code.

my email id : viswa0894@gmail.com

author
ezio719 (author)2016-01-30

Can you elaborate the code block for digitalwrite pins

author
AdamA74 (author)2016-01-19

Hi, a very good project. Am wondering if I could get the android source code.

awai_hazard@hotmail.com

Thanks a bunch!

author
misshoran (author)2016-01-12

Hi TechBitar,

Excellent project, no problem on Mega 2560 but so far not working on Yun.

Does anyone know of any reason for this or maybe I am doing

author
TháiT2 (author)2016-01-11

Please send me the android source file

3t.khatvong2012@gmail.com

Thanks you

author
rekcah2222 (author)2016-01-10

Please send me the android source file

rekcah2222@yahoo.it

Thanks you

author
XebasT (author)2016-01-10

Please can you send me the android source file kutxipato@gmail.com Thanks

author
AnthonyL69 (author)2016-01-06

can pls made an in-depth guide of the Arduino skeleton and how to add some code,

I'm new to this , XD

author
MerylA1 (author)2016-01-03

Please send me the android source file aldovermeryl@gmail.com Thanks

author
VõD4 (author)2015-12-30

Please send me the android source file (aia file): vietbrave2010@gmail.com. Thank you.

author
kiruba joju (author)2015-12-28

sir please send me the source code for android app

kirubarvb@gmail.com

Thamk you

author
coffs (author)2015-12-14

Please send me the source file (aia file): rsatchel@asu.edu

author
keyzac (author)2015-12-06

please send me source code for android app.

my email : softkeyzac@gmail.com

It is important for a project.

author
priatnaz (author)2015-08-30

please send me source code for android app.

my email : priatnajumsa@gmail.com

thank you

author

please give me the code anna.coolprincess@gmail.com

author
feribacsika (author)2015-12-03

Hi, Nice project!. Can I have the source code please? fjmobileservice@gmailcom

It would be awesome to personalize the buttons and menus.

Thank you!

author
shadowbandit (author)2015-11-30

May I have a copy of the code?
If so, please send it to my email: snattrass28@gmail.com

Thanks.

author
walaanasser (author)2015-11-18

could you please send me the source code of the android app at

walaanaser.wn@gmail.com

author
ngocdangrby (author)2015-11-13

Could you please send me the source code of the android app at ngocdangaaa15@gmail.com .