Control arduino with android through usb

Control arduino with android through usb
​Android Phone which supports USB Host Mode (i.e OTG Support) - Most devices running Android 3.1+ support this. Check if your phone does using the USB Host Diagnostics App from the Play Store.
Arduino - Any version will do. I will be using an Uno R3 . 
Arduino USB Cable
USB OTG Cable - You will need this to connect the USB cable of the Arduino to the micro-USB port of the Smartphone. It costs about $5 on Amazon.
Android Studio - You will need to have this installed and setup. It is pretty easy to do that.  Android Studio makes app development easier with its predictions and code generation. It's one of the best IDEs out there. You could also follow this article to set up Android Studio on your computer.


<a href="">Download Android Source Code</a>
  1. Arduino UNO
#define SIDE_PIN 100 #define SIDE_VALUE 101 int side; #define OUTPUT_DIGITAL 100 #define OUTPUT_ANALOG 101 int output; int pin; int value; char chars[10]; int index; void setup() { Serial.begin(9600); pinMode(3, OUTPUT); } void loop() { //analogWrite(A0, 171); return; if (Serial.available() > 0) { char c =; if (c == 'd' || c == 'a') { output = c=='d'?OUTPUT_DIGITAL:OUTPUT_ANALOG; side = SIDE_PIN; index = 0; } else if (c == ',') { String inString = String(chars); pin = inString.toInt(); side = SIDE_VALUE; index = 0; } else if (c == ';') { String inString = String(chars); value = inString.toInt(); Serial.print(pin); Serial.print("="); Serial.print(value); Serial.println(); if (output=='d') { pinMode(pin, OUTPUT); digitalWrite(pin, value); } else { //analogWrite(3, value); } //delay(1000); } else { chars[index] = c; chars[index+1] = '\0'; index++; } } }