ADXL345 will give your projects ability to sense the static acceleration of gravity in tilt-sensing applications plus dynamic acceleration resulting from motion or shock. High resolution of 4mg/LSB gives ability yo measure inclination changes less than 1.0 degrees.  Lets look the main Features:



  • Supply Voltage: 3.3 – 5 VDC
  • Ultra Low Power: As low as 23 uA in measurement mode, 0.1uA in standby mode at 2.5V
  • SPI or I2C Communication
  • Single Tap / Double Tap Detection
  • Activity / Inactivity Sensing
  • Free-Fall Detection

Breakout board pin function Descriptions:

Marking Description
GND Ground
Vcc Supply Voltage
CS Chip Select
INT1 Interrupt 1 Output
INT2 Interrupt 2 Output
SDO Serial Data Output (SPI 4-Wire) / I2C Address Select
SDA / SDI / SDIO / Serial Data I2C / Serial Data Input (SPI 4-WIRE) / Serial Data Input and Output (SPI 3-Wire)
SCL  SCLK / Serial Communications Clock

 

In this tutorial we will look how to connect ADXL345 with Arduino using SPI communication.

  1. Connect ADXL345 to arduino using following connection table. If you use the breakout board show in the picture above  you can use 5V as your operating voltage. For some board (sparkfun) the operating voltage is 3,3V so before connecting check your board specs:
    Arduino Pin ADXL345 Pin
    GND GND
    5V VCC
    10 CS
    12 SDO
    11 SDA
    13 SCL
  2. Next download ADXL345 sparkfun library:  https://github.com/sparkfun/SparkFun_ADXL345_Arduino_Library
  3. Import ZIP library to arduino IDE
  4. And now we will create our sketch:
    #include <SparkFun_ADXL345.h>         // SparkFun ADXL345 Library
    
    ADXL345 adxl = ADXL345(10);           // USE FOR SPI COMMUNICATION, ADXL345(CS_PIN);
    
    void setup() {
    
      Serial.begin(115200);               // Start the serial terminal
      adxl.powerOn();                     // Power on the ADXL345
    
      adxl.setRangeSetting(16);           // Give the range settings
                                          // Accepted values are 2g, 4g, 8g or 16g
                                          // Higher Values = Wider Measurement Range
                                          // Lower Values = Greater Sensitivity
    
      adxl.setSpiBit(0);                  // Configure the device to be in 4 wire SPI mode when set to '0' or 3 wire SPI mode when set to 1
                                          // Default: Set to 1
                                          // SPI pins on the ATMega328: 11, 12 and 13 as reference in SPI Library 
    
    }
    
    void loop() {
    
      // Accelerometer Readings
      int x,y,z;   
      adxl.readAccel(&x, &y, &z);         // Read the accelerometer values and store them in variables declared above x,y,z
    
      // Output Results to Serial
      
      Serial.print(x);
      Serial.print(", ");
      Serial.print(y);
      Serial.print(", ");
      Serial.println(z); 
      delay(1);
      
    }

     

  5. Upload sketch
  6. Open Serial Monitor. Now you should see the flow of accelerometer values.

For more advanced functions like freefall, tap and double tap check out SparkFun examples.

Download ADXL345 Datasheet.