Hercules: the Motion Controlled Android Robot

51,259

161

106

Intro: Hercules: the Motion Controlled Android Robot

When I was in the 8th grade, I was intrigued while playing the motion games on Nokia 5800. I was thrilled, how I could control the racing car by only tilting the phone. I used to dream of making this same car in the real world. 

Now, in 11th  grade ( Age 17) having got an Arduino Uno and learnt how to program it, I was able to build my "Hercules" robot. 

Hercules is the name given to my motion controlled robot because of its immense torque and speed. The robot is controlled by an android phone through bluetooth. The advantage of using an android phone to control the robot, is that I can use any android phone to control it and am not confined to using only one controller for the robot. The use of an android phone as a controller, significantly reduces the cost of the project, since money is not spent in building a controller for the robot.    

The Hercules was built for the 2012 Indian Institute of Technology, Mumbai's IIT Techfest ( Asia's largest tech festival ). The objective was to build a motion controlled robot that could race around an obstacle track.

Step 1: Step 1: Parts Needed:

For making this robot you need the following parts :

         Supplies :

1.     Arduino Uno. 
2.     
Bluetooth Transceiver Chip ( Serial Bluetooth Modem).
3.     L298 Dual H-Bridge IC.
4.     4pcs of Geared Motor (Specifications depend on application of the robot).
5.     4pcs of wheels.
6.     12v 1Ah SLA Battery.
7.     Base plate for the robot components.
8.     3cms x 7cms PCB.
9.     4pcs of Project Enclosure / boxes .
10.   SPST Switch.
11.   Male Header Pins (Straight).
12.   Wire.
13.   Small Screws and nuts.
14.   Resistors ( 1pc 10K ohms and 1pc 20k ohms).
15.   Android phone.


            Tools :

1.   Soldering iron.
2.   Solder.
3.   Soldering wax.
4.   Drill.
     


Step 2: Step 2: Chassis and Wheels

The big screws on the motor make it easy to mount on chassis. The wheels slide on to the motor shaft and get screwed in place.
Connect the Left Side Motors in parallel. Connect the Right Side Motors in parallel. 
After fitting the four motors and wheels, you should have something that looks like the first picture. 

Step 3: Step 3: the Circuit: Arduino Box

The principle of divide and rule can be applied in every aspect of our life. This simple principle is also applied to this circuit. The circuit is divided into different boxes. This modular design makes it easy to maintain and troubleshoot the circuit. If some component burns off during the competition or when it is being run, then the corresponding module can be replaced quickly.

Arduino Box:

1.
  Cut the PCB using a hacksaw into 4 parts as follows: a) 2 nos. of PCB each having eight holes in length and three holes in breadth and b) 2 nos. of PCB each having six holes in length and three holes in breadth; which after assembling should look like the first picture. 

2.   Place the male header pins along the length of the cut PCB and solder them in place. It should look like the second picture.

3.   Solder  wires (approx 4 inches in length) to each of the header pins. Refer to picture 4. Now you are done with the header pins array for the arduino. By using this technique, the header pins do not come off easily from the Arduino as the force is distributed equally between the pins.

4.   To prepare the project enclosure(box) for the Arduino Uno; first, temporarily place the Arduino Uno in the box. Place it in such a way that the USB port end touches the breadth of the box at one end and you can mark the part which you must cut/drill (as the USB port should stick out of breadth of the enclosure). This will help us program the Arduino board even after it is installed in the robot. After cutting/drilling the enclosure, again temporarily place the Arduino Uno in the enclosure, and apply some force making sure that the USB port sticks out of the enclosure. With the Arduino Uno in this position, you will now have to mark and drill sixteen small holes on the upper end of the enclosure's length so that the wires coming out of the PCB circuit will pass through this enclosure (ready to be attached to some other circuit); and diagonally opposite, mark and drill twelve small holes on the lower end of the enclosure's length so that the wires coming out of this PCB circuit will pass through the enclosure (ready to be attached to some other circuit). Note how these well planned holes help the header pin wires to come out neatly from the project enclosure box. Drill four small holes on the base of the box as per the four holes already there on the Arduino Uno so that with the help of small screws and nuts, you can permanently hold the Arduino in place.

