Arduino Android Serial Communication using 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) Power Switching
2) Weather Station
3) Survilence System
4) Iot

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 .

7 Segment Controlling with Arduino Android Usb Otg App

7 segments are connected to the digital pins of arduino .
Pin Configuration is :
Segment ‘a’ is connected to D2 of arduino , Segment ‘b’ is connected to D3 , Segment ‘c’ is connected to D3 of arduino , Segment ‘d’ is connected to D4 ,
Segment ‘e’ is connected to D4 of arduino , Segment ‘f’ is connected to D11 ,
Segment ‘g’ is connected to D10 of arduino i.e
g=10;
f=11;
a=2;
b=3;
e=4;
d=5;
c=6;

7 Segment Arduino Code  :

int a,b,c,d,e,f,g;
char x='0' ;
void setup() {
  // put your setup code here, to run once:
  g=10;
  f=11;
  a=2;
  b=3;
  e=4;
  d=5;
  c=6;
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);

digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()){
    x=Serial.read();
    if(x=='8'){
      digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
    }else if (x=='7'){
      // 7
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
    }else if (x=='1'){
      
// 1
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
    }else if (x=='2'){
      // 2 
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
    }else if (x=='0'){
      digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
    }else if (x=='3'){
      digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
    }else if (x=='4'){
      digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
    }else if (x=='5'){
      digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
    }else if (x=='6'){
      digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
    }else if ('9'){
      digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
    }  
  }
}

You May Also Like

About the Author: quzal

Leave a Reply

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