Measurement of Acceleration Using ADXL345 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.

The ADXL345 is a small, thin, ultralow power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is accessible through I2 C digital interface. Itmeasures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (3.9 mg/LSB) enables measurement of inclination changes less than 1.0°.

In this tutorial the interfacing of the ADXL345 sensor module with arduino nano has been illustrated. To read the acceleration values, we have used arduino with an I2c adapter.This I2C adapter makes the connection to the sensor module easy and more reliable.

Step 1: Hardware Required:

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

1. ADXL345

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 ADXL345 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: Code for Measurement of Acceleration:

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:


// ADXL345 I2C address is 0x53(83)

#define Addr 0x53

void setup()


// Initialise I2C communication as MASTER


// Initialise serial communication, set baud rate = 9600


// Start I2C Transmission


// Select bandwidth rate register


// Normal mode, Output data rate = 100 Hz


// Stop I2C transmission


// Start I2C Transmission


// Select power control register


// Auto-sleep disable


// Stop I2C transmission


// Start I2C Transmission


// Select data format register


// Self test disabled, 4-wire interface, Full resolution, Range = +/-2g


// Stop I2C transmission



} void loop()


unsigned int data[6];

for(int i = 0; i < 6; i++)


// Start I2C Transmission


// Select data register

Wire.write((50 + i));

// Stop I2C transmission


// Request 1 byte of data

Wire.requestFrom(Addr, 1);

// Read 6 bytes of data

// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb

if(Wire.available() == 1)


data[i] =;



// Convert the data to 10-bits

int xAccl = (((data[1] & 0x03) * 256) + data[0]);

if(xAccl > 511)


xAccl -= 1024;


int yAccl = (((data[3] & 0x03) * 256) + data[2]);

if(yAccl > 511)


yAccl -= 1024;


int zAccl = (((data[5] & 0x03) * 256) + data[4]);

if(zAccl > 511)


zAccl -= 1024;


// Output data to serial monitor

Serial.print("Acceleration in X-Axis is : ");


Serial.print("Acceleration in Y-Axis is : ");


Serial.print("Acceleration in Z-Axis is : ");




In wire library Wire.write() and is used to write the commands and read the sensor output.

Serial.print() and Serial.println() is used to display the output of the sensor on the serial monitor of the Arduino IDE.

The output of the sensor is shown in the picture above.

Step 4: Applications:

ADXL345 is a small, thin, ultralow power, 3-axis accelerometer which can be employed in Handsets, Medical instrumentation etc. Its application also includes Gaming and pointing devices, Industrial instrumentation, Personal navigation devices and Hard disk drive (HDD) protection.



    • Planter Challenge

      Planter Challenge
    • Barbecue Challenge

      Barbecue Challenge
    • Classroom Science Contest

      Classroom Science Contest