To measure how flat a surface is, you typically will need a level of some sort. In this article, I will show you a digital level I made with an accelerometer. It is extremely accurate, capable of measuring inclination as small as 1/1000 degree.

The digital accelerometer I used here is ST’s triple-axis accelerometer LIS3LV02DL. I talked about how to use it using SPI a couple of months ago. You only need 2 axises for this particular application, since I happen to have this tripe-axis accelerometer on hand, I will use it here.

The following are the coordinates of the acceleration measurements.

If we are measuring the surface represented by x-axis and y-axis, the angles can be measured as:
$\theta_x = tan^{-1}\frac{g}{g_x}$
$\theta_y = tan^{-1}\frac{g}{g_y}$

When the accelerometer is placed on a perfectly flat surface, the force exerted on z axis would be approximately 1g.

Since LIS3LV02DL has 2 modes (2g and 6g), the 12 bit of resolution per axis (readings from -2048 to 2048) should give us 1/1000 resolution in 2g mode. 6g model can also be used, but the accuracy will be roughly three times lower than in 2g mode. Here is the schematics of the circuit using ATmega328p MCU:

In my design above, I used one button to toggle the back light of the LCD display, one button to calibrate the device and one button to toggle between 2g and 6g modes. Here is a picture of the assembled digital level.

The picture below shows the digital level on a flat surface after initial calibration. Calibration is achieved by placing the digital level on a known flat surface and press the calibrate button. When the calibration button is pressed, the x and y readings are forced to 0’s and thus making relative measurements much easier.

The Arduino code for this project can be downloaded here. This project was developed with the NetBeans IDE and you may need to adjust the included header files if you are using Arduino IDE. For more information, please see my previous article on this topic.)

Be Sociable, Share!