Documentation

ADXL345 Accelerometer 3DOF - Raspberry Pi, Arduino, ESP32 I2C Accelerometer | Klipper Tuning
Documentation / ADXL345 Accelerometer 3DOF - Raspberry Pi, Arduino, ESP32 I2C Accelerometer | Klipper Tuning

ADXL345 Accelerometer 3DOF - Raspberry Pi, Arduino, ESP32 I2C Accelerometer | Klipper Tuning

Overview

The ADXL345 is a small, ultra-low-power 3-axis accelerometer from Analog Devices that has become the de facto standard for measuring tilt, motion, vibration, and orientation. With a ±16g range, 13-bit resolution, and both I2C and SPI interfaces, it fits everywhere from quadcopters and Klipper-tuned 3D printers to motion-activated alarms and DIY pedometers.

This pre-soldered breakout exposes all 8 pins (GND, VCC, CS, INT1, INT2, SDO, SDA, SCL), tying CS and SDO appropriately for I2C operation. Power it with anything from 3V to 5V — the on-board regulator and level shifter handle either. Default I2C address is 0x53.

Beyond raw acceleration data, the ADXL345 has built-in tap detection (single and double tap), free-fall detection, and activity/inactivity interrupts — meaning you can offload motion-event detection from your microcontroller. Use it with Arduino, ESP32, Raspberry Pi, Pico, and Klipper for resonance compensation tuning.

At a Glance

Range
±2g, ±4g, ±8g, ±16g
Resolution
13-bit
Interface
I2C or SPI
Operating Voltage
3V - 5V
I2C Address
0x53 (default)
Output Rate
Up to 3200 Hz

Specifications

Parameter Value
Sensor IC Analog Devices ADXL345
Operating Voltage 3V to 5V (on-board regulator)
Operating Current 40 µA (measurement mode), 0.1 µA (standby)
Acceleration Range ±2g, ±4g, ±8g, ±16g (selectable)
Resolution 13-bit (10-bit fixed at ±2g)
Sensitivity 3.9 mg/LSB (full resolution)
Output Data Rate 0.1 Hz to 3200 Hz
Communication I2C (up to 400 kHz) or SPI (up to 5 MHz, 3 or 4-wire)
I2C Address 0x53 (SDO=GND), 0x1D (SDO=VCC)
Interrupts Tap, double-tap, free-fall, activity, inactivity
Pin Count 8 (VCC, GND, CS, INT1, INT2, SDO, SDA, SCL)
Dimensions ~22 × 18 mm

Pinout Diagram

ADXL345 3-axis accelerometer pinout diagram showing GND, VCC, CS (chip select for SPI), INT1 and INT2 (interrupt outputs), SDO (serial data out / I2C address select), SDA (I2C data), and SCL (I2C clock) pins

Wiring Guide

Arduino Wiring (I2C)

I2C uses just 4 wires. Tie CS to VCC to enable I2C mode. SDO selects address: tie to GND for 0x53 (default), or VCC for 0x1D.

ADXL345 Pin Arduino Pin
VCC 5V
GND GND
SCL A5 (SCL)
SDA A4 (SDA)
CS VCC (enables I2C mode)
SDO GND (address 0x53)
INT1, INT2 Optional — connect to digital pin if using interrupts

ESP32 Wiring (I2C)

ESP32 default I2C is on GPIO 21 (SDA) and GPIO 22 (SCL).

ADXL345 Pin ESP32 Pin
VCC 3.3V
GND GND
SCL GPIO 22
SDA GPIO 21
CS 3.3V
SDO GND

Raspberry Pi Wiring (I2C)

Enable I2C with raspi-config. Default I2C is BCM 2 (SDA) and BCM 3 (SCL). For Klipper resonance tuning, the same wiring applies — Klipper's klippy_extras.adxl345 module reads it over I2C.

ADXL345 Pin Raspberry Pi Pin
VCC Pin 1 (3.3V)
GND Pin 6 (GND)
SCL Pin 5 (BCM 3)
SDA Pin 3 (BCM 2)
CS 3.3V
SDO GND
Info: For Klipper's input shaper tuning, you'll typically wire the ADXL345 over SPI (faster) instead of I2C. Connect the SPI bus instead and reference the Klipper docs.

Raspberry Pi Pico Wiring (I2C)

