Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use ADXL345: Examples, Pinouts, and Specs

Image of ADXL345Design with ADXL345 in Cirkit Designer

Introduction

The ADXL345 is a small, thin, low-power, 3-axis accelerometer with a digital output. It is capable of measuring acceleration in three dimensions (X, Y, and Z axes) with high resolution (13-bit) and a wide measurement range of ±2 g, ±4 g, ±8 g, or ±16 g. The device communicates via I²C or SPI interfaces, making it versatile and easy to integrate into a variety of systems.

Explore Projects Built with ADXL345

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino UNO and ADXL345 Accelerometer Data Logger: A project utilizing ADXL345 in a practical application
Arduino UNO and ADXL345 Accelerometer Data Logger

This circuit features an Arduino UNO microcontroller interfaced with an Adafruit ADXL345 accelerometer for motion detection, powered by two parallel-connected 18650 Li-ion batteries. The accelerometer communicates with the Arduino over I2C, and the system is designed for further code development to utilize the motion sensing capabilities.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

The ADXL345 is designed for low-power operation and high performance. Below are its key technical details:

Parameter Value
Supply Voltage (VDD) 2.0 V to 3.6 V
I/O Voltage (VDDIO) 1.7 V to VDD
Measurement Range ±2 g, ±4 g, ±8 g, ±16 g
Resolution 13-bit
Communication Interface I²C (up to 400 kHz) or SPI (up to 5 MHz)
Power Consumption 40 µA in measurement mode, 0.1 µA in standby
Operating Temperature Range -40°C to +85°C
Dimensions 3 mm × 5 mm × 1 mm (L × W × H)

Pin Configuration and Descriptions

The ADXL345 is typically available in a 14-pin LGA package. Below is the pinout and description:

Pin Name Description
1 VDD Power supply (2.0 V to 3.6 V)
2 GND Ground
3 CS Chip Select (SPI mode) or I²C Address Select
4 INT1 Interrupt 1 output
5 INT2 Interrupt 2 output
6 SCL/SCLK I²C Clock / SPI Serial Clock
7 SDA/SDI/SDO I²C Data / SPI Data In / Data Out
8-14 NC No Connect (leave unconnected)

Usage Instructions

How to Use the ADXL345 in a Circuit

  1. Power Supply: Connect the VDD pin to a 3.3 V power source and the GND pin to ground.
  2. Communication Interface: Choose between I²C or SPI:
    • For I²C, connect the SCL and SDA pins to the corresponding I²C lines on your microcontroller.
    • For SPI, connect the SCLK, SDI, and CS pins to the SPI lines on your microcontroller.
  3. Interrupts: Use the INT1 and INT2 pins to handle interrupts for specific events (e.g., free-fall detection, activity detection).
  4. Pull-Up Resistors: For I²C communication, use pull-up resistors (typically 4.7 kΩ) on the SCL and SDA lines.
  5. Bypass Capacitor: Place a 0.1 µF ceramic capacitor close to the VDD pin for power supply decoupling.

Important Considerations and Best Practices

Example Code for Arduino UNO

Below is an example of how to interface the ADXL345 with an Arduino UNO using I²C:

#include <Wire.h> // Include the Wire library for I²C communication

#define ADXL345_ADDRESS 0x53 // I²C address of the ADXL345
#define POWER_CTL 0x2D       // Power control register
#define DATA_FORMAT 0x31     // Data format register
#define DATAX0 0x32          // X-axis data register (low byte)

// Function to initialize the ADXL345
void setupADXL345() {
  Wire.begin(); // Initialize I²C communication
  Wire.beginTransmission(ADXL345_ADDRESS);
  Wire.write(POWER_CTL); // Select the power control register
  Wire.write(0x08);      // Set the device to measurement mode
  Wire.endTransmission();

  Wire.beginTransmission(ADXL345_ADDRESS);
  Wire.write(DATA_FORMAT); // Select the data format register
  Wire.write(0x01);        // Set range to ±4 g
  Wire.endTransmission();
}

void setup() {
  Serial.begin(9600); // Initialize serial communication
  setupADXL345();     // Initialize the ADXL345
}

void loop() {
  int16_t x, y, z;

  // Read X-axis data
  Wire.beginTransmission(ADXL345_ADDRESS);
  Wire.write(DATAX0); // Request starting from the X-axis low byte
  Wire.endTransmission(false);
  Wire.requestFrom(ADXL345_ADDRESS, 6); // Request 6 bytes (X, Y, Z)

  if (Wire.available() == 6) {
    x = Wire.read() | (Wire.read() << 8); // Combine low and high bytes
    y = Wire.read() | (Wire.read() << 8);
    z = Wire.read() | (Wire.read() << 8);
  }

  // Print the acceleration values
  Serial.print("X: "); Serial.print(x);
  Serial.print(" Y: "); Serial.print(y);
  Serial.print(" Z: "); Serial.println(z);

  delay(500); // Wait for 500 ms
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Communication with the ADXL345

    • Cause: Incorrect I²C address or wiring.
    • Solution: Verify the I²C address (default is 0x53) and check all connections.
  2. Incorrect or No Data Output

    • Cause: Device not in measurement mode.
    • Solution: Ensure the POWER_CTL register is set to enable measurement mode.
  3. High Noise in Readings

    • Cause: Poor power supply decoupling or mechanical vibrations.
    • Solution: Add a 0.1 µF capacitor near the VDD pin and minimize external vibrations.
  4. Interrupts Not Triggering

    • Cause: Interrupts not configured correctly.
    • Solution: Verify the interrupt configuration registers and ensure the INT1/INT2 pins are connected.

FAQs