Acceleration sensor from the smartphone is used to drive the robot forward backw

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

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

1.1 Google Code Archive - Long-term storage for Google Code Project Hosting.

1.2 Google Code Archive - Long-term storage for Google Code Project Hosting.

//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
}

Was there a question?

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

What parts did you use exactly?

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.