ADXL345 Accelerometer

Accelerometer with ADXL345 Experiment

Introduction

This experiment demonstrates how to use the ADXL345 accelerometer to measure acceleration in three axes (X, Y, Z). The data from the sensor is sent to the Arduino and displayed on the serial monitor.

ADXL345 Accelerometer

Components Needed

Circuit Setup

  1. Connect the VCC pin of the ADXL345 to the 3.3V pin on the Arduino.
  2. Connect the GND pin to GND on the Arduino.
  3. Connect the SDA pin to A4 on the Arduino (I2C data pin).
  4. Connect the SCL pin to A5 on the Arduino (I2C clock pin).

Ensure that the sensor is properly connected and powered before uploading the code.

ADXL345 Circuit Setup

Code for ADXL345 Accelerometer

Upload the following code to your Arduino to read acceleration data from the ADXL345:


#include 
#include 
#include 

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();

void setup() {
  Serial.begin(9600);
  if (!accel.begin()) {
    Serial.println("Couldn't find ADXL345 sensor");
    while (1);
  }
}

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(500);
}
            

Explanation

The ADXL345 sensor provides data for the acceleration along the X, Y, and Z axes. In the code:

Troubleshooting