5.   Finally place the Arduino in the box and fasten it with the small screws and nut to the base of the project enclosure. Fit the header arrays on the arduino pins and drive the wires of the header pins array through the holes made in the enclosure box.

6. Now you are done with the Arduino Box. The Arduino box should look something like the first picture. 
 


 


Step 4: Step 4: the Circuit: Bluetooth Transceiver Box

The most tricky part of this instructable is soldering the wires to the tranceiver. A third hand is always useful for such applications.

1. Solder a wire 4 inches in length to pin 1. This is the Tx pin.

2. Solder a wire 4 inches in length to pin 2. This is the Rx pin.

3. Solder a wire 4 inches in length to pin 12. This is the +3.3v pin.

4. Solder a wire 4 inches in length to pin 13. This is the Ground (GND) pin.

Place this bluetooth trasceiver in a small enclosure or box having holes for the wires to exit. Make sure you glue the wires to the box. This acts as a stress relief mechanism preventing the soldered wires from coming off under any pressure. The bluetooth module I got is from ebay. It is quite cheap and reliable, so much so that I use the same bluetooth module in my middleweight combat robot.    

Step 5: Step 5: the Circuit: the Resistor Box

The arduino sends serial output of 5v through the Tx pin, whereas the bluetooth transceiver module uses 3.3v logic. So a voltage divider circuit ( level shifter ) is required to convert this 5v output to 3.3v. Follow the schematic diagram and solder the resistors on the remaining piece of PCB. If your arduino enclosure is big enough, then you can have this circuit within the arduino box, else you will have to use another small box for this circuit.     

Step 6: Step 6: the Circuit: Motor Controller

The motor controller used for the project is an L298 IC. It is a dual H-Bridge IC which is used to control the four motors of the robot. I made a custom etched PCB for the L298 (pic. 3) which makes soldering the wires easy to the L298 pins. If the resources for making a custom etched PCB are not available, then solder a wire to each pin of the L298 IC. After soldering the wires, place the IC in a small enclosure having holes drilled in it for the wires to leave the box. Your Motor Controller box should look something like the first picture. 

Step 7: Step 7: the Circuit: Final Connections

Interconnect the Arduino Box, the Bluetooth module, the resistor box according to the first picture. 

The pin connections of the L298 Motor Controller and the Arduino are as follows :- ( Refer to L298 pinout - picture 2)

1----Ground

2----Pin 1 of Left Side Motors  

3----Pin 2 for Left Side Motors

4---- +12v battery

5---- Arduino Pin 2 

6---- Arduino Pin 3

7---- Arduino Pin 4

8---- Ground

9---- +5v from Arduino

10---- Arduino Pin 5

11---- Arduino Pin 6

12---- Arduino Pin 7 

13---- Pin 1 of Right Side Motors

14---- Pin 2 of Right Side Motors

15---- Ground


Connect the +12v terminal of the battery through a switch to the Vin pin of the Arduino and to pin 4 of the L298 IC.
Connect the -ve terminal of the battery to the Ground (GND) pin of the Arduino.

Step 8: Step 8: Programming the Arduino

Before you can program the Arduino Uno, you have to install the Amarino library for the Arduino. These are the steps to install the library :-

1.   Download the  Amarino library for the Arduino (link).

2.   Extract the zip file to the folder: arduino_install_dir/libraries/extract_meetandroid.zip_here

3.  
Now you would see the library under   " Sketch --> Import Library "  in the Arduino IDE.

4.   You can proceed with the Arduino Uno programming.



The following is the source code for the Arduino. Copy the code below and load it on the Arduino :-


#include <MeetAndroid.h>

const int EnablePin1 = 3;
const int EnablePin2 = 6;
const int Motor_1_A = 2;
const int Motor_1_B = 4;
const int Motor_2_A = 5;
const int Motor_2_B = 7;
float data[3] = {0};
int intdata[3] = {0};
int i = 1;


MeetAndroid meetAndroid(error);

