ADXL345 Digital Accelerometer Created by William Earl Last updated on 2014-05-07 03:00:09 PM EDT
Guide Contents Guide Contents 2 Overview 4 How it Works: 4 (http://adafru.
Sensor Details: 16 Getting and Setting the operating range: 16 Getting and Setting the Data Rate: 16 Reading Sensor Events: 17 © Adafruit Industries https://learn.adafruit.
Overview The ADXL345 is a low-power, 3-axis MEMS accelerometer modules with both I2C and SPI interfaces. The Adafruit Breakout boards for these modules feature on-board 3.3v voltage regulation and level shifting which makes them simple to interface with 5v microcontrollers such as the Arduino. The ADXL345 features 4 sensitivity ranges from +/- 2G to +/- 16G. And it supports output data rates ranging from 10Hz to 3200Hz. ADXL345 datasheet (http://adafru.it/c5e) How it Works: (http://adafru.
© Adafruit Industries https://learn.adafruit.
Assembly and Wiring The board comes with all surface-mount components pre-soldered. The included header strip can be soldered on for convenient use on a breadboard or with 0.1" connectors. However, for applications subject to extreme accelerations, shock or vibration, locking connectors or direct soldering is advised. Assembly: Position the Header: Cut the header to size if necessary. Then plug the header - long pins down - into a breadboard to stabilize it for soldering.
Add the Breakout: Align the breakout board and place it over the header pins on the breadboard. And Solder! Be sure to solder all pins to assure good electrical contact. I2C Wiring: The ADXL345 Breakout has an I2C address of 0x53. It can share the I2C bus with other I2C devices as long as each device has a unique address.
© Adafruit Industries https://learn.adafruit.
Programming and Calibration Install the Library: Download the ADXL345 library (http://adafru.it/aZn) and install it. You will also need the Adafruit Sensor Library (http://adafru.it/aZm) if you do not already have it installed. This guide (http://adafru.it/aYM) will help you with the install process. Test: Click "File->Examples->Adafruit_ADXL345->sensortest" to load the example sketch from the library. Then click on the compile/upload button to compile and upload the sketch to the Arduino.
Calibrate: The ADXL chips are calibrated at the factory to a level of precision sufficient for most purposes. For critical applications where a higher degree of accuracy is required, you may wish to re-calibrate the sensor yourself. Calibration does not change the sensor outputs. But it tells you what the sensor output is for a known stable reference force in both directions on each axis. Knowing that, you can calculate the corrected output from a sensor reading. © Adafruit Industries https://learn.
Gravity as a Calibration Reference Acceleration can be measured in units of gravitational force or "G", where 1G represents the gravitational pull at the surface of the earth. Gravity is a relatively stable force and makes a convenient and reliable calibration reference for surface-dwelling earthlings. Calibration Method: To calibrate the sensor to the gravitational reference, you need to determine the sensor output for each axis when it is precisely aligned with the axis of gravitational pull.
the sides are at right angles. The material is not important as long as it is fairly rigid. Load the Calibration Sketch: Load and run the Calibration sketch below. Open the Serial Monitor and wait for the prompt. Position the Block: Place the block on a firm flat surface such as a sturdy table. Type a character in the Serial Monitor and hit return. The sketch will take a measurement on that axis and print the results.
(Hint:) For the sides obstructed by the breakout board and/or wires, press the block up against the bottom of the table while taking the reading. Calibration Results: Once all six sides have been sampled, the values printed in the Serial Monitor will represent actual measurements for +/- 1G forces on each axis. These values can be used to re-scale readings for better accuracy. Calibration Sketch: #include #include #include
/* Initialise the sensor */ if(!accel.begin()) { /* There was a problem detecting the ADXL345 ... check your connections */ Serial.println("Ooops, no ADXL345 detected ... Check your wiring!"); while(1); } } void loop(void) { Serial.println("Type key when ready..."); while (!Serial.available()){} // wait for a character /* Get a new sensor event */ sensors_event_t accelEvent; accel.getEvent(&accelEvent); if (accelEvent.acceleration.x < AccelMinX) AccelMinX = accelEvent.acceleration.x; if (accelEvent.
Type key when ready... Accel Minimums: 0.00 0.00 0.00 Accel Maximums: 0.12 0.20 1.14 Type key when ready... Accel Minimums: 0.00 0.00 0.00 Accel Maximums: 0.12 0.20 1.14 Type key when ready... Accel Minimums: 0.00 0.00 0.00 Accel Maximums: 0.12 0.20 1.14 Type key when ready... Accel Minimums: 0.00 0.00 -0.24 Accel Maximums: 0.12 1.37 1.14 Type key when ready... Accel Minimums: 0.00 0.00 -0.24 Accel Maximums: 0.12 1.37 1.14 Type key when ready... Accel Minimums: 0.00 -1.22 -0.27 Accel Maximums: 0.12 1.37 1.
Library Reference Constructor: Adafruit_ADXL345(int32_t senso rID = -1) Constructs an instance of the ADXL345 device driver object. 'sensorID' is a device identifier. It will be returned in the sensor_event in each call to getEvent(). The sensorID has no effect on the operation of the driver or device, but is useful in managing sensor events in systems with multiple sensors. Initialization() bo o l begin(vo id) The begin() function initializes communication with the device.
The setDataRate() function sets the rate at which the sensor output is updated. Rates above 100 Hz will exhibit increased noise. Rates below 6.25 Hz will be more sensitive to temperature variations. See the data sheet (http://adafru.it/c5e) for details.