I would like to know if there is a way to obtain a single acceleration of the three axes present in the accelerometer. During research it was suggested to apply pythagoras on the axes to obtain vectorial acceleration as follows: acVec=sqrt (pow (x, 2) + pow (y, 2) + pow (z, 2)). Is this equation valid for obtaining an acceleration resulting from the three axes?

That equation is valid, but is a bad idea in this case.

The pow() function operates on logarithms and exponentials of floating point numbers, and is slow and inaccurate.

To calculate the magnitude of the acceleration vector, use simple float values, derived from the raw accelerometer measurements. Do any required scaling after conversion to float.

```
float accel_mag = sqrt(ax*ax + ay*ay + az*az);
```

OK! Thank you very much

Can I apply the values of the axes converted to m / s2 in this equation or should these values be the raw data received?

For example, as shown in the code, I take the raw data from the accelerometer using the lib “Wire” and then do the necessary calculations to convert it to m / s2.

```
/ * MPU6050 sensor Acceleration reading * /
accX = (int16_t)((i2c_data[0] << 8) | i2c_data[1]); // ([ MSB ] [ LSB ])
accY = (int16_t)((i2c_data[2] << 8) | i2c_data[3]); // ([ MSB ] [ LSB ])
accZ = (int16_t)((i2c_data[4] << 8) | i2c_data[5]); // ([ MSB ] [ LSB ])
// * Converting to m / s² * /
accX = (accX/ACCEL_SCALE) * SENSORS_GRAVITY_STANDARD;
accY = (accY/ACCEL_SCALE) * SENSORS_GRAVITY_STANDARD;
accZ = (accZ/ACCEL_SCALE) * SENSORS_GRAVITY_STANDARD;
```

Mathematically it does not matter which order the operations are applied (but see below).

If you need individual scaled values for each axis, scale each axis separately, then compute the magnitude.

If you need only the scaled magnitude, calculate it from the raw data and scale the result. That reduces multiplication and division operations, saving time and program memory.

Note: if ax, ay, az below are 16 bit integers, integer overflow will probably result. That is why you normally convert to the integer raw data to floats before computing the magnitude.

```
float accel_mag = sqrt(ax*ax + ay*ay + az*az);
```

I understand thank you!