Categories

Follow Us

LIS3DSH accelerometer sensor and Arduino example

In this example we connect a LIS3DSH sensor to an Arduino. Lets look at the sensor

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
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
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

An easy device to connect – remember its 3.3v

Arduino and LIS3DSH

Arduino and LIS3DSH

 

Code

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

#include <Wire.h>
#include <LIS3DSH.h>
 
LIS3DSH accel;
 
void setup() 
{
  Serial.begin(9600);
  Wire.begin();
  accel.enableDefault();
}
 
void loop() 
{
  int16_t x, y, z;
  int8_t temperature;
 
  accel.readAccel(&x, &y, &z);
  accel.readTemperature(&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);
}

 

Output

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

Accel X: -16041 Y: 25096 Z: 30902 T: -5
Accel X: -4264 Y: -3219 Z: -4920 T: -5
Accel X: -3665 Y: -24195 Z: -6582 T: -5
Accel X: -2387 Y: 29273 Z: 25093 T: -5
Accel X: -10046 Y: 18720 Z: 15595 T: -5
Accel X: -19708 Y: -2226 Z: 5157 T: -6
Accel X: -13490 Y: -2875 Z: -2190 T: -6
Accel X: -10057 Y: 11695 Z: 22556 T: -6
Accel X: 1924 Y: 27351 Z: 16082 T: -5
Accel X: -4231 Y: 18639 Z: 14947 T: -5
Accel X: -17774 Y: -2564 Z: 6430 T: -5
Accel X: -13527 Y: -7457 Z: 5894 T: -5
Accel X: -20130 Y: -15443 Z: 10049 T: -5
Accel X: 3386 Y: -1488 Z: 17183 T: -5
Accel X: -2989 Y: 15951 Z: 9403 T: -6
Accel X: -15118 Y: 9226 Z: 6249 T: -6

 

Link

 

Share

Leave a Reply