Skip to content
Home > Components > Sensors > ADXL345 Accelerometer

ADXL345 Accelerometer

A precise 3-axis digital accelerometer used to measure static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock.

Component Preview

ADXL345ADXL345 Module

The ADXL345 is a popular digital accelerometer module. It communicates via I2C or SPI and provides highly accurate readings of acceleration across the X, Y, and Z axes. It is commonly used for step counting, tilt sensing in robotics, and game controllers.

SensorsI2C / SPIMotion

Overview

An accelerometer measures proper acceleration ("g-force"). Even when sitting completely still, the sensor will read roughly 1g (9.8 m/s²) straight down on the Z axis due to Earth's gravity. By analyzing the distribution of this 1g across the 3 axes, you can mathematically determine the module's exact orientation and tilt.

Pin Reference

PinTypeDescription
VCCpowerPower supply (Typically 3.3V, but many modules have a 5V regulator).
GNDpowerGround reference.
SCLinputSerial Clock (I2C SCL or SPI SCLK).
SDAdigitalSerial Data (I2C SDA or SPI MOSI).
SDOdigitalSerial Data Out (SPI MISO) / I2C Address Select (ALT ADDRESS).
CSinputChip Select. Tie HIGH for I2C, use as standard CS for SPI.
INT1outputProgrammable Interrupt 1 (e.g., tap detection, free-fall).
INT2outputProgrammable Interrupt 2.

Configurable Attributes

AttributeTypeDefaultDescription
accelXnumber0Simulated acceleration on the X axis (in m/s²).
accelYnumber0Simulated acceleration on the Y axis (in m/s²).
accelZnumber9.8Simulated acceleration on the Z axis (in m/s²). Default is 1g for gravity.

Working Principle

Inside the silicon chip is a microscopic MEMS (Micro-Electro-Mechanical System) structure. A tiny mass is suspended by springs. When acceleration occurs, the mass shifts, changing the capacitance between it and fixed plates. This change is converted into a digital 13-bit value and sent over I2C/SPI.

Wiring Diagram (I2C Mode)

  1. Connect VCC to 3.3V (or 5V if the module supports it).
  2. Connect GND to Ground.
  3. Connect SCL to the Arduino's SCL pin (A5 on Uno).
  4. Connect SDA to the Arduino's SDA pin (A4 on Uno).
  5. Tie CS to VCC to select I2C mode.
  6. Connect SDO to Ground to set the I2C address to 0x53. (Connecting to VCC sets it to 0x1D).

Wiring Diagram

Example Arduino Code

We highly recommend using the Adafruit Unified Sensor Library to handle the complex math required to convert raw data into standard SI units.

cpp
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup() {
  Serial.begin(9600);
  Serial.println("Accelerometer Test");
  
  if(!accel.begin()) {
    Serial.println("No ADXL345 detected, check your wiring!");
    while(1);
  }
  
  accel.setRange(ADXL345_RANGE_16_G);
}

void loop() {
  sensors_event_t event; 
  accel.getEvent(&event);
 
  // Display the results (acceleration is measured in m/s^2)
  Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");
  Serial.println("m/s^2 ");
  
  delay(500);
}

Simulation Notes

  • In the simulator, the module operates in I2C mode by default at address 0x53.
  • You can manually set the X, Y, and Z acceleration variables via the part attributes to test your code's tilt/motion logic without physically moving the device.

Released under the MIT License.