Using Adafruit LIS3DH with MKR ZERO to define different G levels

I am currently trying to use the tap demo from the Arduino Examples for the LIS3DH to indicate if the board was picked up, dropped, or “fired”. My end result is to test if a nail gun was either picked up, dropped, or fired (plus other data with other sensors).

My questions:

  1. Can I define multiple click thresholds corresponding to the different G levels felt by the board? (I believe I did this already but not sure if I did it correct)

  2. In the if statements within the void loop function, what do the click & 0x10, 0x20, and 0x30 mean? I figured they are a type of address but I am unsure how I could use these to do the project idea up top.

  3. Should I just use the normal acceleration information from the accel demo to do what I want? Maybe both?

Thank you for any help!
(I’m also using the Arduino MKR Zero board and Arduino IDE to code)

Code In Questions Below:
(Defining the different thresholds)
#define CLICKTHRESHHOLD1 5 //testing for 16G (firing)
#define CLICKTHRESHHOLD2 30 //testing for 4G (droping)
#define CLICKTHRESHHOLD3 60 //testing for 2G (picking up)

(Creating the different clicks)
lis.setClick(2, CLICKTHRESHHOLD1);
lis.setClick(2, CLICKTHRESHHOLD2);
lis.setClick(2, CLICKTHRESHHOLD3);

The Loop from Question 2:
void loop() {
uint8_t click = lis.getClick();
if (click == 0) return;
if (! (click & 0x30)) return;
Serial.print(“Click detected (0x”); Serial.print(click, HEX); Serial.print("): “);
if (click & 0x10) Serial.print(” single click");
if (click & 0x20) Serial.print(" double click");




Welcome to the forums. Please read the sticky posts at the top of the forum to learn how to properly post your code using code tags. It will help people help you.

As for your code, calling setClick() multiple times does not create a new level. It overwrites the previous value with the new value.

As for those values you are comparing to click, they are HEX values which are basically specifying a single bit to test within click.

0x10 = 0001 0000 (binary) so you are OR'ing that with the 4th bit of click to see if it is set or not.

Apparently, if that bit is set, it indicates a single click.

0x20 = 0010 0000 so that is testing the next bit to the left and if that is set, it indicates a double click

0x30 = 0011 000 so that means they were both set which seems to be an error and is ignored.

Thank you!

I'm curious if I can use those HEX values to define different tap points? Like set a certain hex value to Picking/Dropping/Firing and the program would read out if it was one of those three options. My only concern is that the accelerometer feels the same G force for picking up and dropping, so I need to figure out how to determine a difference.

Let me know if this makes sense.


You can't have this device trigger at multiple different levels. You will have to collect the data as your nail gun is picked up/dropped/fired to see what values represent those events