void error(uint8_t flag, uint8_t values)
{
  Serial.print("ERROR: ");
  Serial.print(flag);
}


  void setup() {
  Serial.begin(9600);
  Serial.println("\t\t\t.----------------------.");
  Serial.println("\t\t\t|    Starting Up..     |");
  Serial.println("\t\t\t'----------------------'");
  pinMode(EnablePin1, OUTPUT);
  pinMode(EnablePin2, OUTPUT);
  pinMode(Motor_1_A, OUTPUT);
  pinMode(Motor_1_B, OUTPUT);
  pinMode(Motor_2_A, OUTPUT);
  pinMode(Motor_2_B, OUTPUT);
  delay(1000); 
 
 
  meetAndroid.registerFunction(floatValues, 'A'); 


}

void loop()
{
  meetAndroid.receive(); 
}
void floatValues(byte flag, byte numOfValues)
{
 
  meetAndroid.getFloatValues(data);
 
  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);
  }
 
      if (-10<=data[0]<=10) //        This is for Forward/Reverse
      {

        intdata[0] = int(data[0]);
        intdata[0] = intdata[0] * 24;
            if (data[0] <= -2)
            {
              intdata[0] = abs(intdata[0]);
              digitalWrite(Motor_1_A, HIGH);
              digitalWrite(Motor_2_A, HIGH);
              digitalWrite(Motor_1_B, LOW);
              digitalWrite(Motor_2_B, LOW);
              analogWrite(EnablePin1, intdata[0]);
              analogWrite(EnablePin2, intdata[0]);
            }
            else if (data[0] >= 2)
            {
              digitalWrite(Motor_1_A, LOW);
              digitalWrite(Motor_2_A, LOW);
              digitalWrite(Motor_1_B, HIGH);
              digitalWrite(Motor_2_B, HIGH);
              analogWrite(EnablePin1, intdata[0]);
              analogWrite(EnablePin2, intdata[0]);
            }  
            else if (-1<=data[0]<=1)
            {
              digitalWrite(Motor_1_A, LOW);
              digitalWrite(Motor_2_A, LOW);
              digitalWrite(Motor_1_B, LOW);
              digitalWrite(Motor_2_B, LOW);
              digitalWrite(EnablePin1, LOW);
              digitalWrite(EnablePin2, LOW);
            } 
      }


    if (-10<=data[1]<=10)  //        This is for Turn Left/Turn Right
    {
                if (data[1] <= -2)
                {
                  digitalWrite(Motor_1_A, HIGH);
                  digitalWrite(Motor_2_B, HIGH);
                  digitalWrite(Motor_1_B, LOW);
                  digitalWrite(Motor_2_A, LOW);
                  analogWrite(EnablePin1, intdata[0]);
              analogWrite(EnablePin2, intdata[0]);
                }
                else if (data[1] >= 2)
                {
                  digitalWrite(Motor_1_A, LOW);
                  digitalWrite(Motor_2_B, LOW);
                  digitalWrite(Motor_1_B, HIGH);
                  digitalWrite(Motor_2_A, HIGH);
                  analogWrite(EnablePin1, intdata[0]);
                  analogWrite(EnablePin2, intdata[0]);
                }
                else if (-1<=data[1]<=1)
                {
                  digitalWrite(Motor_1_A, LOW);
                  digitalWrite(Motor_2_A, LOW);
                  digitalWrite(Motor_1_B, LOW);
                  digitalWrite(Motor_2_B, LOW);
                  digitalWrite(EnablePin1, LOW);
                  digitalWrite(EnablePin2, LOW);
                }    
    }
   
}

Step 9: Step 9: Software for Android

What is Amarino ?


Amarino is a toolkit designed to work with smartphones based on the Android open source operating system. The good thing is, you don't need any programming knowledge in Android at all to get started with. You can start right away just by installing the provided Android application on your phone. It comes already with many preinstalled events you can select to send it over to your Arduino.

Downloading the Amarino App :

Here is a video on how to install the Amarino App and plugin.




The following are the steps for downloading the Amarino Application:-
  1.  Download the Amarino Application (link) and the Amarino plugin (link) on your computer.
  2.  Copy the Amarino App and Amarino plugin to the Android phone's SD card.
  3.  Install the Amarino App and the Amarino plugin on the Android phone.
  4. Turn On the Bluetooth robot.
  5. On the Android phone go to "Settings-->Wireless and Network-->Bluetooth Settings". Turn on the bluetooth and search for your bluetooth module. Once the bluetooth module is discovered, pair with it but do not connect to it.
  6. Open the Amarino App on the Android phone. Click the "Add BT Device" button. Select the bluetooth module from the list of devices.
  7. Your bluetooth module now appears on the Amarino homescreen. 
  8. Select the red file button next to the bluetooth module's name. 
  9. Select the "Add Events" button and select the "Accelerometer Sensor" option.

