Build a digital spirit level using a SCA610 accelerometer

A bubble or spirit level meter is a handy tool to find whether a surface is horizontal or vertical. It is often carried by civil engineers, mechanical engineers, surveyors, carpenters, and many other professionals whose work involve precise alignments of horizontal and vertical planes. Original spirit levels had two banana-shaped curved glass vials at each viewing point and were much more complicated to use. Mechanical spirit level meters are still available both in 1D and 2D formats. However at present time their electronic counterparts have also emerged and are even available in modern Android equipped cell phones. It’s from there I got my inspiration to make a very simple digital spirit level. Here’s a demo of such an electronic spirit level made by using a Microchip PIC16F684 micro, a SCA610 accelerometer and a handful of other discrete components.

Digital spirit level meter

Theory

The heart of this project is the SCA610 accelerometer IC that senses the inclination of a surface. Bases on VTI 3D MEMS technology, SCA610 is a very reliable, accurate and stable one-axis analog accelerometer. It requires a single power supply and provides an analog output voltage proportional to the inclination. According to its datasheet, if the device is powered with a precise +5.0V, the analog output voltages for +1g (vertical), 0g (horizontal), and -1g (vertical in opposite direction) inclinations would be 3.75V, 2.50V, and 1.25V, respectively. Voltages between 1.25V and 3.75V are linearly interpolated and mapped to the inclination angles varying from +90° to -90°. The analog signal can be processed by a microcontroller through an ADC channel to retrieve the inclination information.

Circuit diagram

The microcontroller used in this project is PIC16F684 which has just enough I/O pins and a built-in 10-bit A/D converter required for this project. The microcontroller runs at 8.0 MHz using the internal oscillator. The SCA610 sensor output goes to AN0 ADC channel of PIC16F684. The microcontroller takes quick multiple ADC samples which are averaged for a better estimation of inclination angle. There are five LEDs connected to RC0 through RC4 port pins and they are arranged in a row. Based on the direction of inclination the LEDs run in either forward or in reverse direction. There is a buzzer connected to RC5 pin which beeps continuously until the entire board settles at 0g or horizontal position. The buzzer used in the circuit is a ON/OFF type. What that means is it turns on when the RC5 pin goes high. If the device is aligned perfectly horizontal then only a central blue LED flashes and the buzzer mutes.

Circuit diagram of a simple LED spirit level meter (Click image to enlarge)

The axis direction of the SCA610 accelerometer is marked on the chip, as shown in the circuit diagram above.

Circuit setup on a breadboard

Software

The firmware for this project has been written in C using mikroElektronika’s mikroC Pro for PIC compiler. Note that the buzzer used in this project is a high impedance ON/OFF type and the software just turns the RC5 pin high in order to make the buzzer on. So this firmware won’t drive a buzzer that requires an ac signal. You can download the source code and compiled HEX output of the firmware from the following link.

Download firmware

Configuration bit settings for PIC16F684

The video below shows the project in action.


This project used a one-axis accelerometer chip and therefore, the alignment can be measured in only one direction at a time. However, the concept can be extended for simultaneous measurements of orientation in two dimensions by adding one more SCA610 sensor or just choosing a dual axis accelerometer (like ADXL202).

Many thanks to Shawon Shahryiar for contributing this article to Embedded Lab. He works as an Engineer in the Research and Development Cell at ELECTRO Group in Dhaka, Bangladesh. If you have any questions regarding this project, please contact him at:

Related Posts

4 comments

Leave a Reply to zaim razali Cancel reply

Your email address will not be published. Required fields are marked *