Stufin
Home Quick Cart Profile

ADXL345 Accelerometer Module (Pack of 25)

Buy Now on Stufin

Pin Configuration

  • ADXL345 Accelerometer Module (Pack of 25) Pinout Explanation
  • The ADXL345 Accelerometer Module is a small, low-power, 3-axis accelerometer that measures acceleration forces in three dimensions. It is a popular choice for IoT projects, robotics, and wearable devices. Here is a detailed explanation of the pins on the ADXL345 Accelerometer Module:
  • Pinout:
  • The ADXL345 Accelerometer Module has a total of 6 pins, which are:
  • 1. VCC (Pin 1):
  • Function: Power supply pin
  • Description: This pin should be connected to a positive voltage source (typically 3.3V or 5V) to power the module.
  • Note: Make sure to use a suitable voltage regulator if your project requires a specific voltage.
  • 2. GND (Pin 2):
  • Function: Ground pin
  • Description: This pin should be connected to the ground of your circuit or power supply.
  • 3. CSI (Pin 3):
  • Function: Chip Select pin (active low)
  • Description: This pin is used to enable or disable the SPI interface. When CSI is low, the SPI interface is enabled, and the module is ready to communicate with the microcontroller.
  • 4. SCL (Pin 4):
  • Function: Clock pin (SPI clock)
  • Description: This pin is used to provide the clock signal for the SPI interface. It is typically connected to the clock pin of your microcontroller.
  • 5. SDO (Pin 5):
  • Function: Data Out pin (SPI data output)
  • Description: This pin is used to transmit data from the ADXL345 module to the microcontroller.
  • 6. SDI (Pin 6):
  • Function: Data In pin (SPI data input)
  • Description: This pin is used to receive data from the microcontroller and configure the ADXL345 module.
  • Pin Connection Structure:
  • Here is a suggested pin connection structure for the ADXL345 Accelerometer Module:
  • Connect VCC (Pin 1) to a positive voltage source (e.g., 3.3V or 5V) using a suitable voltage regulator if necessary.
  • Connect GND (Pin 2) to the ground of your circuit or power supply.
  • Connect CSI (Pin 3) to a digital output pin on your microcontroller (e.g., Arduino's digital pin 10).
  • Connect SCL (Pin 4) to the clock pin on your microcontroller (e.g., Arduino's SCK pin).
  • Connect SDO (Pin 5) to the MOSI (Master Out Slave In) pin on your microcontroller (e.g., Arduino's MOSI pin).
  • Connect SDI (Pin 6) to the MISO (Master In Slave Out) pin on your microcontroller (e.g., Arduino's MISO pin).
  • Note:
  • Make sure to use suitable pull-up or pull-down resistors for the CSI, SCL, SDO, and SDI pins as required by your microcontroller and project requirements.
  • Always refer to the datasheet of your microcontroller and the ADXL345 module for specific pin connections and configuration guidelines.
  • Use a suitable breadboard or PCB to connect the pins, and ensure proper isolation and labeling of the connections.

Code Examples

ADXL345 Accelerometer Module Documentation
Overview
The ADXL345 Accelerometer Module is a high-resolution, low-power, 3-axis accelerometer that measures static acceleration due to gravity as well as dynamic acceleration resulting from motion, shock, or vibration. This module is suitable for a wide range of applications, including vibration monitoring, impact detection, and motion sensing.
Pinout
The ADXL345 Accelerometer Module has the following pins:
VCC: Power supply pin (operating voltage: 2.0-3.6V)
 GND: Ground pin
 SCL: I2C clock pin
 SDA: I2C data pin
 INT1/INT2: Interrupt pins
Technical Specifications
Measurement range: 2g, 4g, 8g, or 16g
 Resolution: 10-bit or 13-bit
 Noise density: 220 g/Hz
 Bandwidth: 0.5-1600 Hz
 Supply current: 40 A (typical)
Code Examples
### Example 1: Basic Acceleration Reading using Arduino
This example demonstrates how to read acceleration data from the ADXL345 Accelerometer Module using Arduino.
```c++
#include <Wire.h>
#define ADXL345_ADDRESS 0x1D // I2C address of the ADXL345
#define ADXL345_DATAREAD 0x32 // Register address for reading acceleration data
void setup() {
  Serial.begin(9600);
  Wire.begin();
}
void loop() {
  int x, y, z;
  Wire.beginTransmission(ADXL345_ADDRESS);
  Wire.write(ADXL345_DATAREAD);
  Wire.endTransmission();
  Wire.requestFrom(ADXL345_ADDRESS, 6);
  x = Wire.read() | (Wire.read() << 8);
  y = Wire.read() | (Wire.read() << 8);
  z = Wire.read() | (Wire.read() << 8);
Serial.print("Acceleration: ");
  Serial.print("X: ");
  Serial.print(x);
  Serial.print(" Y: ");
  Serial.print(y);
  Serial.print(" Z: ");
  Serial.println(z);
delay(100);
}
```
### Example 2: Motion Detection using Raspberry Pi (Python)
This example demonstrates how to use the ADXL345 Accelerometer Module to detect motion using a Raspberry Pi and Python.
```python
import smbus
import time
# Define the I2C bus and ADXL345 address
bus = smbus.SMBus(1)
ADXL345_ADDRESS = 0x1D
# Define the threshold for motion detection
THRESHOLD = 50
while True:
    # Read acceleration data from the ADXL345
    bus.write_byte(ADXL345_ADDRESS, 0x2A)
    bus.write_byte(ADXL345_ADDRESS, 0x00)  # Reset the offset registers
    data = bus.read_i2c_block_data(ADXL345_ADDRESS, 0x00, 6)
x = data[1] | (data[0] << 8)
    y = data[3] | (data[2] << 8)
    z = data[5] | (data[4] << 8)
# Calculate the magnitude of the acceleration
    magnitude = (x2 + y2 + z2)  0.5
# Check for motion
    if magnitude > THRESHOLD:
        print("Motion detected!")
    else:
        print("No motion detected.")
time.sleep(0.1)
```
### Example 3: Interrupt-based Motion Detection using ESP32 (C++)
This example demonstrates how to use the ADXL345 Accelerometer Module to detect motion using an ESP32 board and the Arduino IDE.
```c++
#include <WiFi.h>
#include <Wire.h>
#define ADXL345_ADDRESS 0x1D
#define ADXL345_INT1_PIN 2 // Interrupt pin on the ESP32
volatile bool motionDetected = false;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  pinMode(ADXL345_INT1_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(ADXL345_INT1_PIN), motionISR, RISING);
}
void loop() {
  if (motionDetected) {
    Serial.println("Motion detected!");
    motionDetected = false;
  }
  delay(100);
}
void motionISR() {
  motionDetected = true;
}
```
In this example, the ADXL345 is configured to generate an interrupt when motion is detected, and the ESP32 board is configured to handle this interrupt using an interrupt service routine (ISR). When motion is detected, the ISR sets a flag that is checked in the main loop, and if set, prints a message to the serial console.