## Tilt Sensor (Part 5)

Part 1, 2, 3, 4, 5, 6, 7, 8, 9

Once offsets have been subtracted from the raw data, it is time to convert them into scaled data (Gs actually) by applying the sensitivity convertion factor for each axis. Alike offsets, sensistivity factor can be taken straight from the data sheets (300 mV/G), or pre calculated in a calibration routine.

/* Compute acceleration in Gs */ _maxAcc = 0; /* Reset max acceleration */ for (uint8_t channel = 0; channel < _channels; channel++) { vAcc[channel] = (vAdcRelValue[channel] / vSensitivity[channel]); _maxAcc += square(vAcc[channel]); /* Sum squared accelerations */ } /* Compute the resulting maximum G value which should be one */ _maxAcc = sqrt(_maxAcc);

**Notes**:

- The sensitivity factor varies with VSS
- This routine computes the sum of accelerations along each axis. The resulting acceleration, which should be close to one, shall be used for the normalization of sensiitivities.

And here goes the normalization

/* Normalize acceleration */ for (uint8_t channel = 0; channel < _channels; channel++) { vAcc[channel] /= _maxAcc ; }

In this way, the acceleration vector (in the x, y, z planes) is constrained to 1 G.

We are ready now for computing tilt angles (expressed in Deg)

for (uint8_t channel = 0; channel < _channels; channel++) { /* Compute angles in radian */ switch (channel) { case 0: vTiltAngle[channel] = atan(vAcc[channelX] / (sqrt(square(vAcc[channelY]) + square(vAcc[channelZ])))); break; case 1: vTiltAngle[channel] = atan(vAcc[channelY] / (sqrt(square(vAcc[channelX]) + square(vAcc[channelZ])))); break; case 2: vTiltAngle[channel] = atan(sqrt(square(vAcc[channelX]) + square(vAcc[channelY])) / vAcc[channelZ]); break; } /* Convert radian in degree */ vTiltAngle[channel] *= 180.00; vTiltAngle[channel] /= 3.141592; }

Hey,

do you do the normalization because otherwise you get data like:

902

904

906

or so even when the sensor isnt moving or why do you have to normalize it?

The answer is in the post!

“In this way, the acceleration vector (in the x, y, z planes) is constrained to 1 G.”