Tilt Sensor (Part 6)
Part 1, 2, 3, 4, 5, 6, 7, 8, 9
Unless you plan to use the tilt sensor for detecting 90° tilt angles (e.g. dice position), you must calibrate the sensor prior to running accurate tilt angle measurements. There a many ways of achieving this task. The described method is pretty simple and gives very good results. Under these calibration conditions, starting at 0:0 degrees, putting a piece of paper under one of the accelerometer evaluation board reads a 1° tilt angle!
double X_NO_G; double X_ONE_G; double Y_NO_G; double Y_ONE_G; double Z_NO_G; double Z_ONE_G; LCD.printString(MSG_TLT_NONE, 1); LCD.clearLine(2); delay(3000); LCD.printString(MSG_COMPUTING, 2); delay(500); X_NO_G = analogReadMv(channelX); Y_NO_G = analogReadMv(channelY); Z_ONE_G = analogReadMv(channelZ); LCD.printString(MSG_DONE, 2); delay(1000); LCD.printString(MSG_TLT_X, 1); LCD.clearLine(2); delay(3000); LCD.printString(MSG_COMPUTING, 2); delay(500); X_ONE_G = analogReadMv(channelX); Z_NO_G = analogReadMv(channelZ); LCD.printString(MSG_DONE, 2); delay(1000); LCD.printString(MSG_TLT_Y, 1); LCD.clearLine(2); delay(3000); LCD.printString(MSG_COMPUTING, 2); delay(500); Y_ONE_G = analogReadMv(channelY); Z_NO_G += analogReadMv(channelZ); Z_NO_G /= 2; /* Compute average */ LCD.printString(MSG_DONE, 2); delay(1000); /* Compute sensitivities */ vSensitivity[channelX] = (X_ONE_G - X_NO_G); vSensitivity[channelY] = (Y_ONE_G - Y_NO_G); vSensitivity[channelZ] = (Z_ONE_G - Z_NO_G); /* Compute offsets */ vOffset[channelX] = X_NO_G; vOffset[channelY] = Y_NO_G; vOffset[channelZ] = Z_NO_G;
This code must be placed on top of the sketch, in the setup() function. At boot, the user is prompted to leave the sensor horizontal; after a short while, he is prompted to tilt it along the X axis, and after an other short while, he is prompted to tilt it along the Y axis.
Here is the declaration of the constants
#define MSG_CALIBRATING "CALIBRATING..." #define MSG_COMPUTING "COMPUTING..." #define MSG_DONE "DONE" #define MSG_FIRMWARE "** MicroTLT **" #define MSG_TLT_NONE "NO TILT" #define MSG_TLT_X "TILT IN X DIR." #define MSG_TLT_Y "TILT IN Y DIR." #define MSG_UPLOADING "UPLOADING..."
There are more sophisticated methods, such as solving equations using the least squares method. We will get back to this method once the matrix question shall be covered.
[…] Next post on same subject Tags: Accelerometer, Measuring instruments, Sensors Comment (RSS) | Trackback […]