sensitivity of servo that is controlled via android phone

good day everyone! just like to ask for an assistance on how to make the motion of the servo motor more sensitive with the tilt of the android phone... our program was to control the tilt of the ball maze board via android phone... our code was also given... we are just wondering if this is just the limitation of the Bluetooth connection... we are using amarino application also for the connection between android phone and bluesmirf...
here's the code...

#include <Servo.h>
#include <MeetAndroid.h>

float data[3] = {0};
int intdata[3] = {0};
int i = 1;
Servo myservo;
Servo myservo2;
int pos = 0;


// MeetAndroid meetAndroid();
// you can define your own error function to catch messages
// where not fuction has been attached for
MeetAndroid meetAndroid(error);

float previousdata = 0;
int elapsedtime = 0;

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


void setup()
{
  Serial.begin(115200); //begin serial link @ 9600bps
  // register callback functions, which will be called when an associated event occurs.
  // - the first parameter is the name of your function (see below)
  // - match the second parameter ('A', 'B', 'a', etc...) with the flag on your Android application
  meetAndroid.registerFunction(floatValues, 'A'); 
  myservo.attach(9); //Attach the servo to pin eleven
  myservo2.attach(10);
}

void StopCar()
{
  myservo.write(90);
  myservo2.write(90);
}

void loop()
{
  myservo.write(90);
  myservo2.write(90);
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
void floatValues(byte flag, byte numOfValues)
{
  // create an array where all event values should be stored
  // the number of values attached to this event is given by
  // a parameter(numOfValues)
 
  // call the library function to fill the array with values (floats)
  meetAndroid.getFloatValues(data);
 

  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);//Used for debug purposes
  }

  if (-10<=data[1]<=10)   {
     intdata[1] = int(data[1]); //Cast the X axis float value to int
     intdata[1] = intdata[1]+10;
     pos = intdata[1]*9;
     myservo.write(pos);
  }
  if (-10<=data[0]<=10)   {
    intdata[0] = int(data[0]);
    intdata[0] = intdata[0]+10;
    pos = intdata[0]*9;
    myservo.write(pos);
  }
  if (previousdata == data[0]) { //If the data's still the same (It should have been changed by the meetAndroid.getFloatValues(data) function)
     if ((elapsedtime-millis())>=1000) { //If the car has lost the signal more than 1sec, then stop the car
        StopCar();
     }
   }
           
}

sort by: active | newest | oldest
My coding is a bit rusty but isn't this part of the program that reads the data from the Arduino then passes it along to move the servos? You may want to reduce the highlighted number.

if (-10<=data[1]<=10) {
intdata[1] = int(data[1]); //Cast the X axis float value to int
intdata[1] = intdata[1]+10;
pos = intdata[1]*9;
myservo.write(pos);
}

if (-10<=data[0]<=10) {
intdata[0] = int(data[0]);
intdata[0] = intdata[0]+10;
pos = intdata[0]*9;
myservo.write(pos);
}

Taking the tilt position of the phone and multiplying it by 9 might be the reason for the servo making large swings when there is only slight movement from the phone. I don't know what kind of numbers are coming out of the phone but maybe the range that data[1] and data[0] are looking for need to be played around with as well. Just play with those numbers and see what happens.

I take it this code is from some other project and your adapting it to your project right?
maevalen (author)  mpilchfamily5 years ago
thanK you verY much... but we did try to change the numbers into lower number yet the servo wont function anymore. then we tried it to be on heigher value. the motion is just the same...
mikeasaurus5 years ago
moved to Forum>Tech
maevalen (author)  mikeasaurus5 years ago
thank you very much for the comment... :) i did transfer it now... :)
It was already done by Mike. You've created a duplicate posting, and probably want to delete it.
Take a look at the raw numbers coming over the link. See if there are filter properties of the signal you are reading from the phone - put there to make the signal quieter, but affecting your frequency response.
maevalen (author)  steveastrouk5 years ago
thank you very much for the comment!... :) i'll be trying to see if there will be filter properties of the accelerometer data... :)