Pages: [1]   Go Down
Author Topic: Acceleration sensor from the smartphone is used to drive the robot forward backw  (Read 1970 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Acceleration sensor from the smartphone is used to drive the robot forward backwords left and right

http://youtu.be/1uLr0o4bpm4

1. http://www.amarino-toolkit.net

    1.1 http://code.google.com/p/amarino/downloads/detail?name=Amarino_2_v0_55.apk&can=2&q=

    1.2 http://code.google.com/p/amarino/downloads/detail?name=AmarinoPluginBundle.apk&can=2&q=

 
Code:
//Acceleration sensor from the smartphone is used to drive the robot forward backwords left and right

//inspired from http://www.arduino.cc/playground/Code/HTCDesire
//arduino + amarino + HTC Wildfire

#include <MeetAndroid.h>

#define IDLE 0
#define RINGING 1
#define OFFHOOK 2

MeetAndroid meetAndroid;



int EN1 = 6;
int EN2 = 5;  //
int IN1 = 7;
int IN2 = 4; //

  void Motor1(int pwm, boolean reverse)
    {
    analogWrite(EN1,pwm); //set pwm control, 0 for stop, and 255 for maximum speed
    if(reverse)
    {
    digitalWrite(IN1,HIGH);
    }
    else
    {
    digitalWrite(IN1,LOW);
    }
    }


  void Motor2(int pwm, boolean reverse)
    {
    analogWrite(EN2,pwm);
    if(reverse)
      {
      digitalWrite(IN2,HIGH);
      }
    else
      {
      digitalWrite(IN2,LOW);
      }
      }

  void Forward(int speed)
    {
      Motor1(speed,true); //You can change the speed, such as Motor(50,true)
      Motor2(speed,true);
    }

  void Backward(int speed)
    {
      Motor1(speed,false); //You can change the speed, such as Motor(50,true)
      Motor2(speed,false);
    }

  void Right(int speed)
    {
      Motor1(speed,false);
      Motor2(speed,true);
    }

  void Left(int speed)
    {
      Motor1(speed,true);
      Motor2(speed,false);
    }

  void Stop()
    {
      Motor1(0,false);
      Motor2(0,false);
    }

void setup()  
  {
    Serial.begin(115200);

    meetAndroid.registerFunction(phoneorient, 'A');
      int input=0;
      int i;
    for(i=5;i<=8;i++)     //For Arduino Motor Shield
    pinMode(i, OUTPUT);    //set pin 4,5,6,7 to output mode
  }

void loop()
  {
    meetAndroid.receive(); // you need to keep this in your loop() to receive events
  }

  void phoneorient(byte flag, byte numOfValues)
  {
    //Phone Orientation Controller
    int values[]={0,0,0};
    meetAndroid.getIntValues(values);

  int Steer=values[1];   //
  int Delta=values[2];   //
  int Heading=values[3];    //

  if (Steer >=5)

    {   //left

      Motor1(220,true); // M1 forward when accelerometer is set to 0 -10...0 0
      Motor2(220,false); // M2 forward when accelerometer is set to 0 10 0
        
  }

  else if (Steer <=-5)
  { //right

    Motor1(220,false);
    Motor2(220,true);

  }

   else if (Delta >=5) { //forward
    
    Motor1(220,true);
    Motor2(220,true);

  }
     else if (Delta <=-5) { //back

    Motor1(220,false);
    Motor2(220,false);

  }

  else
  
  {
    Motor1(0,false);
    Motor2(0,false);

  }

    Serial.println(values[1]);  //Throttle  , Pitch
    Serial.println(values[2]);  //Steering, Roll
    Serial.println(values[3]);  // Heading, degree
}
« Last Edit: February 08, 2012, 12:20:40 pm by valim » Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Was there a question?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no question, just for anyone that needs this ...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What parts did you use exactly?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just need to know how you connected the bluetooth module to the arduino and where to connected.. I'm a total noob when it comes to this but I really want to make this project.
Logged

Pages: [1]   Go Up
Jump to: