Showing results for 
Search instead for 
Did you mean: 

LIS2DH12 as movement sensor when the device can be oriented in any way, not just flat/parallel


I would like LIS2DH12 to fire Interrupt1 (to wake up the microcontroller) when the device is slightly moved. I have it working if the device/LIS2DH12 is laying flat parallel to the ground, moving it slightly fires the Interrupt. However, if the device the laying at a angle like 30 degrees, moving it slightly does not fire the Interrupt1. Is this not supported or somehow I need to specify the "rest state" so the movement can be compare to it? I am using Arduino IDE.

One example of code is attached below that only works if the device is laying flat initially. I have tried other examples with same results. I am not tied to a particular library. Please provide some arduino code that work!


#include <Wire.h>
#include "SparkFun_LIS2DH12.h"


int accelInterruptPin = 27;

void setup()
  Serial.println("SparkFun Accel Example");


  if (!accel.begin())
    Serial.println("Accelerometer not detected. Check address jumper and wiring. Freezing...");
    while (1);

  pinMode(accelInterruptPin, INPUT_PULLUP);

  accel.setDataRate(LIS2DH12_POWER_DOWN); //Stop measurements

  // Set INT_POLARITY to Active Low

  // Set INT1 interrupt

  // Set INT1 threshold and duration for any movement detection
  accel.setInt1Threshold(6); // Set threshold to the smallest value for any movement
  accel.setInt1Duration(9);  // Set a duration to filter out noise

  // Clear the interrupt
  while (accel.getInt1()) delay(10); // Reading int will clear it

  // Set data rate and enable interrupts
  accel.setInt1(true); // Enable interrupts on INT1 pin

  Serial.println("Begin Interrupt Scanning");
  Serial.println("Detecting any movement...");

void loop()
  // Poll for the interrupt via I2C just for testing purposes 
  if (accel.getInt1() == true) // Reading int will clear it
    Serial.println(" Movement Detected!");





So its up to you, to detect movement on "enabled axes" - depends on how you setup the chip.

Maybe the lib you use, can be set to it, as you like - just try it. (Or look in the lib, how its working and adjust it to your target.)


>Please provide some arduino code that work!

For this you should ask in Arduino Forum !

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for the quick response. The detection is enabled on all x,y,z axis. Let me rephrase the question and I don't see this any of the examples - is it possible to setup INT1 in a way where if the device starts off on a 30 degree angle and then moved slightly, the INT1 is triggered? If so, can you point me to an example in anything that you have?


I can get it to work if the device is flat/parallel to the ground, moving it in x, y or z slightly triggers INT1 but if starts out not flat to the ground then I can't get it to work. How does it know what the "rest" state is and moving it from the rest state should trigger INT1? - default of 0 makes sense but if the device is at an angle to start with, it won't be zero - is there a way to set this? For example, imagine this is in ball and the ball can be left in any orientation, then when the ball is slightly moved, INT1 should trigger. 

Federica Bossi
ST Employee

Hi @terminator_pro ,

You can refer to AN5005, at page 26, it is reported that before configuring your desired wake-up event on INT1, a dummy read of the REFERENCE register is performed to set the current/reference acceleration/tilt state against which the device performed the threshold comparison.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.