Communication between Arduino and Android with usb otg cable

I was thinking about raspberry pi and its features.What is raspberry pi ? Raspberry is a mini computer with a few output ports. When you decided to do very complicated work with an arduino you will see that it is not enough. At this point you will need something bigger like raspberry or beaglebone.

My point is ,these computers provide you more power than arduino. But is it really necessary ? An android phone with a connected arduino uno board is way better option than using a rasberry.Android for calculation and heavy data process stuff, arduino for physical outputs. That simple 🙂 . But some android phones don’t support otg feature you can check out this thread to see whether it is supporting or not. This is how you going to do this kind of connection ,

-Buy an otg cable for Android like this:

Otp cable for android
Otp cable for android

-Download usbSerial library from here :

-Of course an arduino 🙂

Simply, I designed an app to switch a led on and off. I sent “a” value to switch on the led and I sent “b” value to switch off the led. I’m not going to talk about the code.You can check by yourself, it is really simple code piece already. But you need to make these changes to manifest file  inside <activity> tag:


Android Code:

Let’s get to the arduino part,

Put your led to 8,9 pin outputs.8 pin is ground 9 pin is 5V.  Write this code piece to get data from android with arduino :



Install your app to android and install arduino code.And put the light on or off :).

You can download my app :

App Screenshot :

Sample OTG App
Sample OTG App


25 thoughts on “Communication between Arduino and Android with usb otg cable”

  1. HI, couldn’t quite grasp the Android coding for it. could you elaborate or share the source code with comments for further understanding?

    TY 🙂

    1. Hey ,

      Of course :). But first I need to say that , the codes that you’ve seen in this post are a complete source there is nothing more than that.
      I may suggest a way for you , just open an empty android project and copy the code for android and do the same for arduino. Connect the led to 8th(GND) and 9th pins. If it fails than I will share a complete project. I hope this helps. Good luck 🙂

  2. Hey, nice tutorial.. thanks.. but could you teach me how android receive data from arduino and how arduino sends?

  3. Hi, Thank you for sharing your code.
    I coded the Arduino as described and used the apk you provided but with no luck…
    The led won’t turn on..
    I’m using Doogie DG800 valencia with OTG cable.
    Could you please kindly support ?
    Thank you

    1. Well , supporting usb host mode is really important in this example.First you should check that if your device supports host mode.You can do that by plugging in a usb stick.If it supports , than you should check wire connections.

      1. The phone recognize flash disk on key but not the arduino.
        Note that your code worked just fine when I tried with galaxi note 3

  4. Hello , in the (.java) file , in the list of imports the import is wrong.just HOHO
    Could you pleease tell why is it?

  5. A few notes/questions:

    (1) R.layout.main doesn’t resolved, so I’ve changed to R.layout.activity_main (the name of my xml) and it worked (I mean, it compiled).
    (2) and doesn’t resolved as well, and I’m note sure how to fix this. Can you please help me out?
    (3) Maybe for those reasons, the buttons doesn’t load in the application, so it only shows the Hello Word.


  6. Very nice explanation. I have a question regarding reading the data. I would like to get the serial data from the arduino on to the textview of my android. How can i do that? I am not able to use the read() method because it only provides the num of bytes. Any help will be greatly appreciated.

  7. Hi, can anyone help me by telling me how to add the libraries. I have already tried the procedure posted at github link but libraries are not being added please help.

  8. Thank you for this post, very helpfull to me!
    Can I ask you what is the “usbSerial” library for?
    Can I use only standard Android classes to perform simple reads such as button press on the arduino and write such as turn led on… Thank you again! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *