Determining Direction of Movement with LIS3DH

Hi all, I'm playing around with a Raspberry Pi for the first time and am working on a project where I want to determine if the device is being moved on an axis, and if so, in which direction.

I've hooked up an LIS3DH accelerometer, and have gotten it so that I can fairly reliable determine the start and stop of motion. But I'm not seeing a way to reliably determine which way the accelerometer is moving. For example, if I moving the device back and forth along the y-axis, the acceleration value for the y-axis change, but not in a way that I can reliable tell which direction along the y-axis the device is moving. I.e., when I move it in a given direction along the axis, the values are sometimes positive and sometimes negative.

My expectation (which may be wrong, I haven't really worked with accelerometers before) was that when I accelerate in one direction along an axis the values would be positive and when I accelerate in the opposite direction, they would be negative.

Am I approaching this erroneously? Or is the LIS3DH not the right sensor for the job? (Or both?) Any advice would be appreciated.

Simenzo

Posts: 3
Joined: Tue Jan 08, 2019 5:04 pm

Re: Determining Direction of Movement with LIS3DH

An accelerometer measures acceleration - which is a change in velocity. To calculate the velocity (assuming you are starting from a stationary position), you need to integrate the acceleration over time. Incremental calculations such as this tend to accumulate error over time, so accelerometers are typically combined with other sensors (e.g. GPS) for longer range speed and navigation measurements.

Posts: 73049
Joined: Sat Feb 07, 2009 10:11 am

Re: Determining Direction of Movement with LIS3DH

Thanks for the response! Yes, understood... and that's what I'm doing to determine that movement is happening. But what I'm not being able to figure out is how to determine which direction the movement is going in. I don't need to measure distance, just the direction of movement.

If the sensor is laying flat on a table at rest (or constant velocity), my expectation is that the y-axis value hovers around 0 (which is the case). But when I accelerate it along one direction on that axis, I would expect the value to be positive and when I accelerate in the opposite direction, negative. But that doesn't always seem to be the case. Shouldn't it be? Or am I somehow misunderstanding.

Simenzo

Posts: 3
Joined: Tue Jan 08, 2019 5:04 pm

Re: Determining Direction of Movement with LIS3DH

It will be positive when you accelerate in one direction and negative when you accelerate in the other. However, the sign of the acceleration will be inverted when you decelerate.

So: If you start from a stationary position and move the sensor in the positive Y direction, it will give you a positive Y acceleration value as you accelerate. Then when you decelerate to a stop and the Y readings will go negative.

Posts: 73049
Joined: Sat Feb 07, 2009 10:11 am

Re: Determining Direction of Movement with LIS3DH

I’m not reliably seeing that, but I’ll try fiddling with the sampling rate... maybe I’m just not looking at fine enough detail and am missing the data at at the beginning of the acceleration.

Simenzo

Posts: 3
Joined: Tue Jan 08, 2019 5:04 pm