LIS3DSH accelerometer sensor and an ESP32

In this example we connect a LIS3DSH sensor to an ESP32.

The LIS3DSH is an ultra-low-power high-performance three-axis linear accelerometer belonging to the “nano” family with an embedded state machine that can be programmed to implement autonomous applications.

The LIS3DSH has dynamically selectable full scales of ±2g/±4g/±6g/±8g/±16g and is capable of measuring accelerations with output data rates from 3.125 Hz to 1.6 kHz. The self-test capability allows the user to check the functioning of the sensor in the final application. The device can be configured to generate interrupt signals activated by user-defined motion patterns.

The LIS3DSH has an integrated first-in, first-out (FIFO) buffer allowing the user to store data in order to limit intervention by the host processor. The LIS3DSH is available in a small thin plastic land grid array package (LGA) and is guaranteed to operate over an extended temperature range from -40 °C to +85 °C.

Key Features

  • Wide supply voltage, 1.71 V to 3.6 V
  • Independent IOs supply (1.8 V) and supply voltage compatible
  • Ultra-low power consumption
  • ±2g/±4g/±6g/±8g/±16g dynamically selectable full scale
  • I2C/SPI digital output interface
  • 16-bit data output
  • Programmable embedded state machines
  • Embedded temperature sensor
  • Embedded self-test
  • Embedded FIFO
  • 10000 g high shock survivability

 

Parts List

Part Link
ESP32 New ESP-32 esp32 Lite V1.0.0 For Rev1 wifi Module + bluetooth board 4MB FLASH
LIS3DSH module CJMCU- LIS3DSH High-resolution Three-axis Accelerometer Triaxial Accelerometer Module LIS3DH
Connecting Wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Connection

ESP32 and LIS3DSH
ESP32 and LIS3DSH

 

Code

You need to download and install the https://github.com/yazug/LIS3DSH library

<pre>#include &lt;Wire.h&gt;
#include &lt;LIS3DSH.h&gt;

LIS3DSH accel;

void setup() 
{
  Serial.begin(9600);
  Wire.begin();
  accel.enableDefault();
}

void loop() 
{
  int16_t x, y, z;
  int8_t temperature;

  accel.readAccel(&amp;x, &amp;y, &amp;z);
  accel.readTemperature(&amp;temperature);

  Serial.print("Accel ");
  Serial.print("X: ");
  Serial.print(x);
  Serial.print(" Y: ");
  Serial.print(y);
  Serial.print(" Z: ");
  Serial.print(z);
  Serial.print(" T: ");
  Serial.println(temperature);

  delay(100);
}</pre>

 

Output

Open the serial monitor and you should see something like this – move the module around

Accel X: 361 Y: 5144 Z: 15700 T: -9
Accel X: 409 Y: 5094 Z: 15698 T: -9
Accel X: 365 Y: 5166 Z: 15672 T: -9
Accel X: 377 Y: 5157 Z: 15667 T: -9
Accel X: 1787 Y: -6196 Z: 31329 T: -9
Accel X: 8636 Y: 2808 Z: 15889 T: -9
Accel X: -12408 Y: 5444 Z: -16233 T: -9
Accel X: 8588 Y: 27588 Z: 19617 T: -9
Accel X: 9702 Y: 25909 Z: 522 T: -9
Accel X: -15119 Y: 6115 Z: -19391 T: -9
Accel X: 12926 Y: -3281 Z: 5542 T: -9
Accel X: 4313 Y: -32032 Z: 32757 T: -9
Accel X: -7917 Y: 8240 Z: 20966 T: -9

 

Link

 

SHARE
Previous articlePCA9685 LED controller and ESP32 example
Next articleBeginners Micropython example – flash an LED