October 18, 2024

ADXL345 Accelerometer Interface With Arduino


The ADXL345 is a small, thin, low-power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g [1, 2].


Components Required:
  • ADXL345 Accelerometer 
  • Arduino
  • Jumper Wires
  • Power Supply / Data Cable

Connection Diagram:

Before you upload the code library needs to be installed. Please follow the below-mentioned instructions to install the library.

https://creativestudio1973.blogspot.com/2019/11/introduction-to-arduino-library-manager.html

Source Code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
Adafruit_ADXL345_Unified accel;
void setup(void)
{
Serial.begin(9600);
Serial.println("Accelerometer Test");
if(!accel.begin())
{
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
accel.setRange(ADXL345_RANGE_16_G);
// accel.setRange(ADXL345_RANGE_8_G);
// accel.setRange(ADXL345_RANGE_4_G);
// accel.setRange(ADXL345_RANGE_2_G);
}
void loop(void)
{
sensors_event_t event;
accel.getEvent(&event);
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);
}



 Video:

Reference:
[1] https://www.analog.com/en/products/adxl345.html#part-details
[2] https://www.analog.com/media/en/technical-documentation/data-sheets/adxl345.pdf