3-Axis Digital Accelerometer(±400g) Arduino freezes

Hi,

I’m using the accelerometer with an arduino uno.
Everything works fine, but when the sensor gets a hard impact the arduino randomly freezes. After an reset, everything works again.

What could be the reason for this problem?

Thank you in advance.

Hi,

If possible, please post your sketch here. Could you please post photo of your setup ?

Thanks and Warm Regards

Hi,

i cannot post my whole sketch, but this is the code which i’m using for the sensor:

#include <H3LIS331DL.h>
#include <Wire.h>

//please get these value by running H3LIS331DL_AdjVal Sketch.
#define VAL_X_AXIS  -154
#define VAL_Y_AXIS  -646
#define VAL_Z_AXIS  -2135
H3LIS331DL h3lis;

const int ConstHighPin = 12; //5V for the Sensor

const int ConstBallDetectedThreshold = 600;

int m_LastValues[] = {0, 0, 0};

void setup()
{
  pinMode(ConstHighPin, OUTPUT);
  digitalWrite(ConstHighPin, HIGH);
  
  Serial.begin(9600);
  h3lis.init();
  h3lis.importPara(VAL_X_AXIS,VAL_Y_AXIS,VAL_Z_AXIS);
  Serial.println(h3lis.setFullScale(H3LIS331DL_FULLSCALE_2));
}

void loop()
{    
  CheckValues();
  delay(1);
}

void CheckValues()
{
  int16_t x,y,z;
  h3lis.readXYZ(&x,&y,&z);
  Serial.print(x);
  Serial.print("|");
  Serial.print(y);
  Serial.print("|");
  Serial.println(z);
  if(m_LastValues[0] == 0 && m_LastValues[1] == 0 && m_LastValues[2] == 0)
  {
    m_LastValues[0] = x;
    m_LastValues[1] = y;
    m_LastValues[2] = z;
  }
  if((abs(m_LastValues[0] - x) > ConstBallDetectedThreshold)
    ||(abs(m_LastValues[1] - y) > ConstBallDetectedThreshold) 
    ||(abs(m_LastValues[2] - z) > ConstBallDetectedThreshold))
  {
    Serial.println("Shock detected!!!");
  }
  m_LastValues[0] = x;
  m_LastValues[1] = y;
  m_LastValues[2] = z;
}

The is the setup:
Sensor- Arduino
VCC - D12
GND - GND
SDA - SDA
SCL - SCL

There are three other IO pins used, but they are only set to HIGH or LOW depending on the sensors values.

Hello,

Please power the Grove using Vcc from Arduino. Grove modules are designed to be used with Base Shield V2 or with main boads that support Grove interface.

For maximum compatibility, the sensor is powered by a LDO 2.5V. The digital interfaces (SCL and SDA) uses 5v <—> 2.5V I/O voltage convertor inbuilt.

3Axis_Acc(400).png

Thanks and Warm Regards