Identify forward,backward,right and left with IMU(BNO055)


I'm working on a project where I am trying to detect certain movements using a IMU (BNO055). Those movement are forward,backward,right, and left. I kinda figure out how to do left and right but forward and backward doesn't work well enough for me. Right now I am integrating the accelerometer data to get velocity, then I look at the sign to know the direction. Is there a better way to do this?

The directions sensed as positive acceleration may be indicated by arrows on the BNO055 module.

If not, they are clearly stated in the chip data sheet.

@ Jremington I know the directions I'm facing. I need to know if I am traveling in a certain direction. I tried filtering the data. I tried smoothing the data, but what I get is wrong identifications of forward and backward movement/

Its all kind of abstract.

How about showing code and numbers?

It may as simple as needing to increase accelerometer sensitivity.

I know the directions I'm facing

The question is: which direction is the CHIP facing & sensing?

For posting code and explaining problems, please read and follow the instructions in the "How to use this forum" post.

If you are walking, initial acceleration is brief and very noisy. Do not expect good results for integration to obtain velocity.

This is the function I created. Read comments

// This function only gets called when acceleration in the y axis passes a threshold. Which means a
// change in movement has occurred

char acceleration_lookup(char old_forward_backward){
int array_size = 5;
float buf[array_size] ;
float alpha = .95;
int count = 0;
float accel_y = 0.00 ;
char forward_backward = NULL;
float sum = 0.00;

while(count< array_size){
imu::Vector<3> accel_d = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL); // get acceleration data
accel_y = accel_d.y(); // get the Y axis data
if(count == 0){buf[0] = alpha*accel_y ; // low pass filter to smooth reading
}else{buf[count] = alpha *accel_x + (1- alpha)*buf[count - 1];}
Serial.println(buf[count]); // Run an average over “array_size” of datapoint
sum = sum + buf[count];
sum = sum /array_size;

// - Y is going forward
// + Y is going backward
// If the average is over a threshold record the new direction

if(sum < -1 && ((old_forward_backward == ‘B’) ||(old_forward_backward == NULL)) ){forward_backward = ‘F’;}
else if(sum > 1 && ((old_forward_backward == ‘F’) ||(old_forward_backward == NULL))){forward_backward = ‘B’;}
else {return NULL;}
return forward_backward ;


Please edit your post to add code tags, as described in “How to use this forum”.

Which direction is “y” and how did you choose it?

what I get is wrong identifications of forward and backward movement

That would depend on which direction you call y, and its sign.

It is best to make sure you understand the raw acceleration values and their meaning, before coding all this. For example, when you hold the accelerometer still, tell us the values that it reports and why.