To use the project with a USB connection on your Android device, make sure your Android device is running at least Android version 3.1 and supports USB host mode. You will also need a USB on-the-go or OTG cable to connect to your Arduino. The USB OTG cable tells the Android device to enter USB host mode and supply power to the Arduino. A quick check to see if you device supports USB host mode would be to connect a USB keyboard to the USB OTG cable and connect it to your Android device. If you can use the keyboard on your device, chances are good it will work with USB host mode to communicate to an Arduino.

To load the software on your Android device you will need to enable loading applications from unknown sources by following the instructions at this link.

Download the SmartShaker.apk file to your Android device from the following link:
Your device should prompt you if you want to install the application. Agree to install the application and it will be loaded on your Android device.

With power applied to your project hardware, connect the USB OTG cable to a USB mini or micro cable which is connected to your Arduino. Run the Smart Shaker application (it will have a green star as an icon) and follow the instructions to make a drink. Watch the second half of the video from the overview for an example of using the project with a USB connection.

Note: As mentioned in the previous step, if you also have a Bluefruit EZ-link attached to your hardware make sure to disconnect it before using the USB connection. Also on an Arduino Nano it might be necessary to disconnect the Vin power line to the Arduino so it is powered from USB instead of the power supply.

Android USB Development

If you're interested in building your own Android applications which communicate with Arduno devices over the USB connection you can look at the source code for the Smart Shaker application included in the software download. A full overview of Android development is beyond the scope of this guide, but if you want to learn about Android development check out these resources:
Also be aware the source for this project was built using the Android Studio development environment, and is not directly importable into the ADT + Eclipse environment.

For the USB communication, this project uses the usb-serial-for-android library which is a great wrapper around USB to serial communication for Arduino and common FTDI chips. I've included the source to this library in the application and made a few small changes to it:
  • Added an InputStream and OutputStream implementation to better integrate the USB serial device with other Java classes.
  • Added a function to enumerate all the USB devices which are supported by the library. The default device enumeration function in the library requires permission to all the attached devices which is not really feasible for use in a device selection list.
It will also be helpful to familiarize yourself with Android's USB development documentation. Although the usb-serial-for-android library does most of the work for you, you will still need to do things like add permission for USB host mode to your application manifest.

This guide was first published on Mar 07, 2014. It was last updated on Mar 07, 2014.

This page (USB Communication) was last updated on Mar 03, 2014.

Text editor powered by tinymce.