Control Arduino from Android with USB OTG Cable

Arduino microcontroller is easy to use than pic or any other microcontroller. One of the reason is that it uses C language for compilation and most of the libraries are already built in the compiler.

Using Arduino with Android has many Application some them are mention below
1) Android Controlled CAR
2) Arduino Weather Station
3) Home Automation System
4) Line following Robot

Before this Android App ,people use bluetooth module to control arduino from mobile phone .Using Usb Otg Cable with arduino has several advantages over bluetooth.

Download App From Playtore : 
App Name : Arduino Android OTG USB
https://play.google.com/store/apps/details?id=plutoapps.arduinoandroidusb

Advantages of USB OTG Cable over Bluetooth :
• OTG Cable is very cheap less than a dollar
• It consumes less power
• Easy to connect
• It is relatively fast than Bluetooth

Most Basic Algorithm that can be used to control robot from mobile is that send some character from mobile let say ‘1’ to arduino then on arduino programming compare the received bit with ‘1’ if it is ‘1’ then perform some action .In this way send different character to arduino and compare with the corresponding character on arduino side .One can use if else or switch and case for comparing .
 Algorithm is illustrated in the code below

void setup() {
 // put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop() {
 // put your main code here, to run repeatedly:
if(Serial.available()){ // data is coming ?
 x=Serial.read(); // read data
 if(x=='1'){ // if sent char is 1
 digitalWrite(13,HIGH); // turn on led at pin 13
 }else digitalWrite(13,LOW); //turn off
}
}

Controlling LED’s from Mobile using USB Cable 

Circuit  is shown in the picture

Arduino Code :

char x;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);   // set Led 1 as output
pinMode(12,OUTPUT);   // set Led 2 as output
pinMode(11,OUTPUT);   // set Led 3 as output
Serial.begin(9600);   // begin connection with android phone
} 

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){   // data available ?
x=Serial.read();
if(x=='1'){               
digitalWrite(13,HIGH);   // if received char is 1 then turn on Led 1
}
else if (x=='2'){          
digitalWrite(12,HIGH);   // if received char is 2 then turn on Led 2
}else if (x=='3'){
digitalWrite(11,HIGH);   // if received char is 3 then turn on Led 3
}else if(x=='a'){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);  // if char is a then turn on all the Leds
digitalWrite(11,HIGH);
}else{
digitalWrite(13,LOW);   // for anyother value of char turn of all Leds
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}

}
}

You May Also Like

About the Author: quzal

Leave a Reply

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