ADXL345 Accelerometer With Arduino UNO: Types of Accelerometer Sensors
ADXL345 Accelerometer With Arduino UNO: Types of Accelerometer Sensors
ADXL345 Accelerometer With Arduino UNO: Types of Accelerometer Sensors
UNO
ARDUINO
We used the accelerometer to build various useful applications which you can check at
below links:
Types of Accelerometer Sensors
There are many types of MEMS accelerometer sensors available in the market. They can be
classified on the basis of precision, power consumption, and interfacing. All these sensors
are portable and can be fitted in any kind of device like wearables. These sensors measure
acceleration in 3-axis (x,y,z).
1. ADXL335
2. ADXL345
3. ADXL356
These accelerometer sensors are very popular and apart from these three, there are many
other accelerometer sensors like ADXL354, ADXL355, ADXL372, etc.
Low Low
Power Standard
Typical: Typical:
Consumption Typical: 350µ
150µ 140µ
Pricing High Low Lowest
Among the above three, ADXL345 is easy to interface because of its digital nature. But its
programming is difficult as it works on the SPI/I2C protocol. ADXL345 can measure static
and dynamic accelerations and suitable for mobile applications. Also, these sensors are
laboratory calibrated and don’t require any further calibrations.
Here we will use the Adafruit library for the ADXL345 sensor to interface it with Arduino
Uno.
Components Required
1. Arduino UNO
2. ADXL345 Accelerometer
3. Male-female wires
4. Breadboard
Circuit Diagram
Circuit diagram for ADXL345 accelerometer interface with Arduino is given below:
ADXL345 Arduino Connections:
1. Adafruit ADXL345
2. Adafruit Unified sensor
To download the above libraries, open Arduino IDE and go to Sketch -> Include Library ->
Manage Libraries. Search for Adafruit ADXL345 and install it. Similarly, search for Adafruit
Unified sensor and install.
Now, we are ready to write the code. Example code can be found in Files -> Example ->
Adafruit ADXL345 -> sensortest
1. First, include all the required libraries header files to support the functionality of the
sensor. Here we are also using wire library for I2C communication.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
2. Make an instance by using any variable like accel to use the various functions of the
ADXL345 Arduino library.
void setup()
Serial.begin(9600);
if(!accel.begin())
while(1);
void loop()
sensors_event_t event;
accel.getEvent(&event);
Serial.println("m/s^2 ");
delay(500);
}
Complete code with a Demonstration video is given at the end of this article.
Try to move the sensor slowly in all the directions and observe the readings.
So this is how an Accelerometer can be used with Arduino UNO to detect the variations in x,
y, and z-axis.
Code
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();
void setup(void)
{
Serial.begin(9600);
if(!accel.begin())
{
Serial.println("No valid sensor found");
while(1);
}
}
void loop(void)
{
sensors_event_t event;
accel.getEvent(&event);
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");
Serial.println("m/s^2 ");
delay(500);
}