Android + Arduino + USB Host + Swivel Head Android with LEDs

  

Combining analog and digital outputs with Android and Arduino.  This tutorial will demonstrate the basic use of combined digital and analog outputs.  The basic hardware is a hobby servo and two LEDs inside of an Android figure.  The servo allows Andy Android to rotate 180 degrees.

For additional background information on interfacing Android with the real world, check out my other introductory tutorials:

Simple Digital Input
Simple Digital Output
Simple Analog Input
Simple Analog Output

 

Hardware

Parts needed:

  • Android Device (1.6+)
  • Hobby servo
  • 2x LEDs
  • 2x 330 ohm resistors
  • Breadboard
  • Power supply
  • Hook-up wire
  • Android ADK Board*
  • – OR –
  • Arduino compatible and USB Host shield

*Supported boards include:

Google ADK boardFreeduino ADK board Seeed Studio ADK board, and DIY Drones ADK board

 

Assembly

Connect the two LEDs to digital output pins 3 and 4, using a 330 ohm resistor for each in series to limit current. Connect the signal line of the servo to pin 5.  Other pins can be used, as long as the servo signal line is capable of PWM (usually has a ~ symbol next to it on the Arduino board) and none interfere with the SPI lines connecting to the USB Host (10 -14 on most).  Here is a diagram of the completed circuit (created with Fritzing):

 

Software

Arduino Firmware

Next, upload the Arduino sketch to the microcontroller. The sketch uses the Microbridge implementation by Niels Brouwers. Microbridge uses Android Debug Bridge (ABD) forwarding over TCP, rather than the official Google Android ADK. You can checkout the source for the Arduino sketch from Github, or just copy and paste the following into the Arduino IDE.

 

Android App

Finally, install the Android Demo application onto the device. You can either download the pre-built .apkor checkout the source from Github:

git clone git://github.com/mitchtech/android_adb_andy_android.git

Finally upload the app to the device (or browse to this page on the device and download the apk above). Connect the Android device to the USB Host board/shield, and start up the app.

 

10 Comments

  1. tay ruhong

    hi thank alot for the tutorial. i try and compile the code with my arduino version 1.0 but it say i do not have the header file for adb. i tried add into arduino lib with adb header file but still having this error.

    In file included from ADBAndroid.cpp:2:
    C:\arduino-1.0-windows\arduino-1.0\libraries\Adb/Adb.h:20:20: error: wiring.h: No such file or directory

    do u mind sharing ur header file with me by email?

  2. Hi tay, it looks like this is an issue in the Arduino IDE 1.0 (the article was written with 022 IDE). To fix the problem you will need to change the include statements in the Adb library. In the following files:
    Adb.h, usb.cpp, and max3421e.cpp
    Change the line:
    #include "wiring.h"
    to
    #include "Arduino.h"

  3. tay ruhong

    hi michael, i had try what u mention but still not able to compile with same error occur. the below is the code i use can see if which part need edit.thanks alot alot for ur help .
    #include
    #include
    #include
    #include

    #define LED1 3
    #define LED2 4
    #define SERVO1 5

    Servo servo1;

    Connection * connection;

    // Event handler for shell connection; called whenever data sent from Android to Microcontroller
    void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data)
    {
    // Data packets contain two bytes, first byte is pin number, second byte is state
    // For servos, in the range of [0..180], for LEDs, 0 or 1
    if (event == ADB_CONNECTION_RECEIVE)
    {
    int pin = data[0];
    switch (pin) {
    case 0×3:
    digitalWrite(LED1, data[1]);
    break;
    case 0×4:
    digitalWrite(LED2, data[1]);
    break;
    case 0×5:
    servo1.write(data[1]);
    break;
    default:
    break;
    }
    }
    }

    void setup()
    {
    // Init serial port for debugging
    Serial.begin(57600);

    // Attach servo
    servo1.attach(SERVO1);

    // Init LEDs
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);

    // Initially on
    digitalWrite(LED1, 1);
    digitalWrite(LED2, 1);

    // Init the ADB subsystem.
    ADB::init();

    // Open an ADB stream to the phone’s shell. Auto-reconnect. Use port number 4568
    connection = ADB::addConnection(“tcp:4567″, true, adbEventHandler);
    }

    void loop()
    {
    // Poll the ADB subsystem.
    ADB::poll();
    }

  4. tay ruhong

    hi michael ,
    im able to resolve the problem alr. for phone part im using samsung GT-S5570(version 2.3.6) isit possible to run the app?

  5. Korea Hi Michael, I am a student.
    I’d like to try this project.
    Is there a way to where you got the android robot.

  6. hello michael .ı had added Microbridge library but stıll same arror.

    In file included from sketch_feb15a.ino:2:
    C:\Users\ibrah\Documents\Arduino\libraries\Adb/Adb.h:20:20: error: wiring.h: No such file or directory

    what must ı do ?can you help me ?

Leave a Reply