Introduction: Measurement of Acceleration Using H3LIS331DL and Arduino Nano

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

H3LIS331DL, is a low-power high performance 3-axis linear accelerometer belonging to the “nano” family, with digital I²C serial interface. H3LIS331DL has user selectable full scales of ±100g/±200g/±400g and it is capable of measuring accelerations with output data rates from 0.5 Hz to 1 kHz. The H3LIS331DL is guaranteed to operate over an extended temperature range from -40 °C to +85 °C.

In this tutorial we are going to demonstrate the interfacing of H3LIS331DL with Arduino Nano.

Step 1: Hardware Required:

The materials that we need for accomplishing our goal includes the following hardware components:

1. H3LIS331DL

2. Arduino Nano

3. I2C Cable

4. I2C Shield for Arduino Nano

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the arduino nano. Ensuring correct connections is the basic necessity while working on any system for the desired output. So, the requisite connections are as follows:

The H3LIS331DL will work over I2C . Here is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you’re otherwise agnostic. All you need is four wires!

Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the help of I2C cable.

These connections are demonstrated in the pictures above.

Step 3: Arduino Code for Acceleration Measurement:

Lets start with the arduino code now.

While using the sensor module with the arduino, we include Wire.h library. "Wire" library contains the functions which facilitate the i2c communication between the sensor and the arduino board.

The entire arduino code is given below for the convenience of the user:

<p>#include<Wire.h> </p><p>// H3LIS331DL I2C address is 0x18(24)</p><p>#define Addr 0x18</p><p>void setup()</p><p>{  </p><p>// Initialise I2C communication as MASTER  </p><p>Wire.begin();  </p><p>// Initialise Serial Communication, set baud rate = 9600  </p><p>Serial.begin(9600);</p><p>// Start I2C Transmission  </p><p>Wire.beginTransmission(Addr);  </p><p>// Select control register 1  </p><p>Wire.write(0x20);  </p><p>// Enable X, Y, Z axis, power on mode, data output rate 50Hz  </p><p>Wire.write(0x27);  </p><p>// Stop I2C Transmission  </p><p>Wire.endTransmission();
  // Start I2C Transmission  </p><p>Wire.beginTransmission(Addr);  </p><p>// Select control register 4  </p><p>Wire.write(0x23);  </p><p>// Set full scale, +/- 100g, continuous update </p><p>Wire.write(0x00);  </p><p>// Stop I2C Transmission  </p><p>Wire.endTransmission();  </p><p>delay(300);</p><p>}
void loop()</p><p>{  </p><p>unsigned int data[6];  </p><p>for(int i = 0; i < 6; i++)  </p><p>{    </p><p>// Start I2C Transmission    </p><p>Wire.beginTransmission(Addr);    </p><p>// Select data register    </p><p>Wire.write((40+i));    </p><p>// Stop I2C Transmission    </p><p>Wire.endTransmission();</p><p>// Request 1 byte of data    </p><p>Wire.requestFrom(Addr, 1);    </p><p>// Read 6 bytes of data    </p><p>// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb    </p><p>if(Wire.available() == 1)    </p><p>{      </p><p>data[i] = Wire.read();    </p><p>}  </p><p>}  </p><p>delay(300);</p><p>// Convert the data </p><p>int xAccl = ((data[1] * 256) + data[0]);  </p><p>int yAccl = ((data[3] * 256) + data[2]);  </p><p>int zAccl = ((data[5] * 256) + data[4]);</p><p>// Output data to serial monitor  </p><p>Serial.print("Acceleration in X-Axis : ");  </p><p>Serial.println(xAccl);  </p><p>Serial.print("Acceleration in Y-Axis : ");  </p><p>Serial.println(yAccl);  </p><p>Serial.print("Acceleration in Z-Axis : ");  </p><p>Serial.println(zAccl);  </p><p>delay(300);</p><p>}</p>

All you need to do is burn the code in arduino and check your readings on serial port.The output is shown in the picture above.

Step 4: Applications:

Accelerometers like H3LIS331DL mostly find its application in the games and display profile switching. This sensor module is also employed in the advanced power management system for mobile applications. H3LIS331DL is a triaxial digital acceleration sensor which is incorporated with an intelligent on-chip motion triggered interrupt controller.