ADXL345 Digital Accelerometer: Created by Bill Earl
ADXL345 Digital Accelerometer: Created by Bill Earl
ADXL345 Digital Accelerometer: Created by Bill Earl
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.
How it Works:
(https://adafru.it/c5f)MEMS - Micro Electro-Mechanical Systems
The sensor consists of a micro-machined structure on a silicon wafer. The structure is suspended by polysilicon
springs which allow it to deflect smoothly in any direction when subject to acceleration in the X, Y and/or Z axis.
Deflection causes a change in capacitance between fixed plates and plates attached to the suspended structure. This
change in capacitance on each axis is converted to an output voltage proportional to the acceleration on that axis.
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:
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. Only 4 connections are required for I2C communication:
GND->GND
VIN->+5v
SDA->SDA (Analog 4 on "Classic Arduinos")
SCL->SCL (Analog 5 on "Classic Arduinos")
The Adafruit breakout has level shifting and regulation circuitry so you can power it from 3-5V and use 3V or 5V logic
levels for i2c
This guide (https://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. You should see output
similar to below. Watch the values change as you move the board around.
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.
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. Laboratory quality calibration uses precision positioning jigs. The
method described here is simple and gives surprisingly good results with just a block of wood.
(https://adafru.it/c5g)
Repeat:
Repeat for all six sides of the block to measure the
positive and negative aspects of each axis.
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:
float AccelMinX = 0;
float AccelMaxX = 0;
float AccelMinY = 0;
float AccelMaxY = 0;
float AccelMinZ = 0;
float AccelMaxZ = 0;
void setup(void)
{
Serial.begin(9600);
Serial.println("ADXL345 Accelerometer Calibration");
Serial.println("");
void loop(void)
{
Serial.println("Type key when ready...");
while (!Serial.available()){} // wait for a character
while (Serial.available())
{
Serial.read(); // clear the input buffer
}
}
The results of the calibration sketch can be used to do a two-point calibraton as described here: Two Point
Calibration (https://adafru.it/Dva)
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()
bool begin(void)
The begin() function initializes communication with the device. The return value is 'true' if it succeeds in connecting to
the ADXL345.
Sensor Details:
void getSensor(sensor_t*);
The getSensor() function returns basic information about the sensor. For details about the sensor_t structure, refer to
the ReadMe file (https://adafru.it/aZm) for the Adafruit Sensor Library.
The setRange() function sets the operating range for the sensor. Higher values will have a wider measurement range.
Lower values will have more sensitivity.
range_t getRange(void);
The getRange() function returns the current operating range as set by setRange()
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 (https://adafru.it/c5e) for details.
dataRate_t getDataRate(void);
The getDataRate() function returns the current data rate as set by setDataRate().
The getEvent() function returns the next available reading in the form of a sensor_event. The sensor_event contains
the sensor_id as passed to the constructor as well as the X, Y and Z axis readings from the accelerometer. For more
information about sensor_events, see the ReadMe file (https://adafru.it/aZm) for the Adafruit Sensor Library.