loading

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);
                }    
    }
   
}
<p>Hi</p><p>can you please comment the sketch. it will be so helpful for a newbie, like me. Thanks in advance.</p><p>A.</p>
<p>getting error compiling while compiling the program help me out plz..</p>
<p>You made nice project</p><p>I made simple Do it yourself in 10 minutes bluetooth controlled home automation</p><p><a href="http://www.instructables.com/id/Take-control-of-your-house-in-10-Minutes/" rel="nofollow">http://www.instructables.com/id/Take-control-of-your-house-in-10-Minutes/</a></p>
<p>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</p>
<p>Hi, compliments for the very nice tutorial|</p><p>I'm a beginner and I would appreciate if you can give me a help:</p><p>I do have Arduino uno and a motor shield adafruit as you can see on the image,</p><p>Can you please suggest how can I modify your sketch just to use it and explain in a way so that I can understand?</p><p>I hope to no disturb you with this!</p><p>Thanks a lot</p><p>Regards</p><p>Arnaldo</p><p>PS- My email just in case you want to email me.</p><p>arnaldo.armida@gmail.com</p>
<p>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:<br><br>http://youtu.be/vkvkfcqEUkk</p>
<p>i am using arduino duemilanove instead of uno and the recieved output is random</p><p>please HELPPP</p>
<p>Guys...Just download and use Arduino 0022. Meet android problems will be solved then.<br>:)</p>
Hi. i&quot;ve got this error in arduino <br> <br>In file included from sketch_sep26a.ino:1: <br>C:\Users\ADiTHYA_PC\Documents\Arduino\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)' <br>C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
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.
can i use arm 7 instead of using arduino....
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.
hey can i use arduino leonardo
Hey Jayvis! Your robot inspired our first robot, the Mastadon! http://blimp12.blogspot.in/2012/07/mastodon-10-and-diy-dinner.html <br>Thank you so much!
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 ?<br>
I live in Bangalore, and you?
I live in Mumbai
JAYVIS i too lived in mumbai... <br> <br>i hv a prblm wit prgm will u plz upload it again
hey jayvis i liked ur robot and i m too from mumbai <br> <br> <br>love to so many Indians on instructables !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <br>
Every sixth person on this Earth is an Indian, so you could somewhat expect the same proportion here to. Hehe
can u tell me frm where did u get the blue tooth module and instead of L298 can i use l293D??
The L298 is quite common and can be purchased from Lamington Road. As for the Bluetooth Module, I ordered it from Ebay.com (Not Ebay.in)
can i get a bluetooth module frm lamington rod? <br>and while a upload the sketch i get this error <br>In file included from sketch_jan19a.cpp:1: <br>C:\Documents and Settings\PRANAV JAIN\My Documents\arduino-1.0.1\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)' <br>C:\Documents and Settings\PRANAV JAIN\My Documents\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t what should i do?
I do not know about the error as I am able to compile the program. Have you downloaded the Amarino plugin? <br><br>And about the bluetooth module, try your luck at Lamington but expect it to be overpriced if available.<br>
which module did u buy frm ebay i m geting AUBTM20 with RS232 frm lamington road will it work??? <br> <br>
What did u when u compile the sketch i.installed the amaranio libaray on the computer then wat should I do
does it need any plugin on computer???? <br>
hey <br>i also wannna do a similar stuff. i want to design a robot for surveillance where the robot will be fully autonomous and it wil move for point A to point B autonomously. <br>i want u to help me in designing the autonomous motion planning system to go form one given place to the other using sensors n stuff...i m stuck pls help <br> <br>i have bought the rover system from here just for making prototype of the actual system since i got it at a good price... <br>http://danuc.com/index.php?main_page=index&amp;cPath=6 <br>http://danuc.com/index.php?main_page=index&amp;cPath=4 <br>http://danuc.com/index.php?main_page=index&amp;cPath=1 <br>http://danuc.com/index.php?main_page=index&amp;cPath=7 <br>http://danuc.com/index.php?main_page=product_info&amp;cPath=8&amp;products_id=52 <br> <br>pls reply <br>
<br>i&quot;ve got this error in arduino <br> <br> <br>In file included from sketch_sep26a.ino:1: <br>C:\Users\ADiTHYA_PC\Documents\Arduino\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)' <br>C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
hai jayvis will u pls upload coding for controlling motors through blue control..? <br> <br>wat is the headerfile for this app?any other new library or the same???? <br>
i have a problem.. <br>my mobile detects the bluetooth module but i can't access the robot.. <br>i think there must be problem in app.. <br>pls help i have been doing this for 5 months kindly help me plssss <br>
Check out Step 9. It has all the details on how to pair and connect your Android phone with the bluetooth module.
i built the robot as u said but it s not working. bluetooth s getting paired with my mobile but the robot s not moving so pls help me i dont know what to do.pls reply me as early as possible
Thank you for a fast reply. <br>Ok, got it about the disconnected blth module. About the second problem: i guess something might be wrong with the blth module itself. I tried to detach it from the system and power just with the 3v battery. <br> The phone still doesn't see it. Im scanning for bluetooth devices in settings.
Hi Jayvis! I made this robot according to your instructions but I now face some problems. <br>1)The code doesn't want to upload. It uploads only if I detach all the wires from arduino. <br>2)My android phone doesn't see the robot by bluetooth <br> <br>What can I do here? <br> <br>When I turn on the switch all the lights turn on. On Arduino it's &quot;on&quot; and &quot;L&quot;. Bluetooth light is blinking.
Hi, <br>I have written somewhere in this instructable that the code must be uploaded only when the bluetooth module is disconnected from the Arduino or else the bluetooth module could get damaged. <br>Regarding the connection issue, you must first pair with the robot through bluetooth settings menu in the android phone. Then you must connect the robot with the phone using the Amarino Software. Hope this helps!
can i get any android apps for both motion controll and video receiving if so plz reply <br>
what are all the applications of it in real time problem if you have any idea plz tell me <br>
i have an error while compiling your program.'meetandroid does not a name type'this error which i had faced.eventhough i ve imported library from amarino im facing this error.what can i do?plz reply me soon.. <br>
can i use 12v DC motor which has lower than 500 rpm ? plz help <br>i cant find any at nearest shop in my town.
hi jayvis, i was so thrilled at first when trying to built the same robot like u did/ <br>but im having problem with the programme, help me plezz <br>it says : <br>In file included from sketch_feb22a.cpp:1: <br>C:\Users\LaPtOp PuNoH\Desktop\mat\arduino-1.0\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)' <br>C:\Users\LaPtOp PuNoH\Desktop\mat\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
hey i m trying verify the sketch this error cums <br> <br>In file included from sketch_jan19a.cpp:1: <br>C:\Documents and Settings\PRANAV JAIN\My Documents\arduino-1.0.1\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)' <br>C:\Documents and Settings\PRANAV JAIN\My Documents\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t
Hi... <br>I am experiencing a problem regarding your code... <br>It says MeetAndroid is not a type??? <br>What to do??
This problem was resolved but i m experiencing another problem... <br>I remade your project but failed to get serial data from the bluetooth module... <br>Tell me what to do??? <br>But i m able to send and receive serial data through arduino serial monitor...
Hey did you download the Amarino library? Cause I am able to compile the program and it works flawlessly.
If the problem still persists, try to copy the program from this instructable once again. It could be that you may have missed out a line or so in copying it earlier. <br>
Hi <br>I have created a project same like yours, but by tearing a RC car's circuit and putting my own. I used L298 motor driver, HC-05 bluetooth transreceiver, and two 5v motors with arduino uno. I use four 1.5v battery cells (becomes 6v) for motors and a 9v battery to power the arduino. <br> <br>The problem: <br>It does not get much speed that I desired. When I try to turn the car it gets slower and stops, because two motors work together to take a turn. Any help, suggestions, from your side? <br> <br>Thanks. <br>
Simple use a bigger battery or more number of AA batteries <br>
won't it effect the motor driver? Can I use 12v?
Try using 4pcs of fresh new batteries to power the motors. If it still does not work then increase the voltage.

About This Instructable