Default I2C0 on Pico: SDA on GP4, SCL on GP5.

ADXL345 Pin Pico Pin
VCC 3V3
GND GND
SCL GP5
SDA GP4
CS 3V3
SDO GND

Code Examples

Arduino — Adafruit ADXL345 Library

adxl345_arduino.ino
// ADXL345 - Read X/Y/Z acceleration
// Library: Adafruit ADXL345 (Library Manager) — pulls in Adafruit Unified Sensor

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

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup() {
  Serial.begin(9600);
  if (!accel.begin()) {
    Serial.println("ADXL345 not detected!");
    while (1) {}
  }
  accel.setRange(ADXL345_RANGE_16_G);
}

void loop() {
  sensors_event_t event;
  accel.getEvent(&event);
  Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" m/s^2  ");
  Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" m/s^2  ");
  Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2");
  delay(100);
}

Raspberry Pi (Python)

adxl345_rpi.py
#!/usr/bin/env python3
# ADXL345 - Raspberry Pi Python Example
# Install: sudo pip3 install adafruit-circuitpython-adxl34x

import time
import board
import adafruit_adxl34x

i2c = board.I2C()
accel = adafruit_adxl34x.ADXL345(i2c)

while True:
    x, y, z = accel.acceleration
    print(f"X: {x:6.2f}  Y: {y:6.2f}  Z: {z:6.2f}  m/s^2")
    time.sleep(0.1)

Raspberry Pi Pico (MicroPython)

adxl345_pico.py
# ADXL345 - Pico MicroPython
# Library: micropython-adxl345 from PyPI or copy adxl345.py manually.

from machine import Pin, I2C
import adxl345
import time

i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400_000)
accel = adxl345.ADXL345(i2c)

while True:
    x, y, z = accel.x, accel.y, accel.z
    print("X={:6.2f}  Y={:6.2f}  Z={:6.2f}".format(x, y, z))
    time.sleep_ms(100)

Frequently Asked Questions

What I2C address does the ADXL345 use?
Default is 0x53 when SDO is tied to GND. If you tie SDO to VCC, the address becomes 0x1D — useful when you want two ADXL345s on the same bus. Verify with i2cdetect (Pi) or an Arduino I2C scanner sketch.
Why am I getting noisy readings?
Three common reasons: (1) the sensor is mechanically loose — secure it with double-stick tape or screws. (2) The output data rate is too high, picking up vibration noise — try setSampleRate to 100 Hz or lower. (3) The supply voltage is unstable — add a 0.1 µF decoupling capacitor across VCC and GND close to the chip.
Can the ADXL345 detect taps and gestures?
Yes. The chip has dedicated registers for single-tap, double-tap, free-fall, and activity/inactivity detection. Configure the threshold and duration registers, then read the INT1 or INT2 pin to know when a tap occurred — your MCU doesn't have to poll continuously. The Adafruit_ADXL345 library exposes these via setTapAxis() and similar methods.
Is this suitable for Klipper resonance tuning?
Yes — the ADXL345 is the recommended IMU for Klipper's input shaper. Wire it via SPI for the highest sample rate (3200 Hz) and follow the Klipper "Measuring Resonances" documentation. The included pre-soldered headers make this much easier than the bare AdaFruit module.
What's the difference between I2C and SPI here?
I2C is simpler (4 wires) and adequate up to about 800 Hz output rate. SPI is faster (5 MHz vs 400 kHz I2C) and lets you reach the maximum 3200 Hz sample rate. For motion-event detection (taps, free fall), I2C is plenty. For vibration analysis or Klipper, prefer SPI.
How do I calculate tilt or orientation from raw data?
For static tilt, use atan2() to compute pitch and roll from the X/Y/Z components: pitch = atan2(-X, sqrt(Y² + Z²)) and roll = atan2(Y, Z). For dynamic orientation (with rotation), you need a 6- or 9-axis IMU like the MPU6050 or MPU9250. The ADXL345 is gravity-only — no gyroscope.
Does it work at 5V or only 3.3V?
The ADXL345 chip itself is strictly 3.3V, but this breakout has a 5V-tolerant on-board regulator and level shifter. So you can connect VCC to either 3.3V or 5V without worrying about the chip itself. The I2C lines (SDA/SCL) are also level-shifted on the breakout, so connecting to 5V Arduino is safe.

Related Tutorials