Accelerometer with Arduino

An accelerometer is a device that can detect the acceleration due to any external force such as gravity. The ADXL345 is a 3 axis accelerometer with a thirteen-bit measurement. The data which is output from the module is a digital data and is accessible through SPI or I2C digital interface.

See live demo of the project- Click here to see

The ADXL345 measures all types of static acceleration due to any force including Earth's gravitational force. This module can be used in different applications such as motion orientation sensing, etc. Tilt-sensing is the most important application of this module.

Components Required :

  • Arduino Uno Board
  • Accelerometer ADXL 345
  • Bread Board
  • Jumper Wires
  • LCD Display
Due to its high resolution(4mg/LSB), it is capable of measuring the inclination which may be less than 1.0 degrees.

Applications of accelerometer:

  • Robotics : In many of the Robotics applications, there can situation, where the standing or sliding orientation of the Robot must be determined to predict whether the Robot can proceed or not. In such cases, using accelerometer can be the best option.
  • Vibration Sensing : There are different mechanisms where the vibrations of a particular material or area should be determined. For example, an area where ICs are manufactured, should not be shock-prone, in such cases, an accelerometer can help to sense the vibration. There are infinite requirements for vibration sensing.
  • Games : Nowadays there are different games which require motion sensing. There are games such as car racing, where the gamer gets the chance to slide the car just by sliding the steering or the joystick in the physical world and the same happens on the screen.
  • Smart Vehicle : In real life, vehicles also, the accelerometer can be integrated to change some mechanism of the car using automatic road sensing. For, example, in cars which uses auto-gear, the car can shift its gear to down, when its senses an up in the road, as it requires more force when the car goes up, against gravity.
  • Virtual music Instruments : There are virtual musical instruments which can sense the orientation of hands and can automatically produce sounds as par the movement.
  • In Airplanes : The most important use of this device is in the Airplanes or Aircraft. When the aircraft flies in the air, then the only way to sense its orientation is to measure gravitational balance maintained by its different wings. In this case, an accelerometer present inside all the wings of the airplanes sends the flight stability data to the flight monitor.
  • Industry : In heavy industries such as the manufacturing of different metal related equipment such as nuts, bolts, metal pins, thread, etc. In these cases, if there is a little vibration inside drilling or cutting arm, the entire work may be destroyed or the product may turn unusable. In such cases, vibration sensing through the accelerometer plays an important role, as little or internal vibrations cannot be checked by human beings directly.
  • Earthquake detection : This device can detect an Earthquake.
  • Some other application includes Construction Works, wind force calculation, load balancing, etc.

Details of the Accelerometer: ADXL345

ADXL 345 Description:
  • Material: Gold plated PCB Board.
  • Digital Interface: I2C/ SPI.
  • Ultra-Low Power: 40 micro-ampere in measurement mode.
  • 0.1 micro-ampere in standby mode.
  • Tap/Double Tap detection
  • Free Fall Detection
Features of the ADXL 345
  • The module has 3-axis.
  • Communication means: IIC/ SPI communication protocol.
  • Measuring Range: +(-) 2g to 16g.
PIN Details of the ADXL345


  • GND : Ground (-).
  • Vcc : 5V
  • CS : Chip Select (Active high, that is, will make the chip active if CS is made HIGH).
  • INT1: Interrupt 1 Output
  • INT2 : Interrupt 2 Output.
  • SDO : Serial data Output.
  • SDA : Serial Data Input and Output.
  • SCL : Serial Communication Clock.

Pin Connections

Connecting the LCD Pins


  • Connect the Anode Pin of the LCD into the GND of the Arduino.
  • Connect the Cathode Pin of the LCD into the 5V Pin of the Arduino.
  • Connect the PIN D7 of the LCD into the PIN 13 of the Arduino.
  • Connect the PIN D6 of the LCD into the PIN 12 of the Arduino.
  • Connect the PIN D5 of the LCD into the PIN 11 of the Arduino.
  • Connect the PIN D4 of the LCD into the PIN 10 of the Arduino.
  • Connect Vss PIN of the LCD into the GND of the Arduino.
  • Connect the VDD pin of the LCD into the 5v pin of the Arduino.
  • Connect the Contrast pin of the LCD into the GND pin of the Arduino via a 10K ohm Resistor or a 10K potentiometer.
  • Connect the RS pin of the LCD to the PIN 4 of the Arduino.
  • Connect the RW pin of the LCD to the GND of the Arduino.
  • Connect the Enable pin of the Arduino to the PIN 6 of the Arduino.

Connecting the Accelerometer:


  • Connect the GND of the Sensor to the GND of the Arduino.
  • Connect the Vcc of the Sensor to the 5v pin of the Arduino.
  • Connect the CS of the Sensor to the 5v pin of the Arduino.
  • Connect the SDA pin of the Sensor to the A4 pin of the Arduino.
  • Connect the SCL pin of the Sensor to the A5 pin of the Arduino.

Edit the following program into the Arduino Editor :

#include <Wire.h>        
#include <LiquidCrystal.h>   
#define Register_ID 0    
#define Register_2D 0x2D
#define Register_X0 0x32
#define Register_X1 0x33
#define Register_Y0 0x34
#define Register_Y1 0x35
#define Register_Z0 0x36
#define Register_Z1 0x37
#define Reg_OFSX 0x1E    
#define Reg_OFSY 0x1F
#define Reg_OFSZ 0x20
#define Reg_PWR_CTL 0x2D

LiquidCrystal lcd(4, 6, 10, 11, 12, 13);  
int ADXAddress = 0xA7>>1;  
int reading = 0;
int val = 0;
int X0,X1,X_out;
int Y0,Y1,Y_out;
int Z1,Z0,Z_out;
double Xg,Yg,Zg;

void setup()
   lcd.begin(16, 2);      

void loop()
    X0 =;
    X1 =;
    X1 = X1<<8;
    X_out = X0+X1;
    Y0 =;
    Y1 =;
    Y1 = Y1<<8;
    Y_out = Y0+Y1;
    Z0 =;
    Z1 =;
    Z1 = Z1<<8;
    Z_out = Z0+Z1;
  Xg = X_out/256.00;   
  Yg = Y_out/256.00;
  Zg = Z_out/256.00;
  lcd.setCursor(0, 0); 
  lcd.print(" X="); 
  lcd.setCursor(0, 1);
  lcd.setCursor(8, 1); 
void setAccReg(int reg,byte value){
void setReg(int device,int reg,byte value){

Program Analysis :

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions