{"id":4122,"date":"2011-12-09T23:56:00","date_gmt":"2011-12-10T04:56:00","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=4122"},"modified":"2012-07-30T09:29:14","modified_gmt":"2012-07-30T13:29:14","slug":"build-a-digital-spirit-level-using-a-sca610-accelerometer","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/build-a-digital-spirit-level-using-a-sca610-accelerometer\/","title":{"rendered":"Build a digital spirit level using a SCA610 accelerometer"},"content":{"rendered":"<p>A bubble or spirit level meter is a handy tool to find whether a surface is horizontal or vertical. It is often carried\u00a0by civil engineers, mechanical engineers, surveyors, carpenters, and many other\u00a0professionals 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\u2019s from there I got my inspiration to make a very simple digital spirit level. Here\u2019s 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.<\/p>\n<div id=\"attachment_4123\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/ElectronicSpiritLevelTitle.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4123\" class=\"size-full wp-image-4123\" title=\"ElectronicSpiritLevelTitle\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/ElectronicSpiritLevelTitle.jpg\" alt=\"\" width=\"560\" height=\"391\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/ElectronicSpiritLevelTitle.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/ElectronicSpiritLevelTitle-550x384.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4123\" class=\"wp-caption-text\">Digital spirit level meter<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Theory<\/strong><\/p>\n<p>The heart of this project is the SCA610 accelerometer IC that senses the inclination of a surface. Bases on <a href=\"http:\/\/www.vti.fi\/en\/vti\/mems-technology\/3d-mems\" target=\"_blank\">VTI 3D MEMS<\/a> technology, SCA610\u00a0is a very reliable, accurate and stable one-axis analog accelerometer. It requires a single power supply and\u00a0provides 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\u00b0 to -90\u00b0.\u00a0The analog signal can be processed by a microcontroller through an ADC channel to retrieve the inclination information.<\/p>\n<p><strong>Circuit diagram<\/strong><\/p>\n<p>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.\u00a0Based 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.<\/p>\n<div id=\"attachment_4125\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/SpiritLevelCkt.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4125\" class=\"size-medium wp-image-4125\" title=\"SpiritLevelCkt\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/SpiritLevelCkt-550x325.jpg\" alt=\"\" width=\"550\" height=\"325\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/SpiritLevelCkt-550x325.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/SpiritLevelCkt.jpg 871w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4125\" class=\"wp-caption-text\">Circuit diagram of a simple LED spirit level meter (Click image to enlarge)<\/p><\/div>\n<p>The axis direction of the SCA610 accelerometer is marked on the chip, as shown in the circuit diagram above.<\/p>\n<div id=\"attachment_4127\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/EleCTRONICSpiritLevelSetUp.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4127\" class=\"size-full wp-image-4127\" title=\"EleCTRONICSpiritLevelSetUp\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/EleCTRONICSpiritLevelSetUp.jpg\" alt=\"\" width=\"560\" height=\"424\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/EleCTRONICSpiritLevelSetUp.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/EleCTRONICSpiritLevelSetUp-550x416.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4127\" class=\"wp-caption-text\">Circuit setup on a breadboard<\/p><\/div>\n<p><strong>Software<\/strong><\/p>\n<p>The firmware for this project has been written in C using mikroElektronika&#8217;s mikroC Pro for PIC compiler. Note that the buzzer used in this project is a high impedance ON\/OFF type and the\u00a0software just turns the RC5 pin high in order to make the buzzer on. So this firmware won&#8217;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.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/ShawonS\/ElectronicSpiritMikroC.zip\" target=\"_blank\"><strong>Download firmware<\/strong><\/a><\/p>\n<div id=\"attachment_4129\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/fuse-settings.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4129\" class=\"size-medium wp-image-4129\" title=\"fuse settings\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/fuse-settings-550x353.jpg\" alt=\"\" width=\"550\" height=\"353\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/fuse-settings-550x353.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/fuse-settings.jpg 810w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4129\" class=\"wp-caption-text\">Configuration bit settings for PIC16F684<\/p><\/div>\n<p>The video below shows the project in action.<\/p>\n<p><center><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/EWa2xbLPY_w\" frameborder=\"0\" width=\"480\" height=\"360\"><\/iframe><\/center><br \/>\nThis 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).<\/p>\n<table style=\"width: 560px;\" border=\"0\" cellspacing=\"5\" cellpadding=\"2\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"border-color: #cccccc; background-color: #fdfdfd;\"><span style=\"color: #404040;\"><em>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:<\/em><\/span><em><br \/>\n<\/em><em><strong> <\/strong> <\/em><img decoding=\"async\" src=\"http:\/\/embedded-lab.com\/uploads\/images\/ShawonEmail.png\" alt=\"\" \/><\/td>\n<td style=\"border-color: #cccccc; background-color: #fdfdfd;\"><img decoding=\"async\" src=\"http:\/\/embedded-lab.com\/uploads\/images\/Shawon.jpg\" alt=\"\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>A bubble or spirit level meter is a handy tool to find whether a surface is horizontal or vertical. It is often carried\u00a0by civil engineers, mechanical engineers, surveyors, carpenters, and many other\u00a0professionals 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\u2019s from there I got<\/p>\n","protected":false},"author":1,"featured_media":4123,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[245,4],"tags":[380,381,382],"class_list":["post-4122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-lab-projects","category-pic-projects","tag-electronic-spirit-level","tag-pic16f684","tag-sca610"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=4122"}],"version-history":[{"count":21,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4122\/revisions"}],"predecessor-version":[{"id":4150,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4122\/revisions\/4150"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/4123"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=4122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=4122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=4122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}