Obtaining orientation from an IMU

I’m wanting to obtain the real time orientation of an object. How do I obtain this?

Currently I have the Wifi Uno Rev 2 with the LSM6DS3TR IMU. Though I can obtain other equipment if needed.

1 Like

Couple of quick questions.

What is the object that we are tracking?
Will the object be stationary in space while it’s rotating or is carried around?
Does the object have room on the inside which could house the LSM6DS3TR IMU?

1 Like

Hi Mitchell,

Another couple of questions.

What do you mean by real-time orientation? Is it just the angle that the object is being held at or also a distance from where it was picked up?

A bit more general information about your project will help a ton!

1 Like

Thanks Mixmusix

The thigh of a person while walking, so the object will move in space as well as rotating. The IMU would be on the persons thigh so not technically inside

1 Like

Just the angle will be sufficient. I want to assess the orientation of someone’s thigh in real time (flexion/extension, abduction/adduction, internal rotation/external rotation.

1 Like

Have a look at this library by adafruit that interfaces between the arduino and the lsm6ds3trc

You’ll also need some code to calculate the 3d distance travel between each loop. I’d recommend a crude linear algebra approach.

struct GVec {
   float x;
   float y;
   float z;

  float dist(GVec v) {
    float dx = x - v.x;
    float dy = y - v.y;
    float dz = z - v.z;
    return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);

//Init a global vector.
GVec cacheVector;
/* SETUP REQUIRED! See Library Documentation */
void setup{// CODE GOES HERE!}

void loop() {
  // Get a new normalized sensor event
  sensors_event_t accel;
  sensors_event_t gyro;
  sensors_event_t temp;
  lsm6ds3trc.getEvent(&accel, &gyro, &temp);

  /* Calculate the distance traveled form last loop in radians */
  GVec vzero;
  vzero.x = gyro.gyro.x;
  vzero.y = gyro.gyro.y;
  vzero.z = gyro.gyro.z;
  cacheVector = vzero;

Hi Mitchell,

An IMU seems like the intuitive answer but a poteniometer is also an option: Core Electronics on Instagram: "We caught Liam trying to turn himself into a cyborg after playing too much Cyberpunk 2077. Only a few pots, a Pico and some Feetech servos and he's already claiming he can talk to the toaster. Head the link in bio to grab yourself some servos and get in on the craze."

There is definitely a scale of accuracy and timelyness when using an IMU, the method PIx used is very fast to compute but doesnt account for gyro drift.
Using the accelerometer is also fast but cannot easily reject fast movements or vibrations.

Sensor fusion through the use of a Kalman filter will be a bit slower to compute (still close enough to real time for the movements of a human) and help with the issues above.



Ooooo yeah good point.

Hi Mitchell
Maybe I’m missing something here, but if you want the orientation of an object in real time without drift error then a 3D magnetometer sensor would seem to be the most appropriate. Core sell various magnetometers, some with onboard accelerometers, gyroscopes and onboard processing included.

1 Like

Here’s an example of an IMU that does the fusion itself and has a visualiser.
I’ve linked our store page and Adafruit’s page. There is a comprehensive setup guide in there for a few different processors.

1 Like

How do I apply the Kalman Filter in the code. What would be an estimate of the delay using the Kalman Filter?


Great, thanks. An IMU that does the fusion itself will be the best option.

There are some discussion posts about drift over time causing significantly inaccurate measures with this sensor. Are there other options that are more accurate?

1 Like

There will always be some element of drift that creeps into sensors. Long term the goal is to minimise it.
Some things to consider, in no particular order, would be:

  • Testing the sensors regularly
  • Keeping the environment they’re in while in use consistent (This is one that may cause you issues)
  • Redundancy can help pick up on drift while still providing some source of data
  • Implementing filters in your code (I can see references to a Kalman filter, there are libraries for these readily available online, I recommend plotting your raw and filtered data together while you tune it)
  • The effect of batteries on the magnetometers magnetic field should also be considered, I can see this is where some people are having difficulties with drift. If you are tracking some ones thigh, if they place the battery in their pocket you shouldn’t have any issues.

Another thing to consider is if you are tracking movement long enough for drift to be an issue. This is where testing is needed.

I am pretty sure I have given you some more questions than answers here but hopefully this helps.

1 Like

Is there a product that you would recommend?


Hey Sally,

It depends on the specs that you need, and what microcontroller/s you’re intending on using it with. Although the MPU-6050’s and similar breakouts are often the ubiquitous generic option:

As for a magnetometer, something like the LIS3MDL is a popular generic choice:

Otherwise, if you’re using a MicroBit, RPi, or Pico you can set up the PiicoDev range that we design, manufacture, and prep code for here:

1 Like

It’s difficult to recommend the best sensor without knowing all the facts. It seems a BNO055/BNO085/BNO086 might be a good start if size is not an issue. And it may be necessary to trial a few sensors before finding the optimum solution. Drift should not be an issue from my experience. However, as Jack mentioned, there may be some distortion of output if there is any iron nearby the sensor, but your other components should be designed to minimise such distortion.


100% agree here, completely depends on use case and the problem-space.

This includes the level of precision required, what you’re intending to interface it with, available power and any battery life requirements, price, how comfortable you are with abstraction rather than dealing with and likely filtering or handling raw readings, etc.

If you’re putting together a prototype to get a better understanding of how to approach a solution, an all-in-one IMU such as the BNO Jack linked earlier would be a good place to start, should have plenty of docs online too.

Start generic and after some experimentation and experience with the setup you should have a much better idea of what hardware and specs are needed.


Is there a way to power the device without/minimally effecting the magnetometer while still having the power source and hardware together? As a small, all inclusive device would be best as it is a wearable… Also, what is the smallest set up with the BN085 powered and transmitting data via bluetooth to a pico W. Currently using a pico W with the BN085.

Hey Mitchell,

Avoiding electromagnetic interference entirely might prove challenging. Maybe have a look into EMF shielding sheets? Separating the components as best as you can with EMF shielding may be your best bet although it can only do so much as you probably wont be able to completely enclose your batteries.

as a general rule electromagnetic interference will grow alongside the current drawn from the batteries so if you could minimise that as much as possible you will get the best results.

If you can the more you can space out the batteries and the sensor the better. use EMF shielding if you need and keep the current draw as low as possible.

The smallest setup that you could easily setup for this would probably be a small battery, the esp32 and the BN085 on one end and another esp32 device on the other for it to talk to.

Hope this helps!

1 Like

Hi Mitchell
As Sam has pointed out EMF shielding can be a pain. The one thing he has not mentioned that is the most effective material for a shield is steel. Aluminium is just about useless. This makes it a real pain in the you know what.

As most of your static interfering field should be in the battery wires there is one thing you can do which will be really effective. Have the positive and negative wires the same length. They probably would normally be anyway. Twist them together as a twisted pair. This does not have to be too tight as long as they are kept in close proximity to each other. As the currents in the 2 wires are going in opposite directions the magnetic fields will cancel out so you should end up with a near zero result. There is no need for any shielding but don’t have them wandering all over the place. Keep as short as practical and you will have no trouble from this source.
Cheers Bob

1 Like