Email Address:

Lost your password?

This is the legacy website; please use the new website.

Build A Digital Spirit Level

This project is really on the . . . errr . . . level. It's an inclinometer, an electronic version of the old spirit level except that this one gives a digital readout of the angle of any flat surface in 0.1° increments from 0-360°. A MEMS accelerometer chip, as found in tablets and smart phones, is at the heart of the project.

By Andrew Levido

Most of us have a spirit level somewhere in our shed or garage. These handy devices have been around since the mid 1600s, although the modern form of the device dates from the 1920s. A simple air bubble in a slightly curved tube of coloured alcohol can indicate horizontal or plumb (vertical) with surprising accuracy.

Often a quick check for plumb or level is all that is needed but if you want to measure the actual angle you need an inclinometer. You can buy a digital one for up to a couple of hundred dollars or build one yourself for less than $40, thanks to the plummeting costs of MEMS accelerometers.

MEMS (Micro Electromechanical Systems) technology is finding its way into all sorts of consumer electronics these days. Your tablet or smart phone has a MEMS accelerometer so it knows whether you are holding it in portrait or landscape orientation. Handheld game controllers use both accelerometers and gyroscopes to detect how they are waved, shaken, pointed or flicked. Even my universal remote controller uses one to turn on its LCD when I pick it up.

The inclinometer described in this article uses a typical MEMS chip; the Freescale Semiconductor MMA8451Q. This tiny 16-pin surface-mount device includes a 14-bit 3-axis accelerometer together with a sophisticated DSP (Digital Signal Processor) and an I2C interface, all for less than $10. Add a low-cost PIC microcontroller, four 7-segment LED displays and a handful of common components and you have all that is necessary for a pretty useful little instrument.

Form factor

Our inclinometer has a form factor that’s similar to a small spirit level and can measure angle of tilt with an accuracy of 0.1° over the full 360° of rotation. Operation could not be simpler. Just pick up the device and give it a shake to bring it to life, then place it on the surface you want to measure. It will stay awake while ever it senses movement and it will automatically turn off after 30 seconds of inactivity.

How it works

The inclinometer measures its orientation with reference to the acceleration due to gravity which, conveniently for us all, always points straight down. We nominate the side-to-side horizontal axis of the accelerometer as “x”, the top-to-bottom axis as “y” and the front-to-back axis as “z”.

Click for larger image
Fig.1: the accelerometer measures the component of the acceleration due to gravity acting on each of the three axes. These components are trigonomet­rically related to the angle of inclination (see text). Note that the z-axis has been omitted from this diagram for clarity.

If the accelerometer is level, gravity will be perfectly aligned with the y axis. However, when tilted as shown in Fig.1, there will be components of gravitational acceleration (ie, G x sinθ and G x cosθ) along both the “x” and “y” axes, depending on the tilt angle.

Using trigonometry, we could calculate the angle of tilt from the measured acceleration along the x or y axis, as long as we knew the gravitational acceleration. Unfortunately, this varies from the nominal 9.8ms2 depending on location, since the Earth is neither perfectly spherical nor uniformly dense.

Fortunately, we can use the trigonometric identity tanθ = sinθ/cosθ, to solve our problem. If we take the inverse tangent (arctangent) of the ratio of accelerations along the x and y axes, the gravity terms cancel out and we arrive at the angle of inclination using only the acceleration values.

Share this Article: 

Privacy Policy  |  Advertise  |  Contact Us

Copyright © 1996-2021 Silicon Chip Publications Pty Ltd All Rights Reserved