# SparkFun Qwiic 3-Axis Accelerometer (ADXL313) Hookup Guide

Pages
Contributors: Santa Claus Impersonator, QCPete

## Arduino Examples

### Example 1: Basic Readings

Once you've got the library installed, open the Example1 Basic Readings sketch. You can find it under

File > Examples > SparkFun ADXL313 Arduino Library > Examples


Then load it onto your RedBoard or Uno. Open your favorite Serial Terminal to see the printed values.

Raw data readings for ADXL313. (Click to enlarge)

This example outputs the raw acceleration values read by the sensor. To convert the values, use the following equation.

In this example, g-range = 2 and the resolution = 10-bits = 1024; therefore the measured acceleration (g's):

### Example 3: Auto. Sleep

Open the Example3 Autosleep sketch, and load it onto your RedBoard or Uno.

Raw data readings with indicators for when the sensor detects inactivity and enters auto-sleep. (Click to enlarge)

After the sensor detects inactivity for more than 5 seconds, it will automatically enter sleep mode and stop recording data into the FIFO. This conserves power to the accelerometer.

Note: The senor has to be relatively flat on the x-axis in order for it to enter sleep mode. Therefore, users may need to play with a level if their desk isn't level or flat.

Otherwise, users can change the threshold on line 73: myAdxl.setActivityThreshold(10); // 0-255 (62.5mg/LSB) to a higher value, like 40 to increase the inactivity threshold. This means the sensor doesn't have to lie precisely flat, but also means that the sensor requires more acceleration to wake up as well.

### Example 6: Interrupt

Note: For this example to work, the microcontroller's interrupt pin needs to be connected to the Qwiic ADXL313. Make sure that this pin is also designated in the code. For the RedBoard Qwiic, Pin 2 can operate as an interrupt and is coded by default in the example.

Wiring between ADXL313 and microcontroller for the interrupt functionality. (Click to enlarge)

Close up of the wiring at the microcontroller. (Click to enlarge)

Close up of the wiring at the ADXL313 interrupt pin. (Click to enlarge)

Once the interrupt pin has been wired up, open the Example6 Interrupt sketch, and load it onto your RedBoard or Uno.

Let the sensor sit still, flat on a table to enter sleep mode. While, shaking the accelerometer will trigger the interrupt on the microcontroller for start reading data. Lying the accelerometer flat and still, will discontinue the sensor readings and put it into sleep mode again.

Waking the microcontroller.