The ADXL345 is a compact, low-power, 3-axis accelerometer that provides high-resolution (13-bit) measurements of acceleration in up to ±16 g ranges. This MEMS sensor is designed by Analog Devices and is widely used in various applications such as mobile devices, gaming systems, personal health devices, and inertial navigation systems where tilt and motion sensing is required.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (2.0V to 3.6V) |
2 | GND | Ground |
3 | CS | Chip select for SPI interface (active low) |
4 | INT1 | Interrupt output 1 |
5 | INT2 | Interrupt output 2 |
6 | SDO | Serial data output for SPI; alternate address for I2C |
7 | SDA | Serial data for I2C; serial data input for SPI |
8 | SCL | Serial clock for I2C; serial clock input for SPI |
Q: Can the ADXL345 be used with an Arduino? A: Yes, the ADXL345 can be easily interfaced with an Arduino using either I2C or SPI.
Q: What is the purpose of the CS pin? A: The CS pin is used to select the ADXL345 when using SPI communication. It must be driven low to enable the device.
Q: How can I change the measurement range of the ADXL345? A: The measurement range can be changed by configuring the DATA_FORMAT register.
Q: What is the maximum sampling rate of the ADXL345? A: The maximum sampling rate (ODR) of the ADXL345 is 3200 Hz.
Below is an example of how to interface the ADXL345 with an Arduino UNO using I2C:
#include <Wire.h>
#include <ADXL345.h>
ADXL345 accelerometer;
void setup() {
Serial.begin(9600);
Wire.begin(); // Initialize I2C
if (!accelerometer.begin()) {
Serial.println("Could not find a valid ADXL345 sensor, check wiring!");
while (1);
}
// Set measurement range to ±16g
accelerometer.setRange(ADXL345_RANGE_16_G);
}
void loop() {
// Read the acceleration values
sensors_event_t event;
accelerometer.getEvent(&event);
// Display the results (acceleration is measured in m/s^2)
Serial.print("X: ");
Serial.print(event.acceleration.x);
Serial.print(" m/s^2, Y: ");
Serial.print(event.acceleration.y);
Serial.print(" m/s^2, Z: ");
Serial.print(event.acceleration.z);
Serial.println(" m/s^2");
delay(500);
}
Note: This code assumes the use of the ADXL345
library, which provides the ADXL345
class and related methods for interacting with the sensor. Make sure to install the library through the Arduino IDE before compiling the code.