

The ADXL345 is a small, thin, low-power, 3-axis accelerometer capable of high-resolution (13-bit) measurements at up to ±16g. It is designed for applications requiring precise motion sensing, tilt detection, and gesture recognition. The device supports both I2C and SPI communication protocols, making it versatile and easy to integrate into a wide range of systems.








The ADXL345 has 14 pins. Below is the pinout and description:
| Pin | Name | Description |
|---|---|---|
| 1 | VDD | Power supply input (2.0V to 3.6V). |
| 2 | GND | Ground. |
| 3 | CS | Chip Select. Used to select SPI (active low). Tie high for I2C mode. |
| 4 | INT1 | Interrupt 1 output. Configurable for various interrupt events. |
| 5 | INT2 | Interrupt 2 output. Configurable for various interrupt events. |
| 6 | SCL/SCLK | Serial clock line for I2C or SPI. |
| 7 | SDA/SDI/SDO | Data line for I2C or SPI. |
| 8 | NC | No connection. Leave unconnected. |
| 9-14 | NC | No connection. Leave unconnected. |
#include <Wire.h> // Include the Wire library for I2C communication
#define ADXL345_ADDRESS 0x53 // I2C address of the ADXL345
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Initialize the ADXL345
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x2D); // Power control register
Wire.write(0x08); // Set the device to measurement mode
Wire.endTransmission();
// Set data format to ±2g and full resolution
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x31); // Data format register
Wire.write(0x08); // Full resolution, ±2g
Wire.endTransmission();
}
void loop() {
int16_t x, y, z;
// Request 6 bytes of data from the ADXL345 (X, Y, Z axes)
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x32); // Start reading from the DATAX0 register
Wire.endTransmission(false);
Wire.requestFrom(ADXL345_ADDRESS, 6);
if (Wire.available() == 6) {
x = Wire.read() | (Wire.read() << 8); // Combine low and high bytes for X-axis
y = Wire.read() | (Wire.read() << 8); // Combine low and high bytes for Y-axis
z = Wire.read() | (Wire.read() << 8); // Combine low and high bytes for Z-axis
}
// Print the accelerometer readings
Serial.print("X: "); Serial.print(x);
Serial.print(" Y: "); Serial.print(y);
Serial.print(" Z: "); Serial.println(z);
delay(500); // Delay for readability
}
No Communication with the ADXL345:
Incorrect or No Data:
High Noise in Readings: