 # help! ADXL335 Accelerometer, acceleration and vector math

Hi,
I’ve been working on using the ADXL335 accelerometer with an Arduino UNO.
I have a question regarding a 3-axis accelerometer and vector math.

What I want:
I want to figure out, how to track acceleration of the 3-axis (x, y, z) accelerometer (e.g. if the accelerometer is moving at 10m/s^2, I want the number 10 and if at 1m/s^2, I want the number 1).

The set-up:
Despite I have NO electronics/physics background, I know roughly that accelerometers spit out readings of the acceleration applied to the axises, and also they naturally take in account the gravity on the z-axis.

In my project the accelerometer is hanging in mid air, attached at the end of a string (kinda like a pendulum) - so it can move in any random direction. My hypothesis is that by calculating the changes of the acceleration in each loop of the Arduino code will allow me to get the value of the combined change of the 3-axis. The issue here I think is that the accelerometer is moving in any random direction in space, making the situation difficult to calculate acceleration of all the 3-axises and combining them into one.

The question
Now, I found this tutorial here Das Blinken Top Hat - learn.sparkfun.com that seems to be trying to achieve something similar.

It states that I have to do a thing called vector math, to "combine the three acceleration vectors into one. For our purposes we care only about the movement of the hat (magnitude of movement), not direction:
A^2 + B^2 + C^2 = Z^2
"

This is the bit I’m confused about. Do you know why they did this? “Combining” the three acceleration sounds like what I want to do, but what does it mean to combine acceleration “vectors”?

Hey, it's me again. I'll be using an example from my current MPU6050 project, but I think it'll help you make something out.

This is the bit I'm confused about. Do you know why they did this? "Combining" the three acceleration sounds like what I want to do, but what does it mean to combine acceleration "vectors"?

I know this is what you want but I'll try and give some input. Try using an Excel Spreadsheet or Google Sheets and analyze the data your sensor outputs. Put it in a while() loop and run it for about a second or two. Copy and paste that onto a spreadsheet and graph them. I doubt you'd want to, but it sure helped me to make sense of my MPU6050's motion

Do you know a "conversion constant/factor" that allows you to change the raw values from your sensor to usable data (m/s2)?

For example, with my sensor, a quick read at the datasheet that some of the raw values will be either 2048, 4096, 8192, or 16384. My own chip was outputting a value close to 16384 while it was on my table, and this was the z-axis (where the chip is relatively flat to the horizontal). Given this, I deduced that this is some weird value signifying g. My conversion ended up being 1671.

How I found "1671" --
16384 / 9.81 = 1671

When any raw value is divided by this constant, you get the value of acceleration in m/s2

Otherwise if you don't have a constant...

How will you do it?
Follow the little formula I gave and divide your value by g. HOWEVER, look into the datasheet to find what value corresponds to "g."

Now, in your code write a function like this:

``````float accel_x = raw_value_x / conversion_number;
``````

I hope this helps

Jerome A.