You are now done with installing the Software part on the Android Phone

Step 10: Step 10: Driving the Hercules

You are done with building the Hercules robot, so now its time to drive the beast.


These are the steps to drive the Hercules:
  1. Turn on the Hercules robot.
  2. Open the Amarino Application on the Android phone.
  3. Click the "Connect" button to connect the Android phone to the robot.
  4. Tilt the phone to move your Hercules robot.
Notice that the robot's speed is proportional to how much you tilt your Android phone. This is the tilt proportional drive of the Hercules robot.

It could so happen that the robot goes in an undesired direction. Under such cases, invert the wires going to the motor which side goes in the wrong direction.

And there you go, you have built your very own Motion Controlled Robot..

If you have any difficulties building your Robot, do feel free to ask.

GREAT!!!!! NOW GO AHEAD AND CONSTRUCT ONE YOURSELF!!!!! : )

Robot Challenge

Finalist in the
Robot Challenge

Arduino Challenge

Second Prize in the
Arduino Challenge

Share

    Recommendations

    • Metalworking Contest

      Metalworking Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Audio Contest 2018

      Audio Contest 2018

    106 Discussions

    0
    None
    Rishav09

    2 years ago

    Not works with marshmellow. Some firmware updating issue is there. But i am quite sure amarino is not finding any bluetooth connection nearby

    0
    None
    ammar Khalil

    2 years ago

    Hi

    can you please comment the sketch. it will be so helpful for a newbie, like me. Thanks in advance.

    A.

    0
    None
    PrathmeshR1

    3 years ago on Step 8

    getting error compiling while compiling the program help me out plz..

    0
    None
    Akshay Jha

    4 years ago on Introduction

    hiiiii vineet i just want to know from where you learn arduino and android both because i have made many projects of arduino and microcontroller but the shamefu thing is that i had never written my project code itself so i want your help to learn language for arduino plz guide me and reply soon you can also mail me at akshay20jha@gmail.com

    0
    None

    Hi, compliments for the very nice tutorial|

    I'm a beginner and I would appreciate if you can give me a help:

    I do have Arduino uno and a motor shield adafruit as you can see on the image,

    Can you please suggest how can I modify your sketch just to use it and explain in a way so that I can understand?

    I hope to no disturb you with this!

    Thanks a lot

    Regards

    Arnaldo

    PS- My email just in case you want to email me.

    arnaldo.armida@gmail.com

    adafruit-motorshield.jpg
    0
    None
    abencomo

    4 years ago on Introduction

    Nice work! We built a similar project. However, we installed an Android device onto a RC car and used an IOIO board instead to control it autonomously. Here is the preliminary result:

    http://youtu.be/vkvkfcqEUkk

    0
    None
    sidharthjain

    4 years ago on Introduction

    i am using arduino duemilanove instead of uno and the recieved output is random

    please HELPPP

    0
    None
    gm4afsal

    4 years ago on Introduction

    Guys...Just download and use Arduino 0022. Meet android problems will be solved then.
    :)

    0
    None
    YARiK_997

    4 years ago on Introduction

    Hi. i"ve got this error in arduino

    In file included from sketch_sep26a.ino:1:
    C:\Users\ADiTHYA_PC\Documents\Arduino\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)'
    C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

    1 reply

    I do not know why some people are getting this error these days. I had written the program in Arduino ADK version 0022 hence try installing the version 0022 and see if that helps.

    You could use the arm 7 instead of the Arduino, but I cannot help you out with that as I have no experience working with ARM processors.

    0
    None
    bhar92

    6 years ago on Introduction

    Hey Jayvis! Your robot inspired our first robot, the Mastadon! http://blimp12.blogspot.in/2012/07/mastodon-10-and-diy-dinner.html
    Thank you so much!

    5 replies

    I'm glad hearing about how you replicated the robot. Enjoy with it now. You can customize it in a number of ways to suit different purposes. All the best !! Btw where do you live in India ?