Hanging moving guestures(Left/normal/right/up/normal/down) using mpu9150 sensor

Hello Sir,

We tried (Arduino+mpu9150) using gestures LEFT-NORMAL-RIGHT, UP-NORMAL-RIGHT.

We can able to get these gestures, but not accurately.

Its HANGING in middle, and sometimes values are also Incorrect.

Could you please help me to fix this issue?

Please check complete code for an ++attachment.

CODE:

void guesture() {

//LEFT & RIGHT
//Starting Accelerartion condition

if ( diff_yaw < -250)
{
diff_yaw = -(360 + diff_yaw);
}
else if (diff_yaw > 250)
{
diff_yaw = 360 - diff_yaw;
}

if ((aaReal.y < -1500) && (flag1 == false) && (flag2 == false) ) {
old_time1 = new_time;
old_yaw = new_yaw;
flag1 = true;
} else if ((aaReal.y > 1000) && (flag2 == false) && (flag1 == false)) {
old_time1 = new_time;
old_yaw = new_yaw;
flag2 = true;
} else if (aaReal.z > 400 && flag11 == false) {
old_time = new_time;
flag11 = true;
} else if (aaReal.z < -400 && flag22 == false) {
old_time = new_time;
flag22 = true;
}

if ((aaReal.y > 1000) && (flag1 == true) && (flagZ1 == false)) {
flagZ1 = true;
} else if ((aaReal.y < -1500) && (flag2 == true) && (flagZ2 == false)) {
flagZ2 = true;
} else if (aaReal.z < -400 && flag11 == true) {
diff_time = new_time - old_time;
flag11 = false;
if (diff_time < 2000 ) {
flag33 = true;
old_time = new_time;
}
} else if (aaReal.z > 400 && flag22 == true) {
diff_time = new_time - old_time;
flag22 = false;
if (diff_time < 2000 ) {
flag33 = true;
old_time = new_time;
}
}

if ((aaReal.y < 1000) && (flagZ1 == true)) {
flag1 = false;
flagZ1 = false;
diff_yaw = new_yaw - old_yaw;
diff_time = new_time - old_time1;
if (diff_time < 2000)
{
flagN = true;
}

} else if ((aaReal.y > -1500) && (flagZ2 == true)) {
flag2 = false;
flagZ2 = false;

diff_yaw = new_yaw - old_yaw;
diff_time = new_time - old_time1;
if (diff_time < 2000)
{
flagN = true;
}

}

if (flagN == true) {

if (Iposition == 0 && diff_yaw > 0) { //Right
Iposition = 1;
flagR = true;
} else if (Iposition == 0 && (diff_yaw) < 0 ) { //Left
Iposition = 2;
flagL = true;
} else if (Iposition == 1 && (diff_yaw) < 0 && (diff_yaw) > -25) { //Right-Normal
Iposition = 0;
flagNL = true;
} else if (Iposition == 1 && (diff_yaw) < -25) { //Right-Left
Iposition = 2;
flagL = true;
} else if (Iposition == 2 && (diff_yaw) > 0 && diff_yaw < 25) { //Left-Normal
Iposition = 0;
flagNL = true;
} else if (Iposition == 2 && diff_yaw > 25) { //Left-Right
Iposition = 1;
flagR = true;
}
}
if (flagN == true || flag33 == true) {
if (flagR == true) {
Serial.println(“POSITION : RIGHT”);
flagR = false;
} else if (flagL == true) {
Serial.println(“POSITION : LEFT”);
flagL = false;
} else if (flagNL == true) {
Serial.println(“POSITION : NORMAL”);
flagNL = false;
} else if (Ipos == 0 && pO >= 20 ) {
Ipos = 1;
Serial.println(“POSITION : UP”);
} else if (Ipos == 0 && pO <= -20 ) {
Ipos = 2;
Serial.println(“POSITION : DOWN”);
} else if (Ipos == 1 && pO <= 10 && pO >= -10 ) {
Ipos = 0;
Serial.println(“POSITION : NORMAL”);
} else if (Ipos == 1 && pO < -5 ) {
Ipos = 2;
Serial.println(“POSITION : DOWN”);
} else if (Ipos == 2 && pO >= -10 && pO < 0) {
Ipos = 0;
Serial.println(“POSITION : NORMAL”);
} else if (Ipos == 2 && pO > 0 ) {
Ipos = 1;
Serial.println(“POSITION : UP”);
}
flagN = false;
flag33 = false;
}

}

MPU9150_DMP6.ino (17.4 KB)