element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum control arduino with android app
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 8 replies
  • Answers 4 answers
  • Subscribers 393 subscribers
  • Views 1641 views
  • Users 0 members are here
Related

control arduino with android app

Former Member
Former Member over 9 years ago

Hey guys.

I'm new here and new to using an Arduino.

Basically all I'm looking to do is to be able to control the pin out puts of my arduino using my android phone using the OTG cable (serial usb).

I've modified a sketch that i found online and i believe it will work, however, i do not know how to code an app to do what i want it to do. I have tried MIT App inventor but it does not seem to allow communication

over a serial link, only bluetooth and i am unsure of how to use android studio or eclipse.

My project is a simple 4 channel relay. If anyone can help or knows of an app which already exist, i would be greatful.

 

Thank you.

 

Here is the sketch that I'm using :

 

int ledpin[6] = {2,4,6,8,10,12};

int ledstate[] = {3,5,7,9,11,13};

String rx="";

byte b = 0;

char c = 'a';

boolean rx_done = false;

 

void setup(){

  pinMode(2,OUTPUT);

  pinMode(4,OUTPUT);

  pinMode(6,OUTPUT);

  pinMode(8,OUTPUT);

  pinMode(10,OUTPUT);

  pinMode(12,OUTPUT);

 

  pinMode(3,INPUT);

  pinMode(5,INPUT);

  pinMode(7,INPUT);

  pinMode(9,INPUT);

  pinMode(11,INPUT);

  pinMode(13,INPUT);

 

  Serial.begin(9600);

}

 

void loop(){

 

  while(Serial.available()){

    char c = (char) Serial.read();

    rx += c;

    delay(2);

  }

 

  if(rx != ""){

    int pin_number = rx.charAt(0)-48;

    //int pin_state = rx.charAt(1)-48;

    if(pin_number > 5){

      //Serial.println("false");

    }

    else{

      int new_state;

      if(digitalRead(ledpin[pin_number]) == HIGH){

        new_state = 0;

        digitalWrite(ledpin[pin_number],new_state);

      } else {

        new_state = 1;

        digitalWrite(ledpin[pin_number],new_state);

      }

     

      String s = rx+new_state;

      Serial.print(s);

    }

   

    rx ="";

  }

 

  delay(1000);

}

  • Sign in to reply
  • Cancel

Top Replies

  • dougw
    dougw over 9 years ago +2 suggested
    If you just want to control relays from android using USB, you could check out EECI. They make the relay card and android app... USB Relay - USB Analog to Digital with Data Logger - RS-232, RS-485 Relay…
  • Former Member
    Former Member over 9 years ago in reply to balearicdynamics +1
    Thank you very much
  • balearicdynamics
    0 balearicdynamics over 9 years ago

    Hello potts,

     

    you should just google "Control arduino with android" and an entire world will open in front of your eyes. It is not needed to develop an app as there are many well working open source applications documented just to program Arduino from your device.

     

    Instead, if you need to interact via Android USB to an arduino, the real problem is not the app but it is to know if your Android device support or not the USB Host, that is just the opposite of the OTG.

     

    With the "normal" USB connection you can connect a PC to a Android smartphone so the Android device is the "client". The PC send commands and applications that you develop with some IDE like Android Studio or Eclipse.

     

    By the opposite side instead, you need that the smartphone will become the Host, controlling Arduino as a client connected via USB. This feature is not obviously present in all the device and you should investigate if your model does support it or not.

     

    The most reliable approach, that should work 100% is to connect Android via Bluetooth, but to do this you need to make some changes to your Arduino USB connection with a USB to Bluetooth converter.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • neilk
    0 neilk over 9 years ago

    Hi ashman  Enrico is correct: the most reliable approach is to use Bluetooth between your Android device and your Arduino.

     

    Bluetooth adapters are readily and cheaply available - HC-06 is very easy to use.

     

    Here is a very simple example, using App Inventor:

     

    https://www.element14.com/community/people/neilk/blog/2014/07/14/mit-app-inventor-creating-android-app-to-control-arduino-via-bluetooth

     

    Hope this helps

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • gihu
    0 gihu over 9 years ago

    Hi,

     

    Maybe this gives you some ideas:

    https://github.com/mik3y/usb-serial-for-android

    But as balearicdynamics says, you have to check your Android device allows USB otg. There are app that let you know if itpossible or not, like USB host check.

    Also you can if your device can detect the Arduino.

    Other apps, like 'USB Host View' or 'USB Detective' let you know more info about the USB devices connected to your Android device.

     

    Android API allows you to communicate over USB, without OS drivers. I succed on communicate an android device over USB to an CP2130, so probably will succed.

    Using CP2130EK, an USB to SPI brigde, in Android (previous)

     

    Which arduino are you using? A 32u4 based one?

     

    PS. As neilk and balearicdynamics suggest bluetooth should be quite simple, connecting the bluetooth module directly to a serial connection to the arduino (not over USB)

     

    Hope that helps,

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 9 years ago

    Ash please contact me by email. I have a USB monitor application to check the attached devices, the USB features and also a logging features in HTML format. I can send it to you. It somewhere on the market .ru or somewhere else but I don't remember so it is better if I send you directly the app.

     

    Enrico

     

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dougw
    0 dougw over 9 years ago

    If you just want to control relays from android using USB, you could check out EECI.

    They make the relay card and android app...

    USB Relay - USB Analog to Digital with Data Logger - RS-232, RS-485 Relay Interface

    https://eeci.com/android2.htm

    https://www.eeci.com/android2n.htm

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to balearicdynamics

    Thank you very much my email is, apotts1310@gmail.com

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 9 years ago in reply to Former Member

    Fine! Tomorrow I will provide you a copy.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to balearicdynamics

    Thank you very much

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube