The ADXL345 is a 3-axis digital accelerometer that can measure acceleration in the X, Y, and Z axes. Unlike the ADXL335, which provides analog outputs, the ADXL345 has digital output via I2C or SPI communication protocols, which makes it easier to interface with most modern microcontrollers like Arduino or Raspberry Pi.
Key Features of the ADXL345 Module:
- 3-Axis Measurement:
- It measures acceleration along the X, Y, and Z axes.
- It is capable of detecting both static acceleration (like gravity) and dynamic acceleration (like vibrations or movement).
- Digital Output:
- The ADXL345 uses I2C (default) or SPI communication to transfer data, making it easier to interface with microcontrollers.
- Data is sent as 16-bit values representing the acceleration in each axis.
- Measurement Range:
- The sensor can be configured for different measurement ranges: ±2g, ±4g, ±8g, and ±16g.
- The choice of range determines the sensitivity of the sensor (higher g ranges provide lower sensitivity but wider ranges for detecting larger accelerations).
- Resolution:
- It provides a 10-bit resolution for acceleration data (with 2's complement format), which allows for precise measurements.
- The sensor can detect small changes in acceleration based on the chosen range.
- Low Power Consumption:
- It operates at a low current of around 23 µA in measurement mode, and it features a power-saving mode that can further reduce power consumption when not in use.
- Output Rate:
- The ADXL345 can operate at a maximum data rate of 3200 Hz. The data rate can be configured for different applications depending on the requirements.
- Built-in Features:
- Free-fall detection, tap detection, and activity/inactivity sensing. These built-in features allow for specialized applications like motion detection, triggering actions based on user taps, or detecting free-fall events.
- Size:
- The module is small, typically available in a compact 3.2mm x 5mm package, and is available as a breakout board with headers for easy integration into your projects.
Pinout: The ADXL345 comes in a module format that typically includes the following pins:
- VCC: Power supply pin (typically 3.3V or 5V depending on your system).
- GND: Ground pin.
- SDA: Serial Data line (I2C interface) or MOSI (SPI interface).
- SCL: Serial Clock line (I2C interface) or SCK (SPI interface).
- CS: Chip Select (for SPI interface).
- SDO: Serial Data Output (used for I2C or SPI communication).
- INT1/INT2: Interrupt pins used for triggering actions based on certain conditions (e.g., tap detection, activity/inactivity).
Communication Interfaces:
- I2C Interface (default):
- SDA (Data line) and SCL (Clock line).
- I2C allows multiple devices to communicate over the same bus using unique addresses.
- SPI Interface:
- MOSI, MISO, SCK, and CS are used for SPI communication.
- SPI offers faster data transfer speeds than I2C, but requires more pins for communication.
Accelerometer Output:
The output data from the ADXL345 is 16-bit, where the values represent the acceleration in g (acceleration due to gravity). The digital output is stored in registers and can be accessed via I2C or SPI. For example, the raw data for each axis (X, Y, and Z) can be read and converted to a meaningful acceleration value based on the selected range.
Output Sensitivity:
The output sensitivity depends on the range you select for the sensor. For each selected range, there is a corresponding sensitivity factor:
- ±2g range: 256 LSB/g (Least Significant Bits per g)
- ±4g range: 128 LSB/g
- ±8g range: 64 LSB/g
- ±16g range: 32 LSB/g
For example, with a ±2g range, a value of 256 LSB would correspond to 1g of acceleration. The higher the range, the less sensitive the sensor is, but it can detect higher accelerations.
Example Connections to Arduino (I2C):
To use the ADXL345 with an Arduino using I2C communication:
- VCC (ADXL345) to 5V or 3.3V (Arduino)
- GND (ADXL345) to GND (Arduino)
- SDA (ADXL345) to A4 (Arduino) – Data line (I2C)
- SCL (ADXL345) to A5 (Arduino) – Clock line (I2C)
- CS (ADXL345) to 3.3V (to select I2C mode)
- SDO (ADXL345) to GND (optional, for setting I2C address)
Sample Code (Arduino I2C):
#include <Wire.h>
const int ADXL345_ADDRESS = 0x53; // I2C address for ADXL345
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize ADXL345
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x2D); // Power control register
Wire.write(0x08); // Set to measure mode
Wire.endTransmission();
}
void loop() {
// Read acceleration data from the ADXL345
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x32); // Starting address for X-axis data
Wire.endTransmission(false);
Wire.requestFrom(ADXL345_ADDRESS, 6); // Read 6 bytes of data (2 for each axis)
// Extract the raw data for X, Y, and Z axes
int x = Wire.read() | (Wire.read() << 8);
int y = Wire.read() | (Wire.read() << 8);
int z = Wire.read() | (Wire.read() << 8);
// Print the raw data (accelerations in raw counts)
Serial.print("X: ");
Serial.print(x);
Serial.print(" Y: ");
Serial.print(y);
Serial.print(" Z: ");
Serial.println(z);
delay(500); // Delay before next reading
}
Calibration:
To get accurate acceleration values, the ADXL345 should be calibrated, especially if you require precise measurements. Calibration might involve adjusting for offsets and scaling factors based on the sensor’s range and the specific application.
Applications:
- Motion Sensing: Detecting movement in robotics, drones, or mobile devices.
- Tilt Sensing: Used in devices like orientation-sensitive displays, level detection, and tilt-controlled toys.
- Vibration Monitoring: Monitoring vibrations in machinery or infrastructure.
- Gesture Recognition: Recognizing gestures for user interface control (e.g., shaking, tapping).
- Free-fall Detection: Identifying when a device experiences free-fall, often used in devices like hard drives to protect against damage during drops.
Advantages of ADXL345:
- Digital Output: Simplifies integration with microcontrollers, reducing the need for analog-to-digital conversion.
- Low Power: Ideal for battery-powered devices and low-power applications.
- Multiple Range Options: Flexible for different levels of sensitivity and applications.
- Built-in Features: Tap detection, free-fall detection, and motion sensing help offload some computation to the sensor, which is useful in embedded systems.
Brand: Generic
Origin: China