The ADXL345 KeyStudio is a small, thin, low-power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface. The ADXL345 is well-suited for mobile device applications. It can measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (2.0V to 3.6V) |
2 | GND | Ground |
3 | SCL/SPICLK | I2C clock line/SPI clock line |
4 | SDA/SDI | I2C data line/SPI data input |
5 | SDO | SPI data output (optional) |
6 | CS | SPI chip select (active low) |
7 | INT1 | Interrupt output 1 |
8 | INT2 | Interrupt output 2 |
#include <Wire.h>
#include <ADXL345.h>
ADXL345 adxl; // Create an instance of the ADXL345 library
void setup() {
Wire.begin(); // Join I2C bus
Serial.begin(9600); // Initialize serial communication
adxl.initADXL345(); // Initialize the ADXL345
}
void loop() {
int x, y, z;
adxl.readAccel(&x, &y, &z); // Read the accelerometer values
// Output the values to the serial monitor
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.println(z);
delay(100); // Delay for readability
}
Q: Can the ADXL345 KeyStudio be used with both 3.3V and 5V microcontrollers? A: Yes, but ensure that the VCC is within the specified range and logic level conversion is used if necessary.
Q: How can I change the range of measurement? A: The range can be set using the appropriate function in the library. Refer to the library documentation for details.
Q: What is the purpose of the INT1 and INT2 pins? A: These pins can be configured to trigger interrupts for events like free-fall, activity/inactivity, and more.
Q: How do I calibrate the ADXL345? A: Calibration involves setting offsets for the x, y, and z axes using the library functions after placing the sensor in a known orientation.
Q: Can I use multiple ADXL345 sensors on the same I2C bus? A: Yes, the ADXL345 has an alternate I2C address that can be used by connecting the SDO pin to VCC. This allows for two sensors on the same I2C bus.