[Introduction to accelerometer] Let's use the tap detection function

In the [Introduction to Accelerometer] series, we will explain the basic usage and application methods, focusing on analog devices' accelerometers. In the previous article, I introduced "how to implement motion detection" using the accelerometer "ADXL345" and "Arduino". In this article, I would like to consider removing gravitational acceleration, which is necessary when performing motion detection, etc.

[Introduction to accelerometer] Click here for the series list

Let's remove the gravitational acceleration

static and dynamic acceleration

MEMS acceleration sensors are generally capable of detecting DC (direct current component) acceleration. groundGravitational acceleration acts on the sphere, so an acceleration of 1[g] can be detected. The figure below shows the acceleration waveform measured when the accelerometer is placed on a flat desk. Since the Z-axis is perpendicular to the gravity direction, it can be confirmed that the acceleration of 1g is constant with respect to the time axis. Static acceleration is a DC component acceleration that always produces a constant value over time, such as gravitational acceleration. On the other hand, acceleration that occurs in actions such as motion and vibration is acceleration that changes over time and is called dynamic acceleration. increase. Acceleration thresholding becomes important when you want to implement motion detection that detects dynamic acceleration. However, there are cases where it is necessary to remove the DC component of the gravitational acceleration as an offset.

Acceleration data waveform
Acceleration data waveform

Implementing a high-pass filter

There is a high-pass filter as a method to remove the DC component such as the gravitational acceleration as shown in the figure and obtain the dynamic acceleration. For analog output type accelerometers, a high-pass filter can be built with a capacitor and resistor before AD conversion. Since the ADXL345 used this time is a digital output, the high-pass filter function must be included in the host processor such as a microcomputer.

High-pass filter operation image diagram
Operation image diagram of active function & inactive function

Things to prepare

We will create a sample program to "remove gravitational acceleration" using the acceleration sensor "ADXL345" and the hardware open platform "Arduino".

Here is what I prepared to evaluate the accelerometer this time.

 

・PC with Arduino IDE installed (Download Arduino IDE from here)

Arduino Nano compatible board 

Accelerometer ADXL345 

・Others (USB cable (for Arduino and PC connection), breadboard, wires)

 

Combine the above parts to form a circuit as shown in the figure below. Power supply to Arduino Nano is supplied by USB bus power from PC. The ADXL345 supports SPI and I2C interfaces, but this time we will use the I2C interface.

Connection diagram
Connection diagram

Program content

A high-pass filter is implemented in a simple way. The program flow acquires acceleration data at regular intervals. After that, the data of the previous state obtained is retained, and the gravitational acceleration component is removed by taking the difference with the current data. This time, I implemented it by the method described in the Android development guide. You can download the project file created with the Arduino IDE, so if you are interested, please get it from the "Document Download" below.

 

 

operation check

Let's check the operation with the created program. The video only uses the Z axis on the ArduinoIDE serial plotter for clarity. Also, for comparison, the data before and after removing the gravitational acceleration are displayed. Although it is a simple filter, it was confirmed that the gravitational acceleration was removed. However, there may be cases where filter adjustment is necessary due to limitations such as the responsiveness at startup and the amplitude becoming smaller for movements with slow changes in acceleration. However, I was able to remove the gravitational acceleration with a simple implementation, so I would like to use it in future motion detection.

 

Download the sample code verified this time

We provide the Arduino project file that we implemented this time. Please apply from here and give it a try.

About Accelerometer ADXL345

The ADXL345 used this time is a 3-axis digital output acceleration sensor. The main features are as follows.

・A standard accelerometer that is very easy to use with built-in ADC, operation function block, and FIFO
・Acceleration data adopts general I2C/SPI in digital serial method
・The 3-axis type sensor is a rectangular coordinate (X, Y, Z), and the acceleration acting on each axis can be obtained.
・The maximum detectable acceleration can be set in the range of 2g to 16g, and the sampling range is as wide as ~3.2kHz, so it can be applied to various applications such as impact, tilt, and motion detection.
・Flexible mode to reduce current consumption

For more information on the ADXL345, visit www.adxl345.com. data sheet Please refer to. Also, this accelerometer is very easy to use, so if you want to evaluate an accelerometer from now on, please try it on the evaluation board.

 

At the end

If you have any questions about the contents of this article, or if you have any problems with selecting or using accelerometers, please contact us from the following.



Analog Devices Manufacturer Information Top

If you want to return to Analog Devices Manufacturer Information Top, please click the button below.