Measurement of Acceleration Using ADXL345 and Particle Photon

Introduction: Measurement of Acceleration Using ADXL345 and Particle Photon

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 particle photon has been illustrated. To read the acceleration values, we have used particle 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. Particle Photon

3. I2C Cable

4. I2C Shield for particle photon

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the particle photon. 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 particle code now.

While using the sensor module with the particle, we include application.h and spark_wiring_i2c.h library. "application.h" and spark_wiring_i2c.h library contains the functions which facilitate the i2c communication between the sensor and the particle.

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



// ADXL345 I2C address is 0x53(83)

#define Addr 0x53

int xAccl = 0, yAccl = 0, zAccl = 0;

void setup()


// Set variable





// Initialise I2C communication as MASTER


// Initialise serial communication, set baud rate = 9600


// Start I2C transmission


// Select bandwidth rate register


// Select output data rate = 100 Hz


// Stop I2C Transmission


// Start I2C transmission


// Select power control register


// Select auto sleep disable


// Stop I2C transmission


// Start I2C transmission


// Select data format register


// Select full resolution, +/-2g


// End I2C transmission




void loop()


unsigned int data[6];

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


// Start I2C transmission


// Select data register


// Stop I2C transmission


// Request 1 byte of data from the device


// Read 6 bytes of data

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



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 dashboard

Particle.publish("Acceleration in X-Axis is :", String(xAccl));

Particle.publish("Acceleration in Y-Axis is :", String(yAccl));

Particle.publish("Acceleration in Z-Axis is :", String(zAccl));


Particle.variable() function creates the variables to store the output of the sensor and Particle.publish() function displays the output on the dashboard of the site.

The sensor output is shown in the picture above for your reference.

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.

Be the First to Share


    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge
    • Paint Challenge

      Paint Challenge
    • Unusual Uses Contest

      Unusual Uses Contest