{"id":27205,"date":"2016-11-17T23:22:21","date_gmt":"2016-11-17T23:22:21","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=27205"},"modified":"2019-04-02T10:23:30","modified_gmt":"2019-04-02T10:23:30","slug":"guide-for-the-tilt-sensor-inclinometer-with-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/guide-for-the-tilt-sensor-inclinometer-with-arduino\/","title":{"rendered":"Guide for the Tilt Sensor (inclinometer) with Arduino"},"content":{"rendered":"<p>This post shows how to use the tilt sensor module with the Arduino. The tilt sensor is many times referred to as inclinometer, tilt switch or rolling ball sensor. Using a tilt sensor is a simple way to detect orientation or inclination.<!--more--><\/p>\n<h2>Introducing the Tilt Sensor Module<\/h2>\n<p>The tilt sensor module is the one\u00a0in the following figure.<\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-28575\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=376%2C395&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"dsc09409\" width=\"376\" height=\"395\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=143%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 143w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=286%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 286w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=76%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 76w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=210%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 210w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=95%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 95w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=227%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 227w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=395%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 395w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=464%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 464w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?resize=567%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 567w\" sizes=\"(max-width: 376px) 100vw, 376px\" \/><\/p>\n<p>The tilt sensor allows to detect orientation or inclination. It detects if the sensor is completely upright or if it is tilted.<\/p>\n<p>This makes it\u00a0very useful to be used, for example,\u00a0in toys, robots and other appliances whose working methodology depends on inclination.<\/p>\n<h3>How does it work?<\/h3>\n<p>The tilt sensor is cylindrical and contains a free conductive rolling ball inside with two conductive elements (poles) beneath.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-28577\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=663%2C407&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"tilt-sensor-how-it-works\" width=\"663\" height=\"407\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?w=663&amp;quality=100&amp;strip=all&amp;ssl=1 663w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=150%2C92&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=300%2C184&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=80%2C49&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=220%2C135&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=163%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 163w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=244%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 244w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensor-How-it-works-1.png?resize=388%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 388w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/p>\n<p>Here&#8217;s how it works:<\/p>\n<ul>\n<li>When the sensor is completely upright, the ball falls to the bottom of the sensor and connects the poles, allowing the current to flow.<\/li>\n<li>When the sensor is tilted, the ball doesn&#8217;t touch the poles, the circuit is open, and the current doesn&#8217;t flow.<\/li>\n<\/ul>\n<p>This way, the tilt sensor acts like a switch that is turned on or off depending on its inclination. So, it will give digital information to the Arduino, either an HIGH or a LOW signal.<\/p>\n<h2>Where to buy?<\/h2>\n<p>You can go to\u00a0<a href=\"https:\/\/makeradvisor.com\/tools\/tilt-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">Maker Advisor<\/a>\u00a0and find the sensor\u2019s best price.<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/tilt-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tilt sensor\/inclinometer<\/a><\/li>\n<\/ul>\n<h2>Pin wiring<\/h2>\n<p>Wiring the tilt sensor to you Arduino is pretty straightforward.\u00a0You just need to connect one pin to an Arduino digital pin and GND to GND.<\/p>\n<p>If you connect the sensor like so, you need to activate the arduino internal pull-up resistor for the digital pin to which your sensor is connected to. Otherwise, you should use a 10kOhm pull up resistor in your circuit.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-28646\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=349%2C355&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"pin-wiring_bb\" width=\"349\" height=\"355\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=147%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 147w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=295%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 295w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=80%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=216%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 216w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=98%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 98w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=234%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 234w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=408%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 408w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=479%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 479w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Pin-Wiring_bb.png?resize=585%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 585w\" sizes=\"(max-width: 349px) 100vw, 349px\" \/><\/p>\n<h2>Example: Tilt sensitive LED<\/h2>\n<p>This is just a simple example for you to start put hands on your tilt sensor.<\/p>\n<p>In this example, an LED will be turned off if the sensor is upright, and will be turned on\u00a0if the sensor is tilted.<\/p>\n<h3>Parts required<\/h3>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Breadboard\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/tilt-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Tilt Sensor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x LED<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 220Ohm resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires<\/a><\/li>\n<\/ul>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h3>Schematics<\/h3>\n<p>For this example, you just need to add an LED to the schematics in the &#8220;Pin Wiring&#8221; section.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-28647\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=385%2C578&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"tilt-sensitive-led_bb\" width=\"385\" height=\"578\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=100%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 100w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=200%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 200w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=682%2C1024&amp;quality=100&amp;strip=all&amp;ssl=1 682w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=53%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 53w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=147%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 147w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=67%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 67w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=159%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 159w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=276%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 276w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=324%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 324w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/Tilt-sensitive-LED_bb-1.png?resize=396%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 396w\" sizes=\"(max-width: 385px) 100vw, 385px\" \/><\/p>\n<h3>Code<\/h3>\n<p>To complete this example,\u00a0upload the following code to your Arduino board.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n \n \nint ledPin = 12;         \nint sensorPin = 4;\nint sensorValue;\nint lastTiltState = HIGH;   \/\/ the previous reading from the tilt sensor\n    \n\/\/ the following variables are long's because the time, measured in miliseconds,\n\/\/ will quickly become a bigger number than can be stored in an int.\nlong lastDebounceTime = 0;  \/\/ the last time the output pin was toggled\nlong debounceDelay = 50;    \/\/ the debounce time; increase if the output flickers\n \nvoid setup(){\n  pinMode(sensorPin, INPUT);\n  digitalWrite(sensorPin, HIGH);\n  pinMode(ledPin, OUTPUT);\n  Serial.begin(9600);\n}\n \nvoid loop(){\n  sensorValue = digitalRead(sensorPin);\n  \/\/ If the switch changed, due to noise or pressing:\n  if (sensorValue == lastTiltState) {\n    \/\/ reset the debouncing timer\n    lastDebounceTime = millis();\n  } \n  if ((millis() - lastDebounceTime) &gt; debounceDelay) {\n    \/\/ whatever the reading is at, it's been there for longer\n    \/\/ than the debounce delay, so take it as the actual current state:\n    lastTiltState = sensorValue;\n  }\n  digitalWrite(ledPin, lastTiltState);\n\n  Serial.println(sensorValue);\n  delay(500);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino_tilt_sensor.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<h3>Demonstration<\/h3>\n<p>In the end, this is what you&#8217;ll have.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28611\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/tilt-sensor-GIF.gif?resize=480%2C270&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"tilt-sensor-gif\" width=\"480\" height=\"270\" \/><\/p>\n<h2>Wrapping up<\/h2>\n<p>I hope you&#8217;ve found this post useful.<\/p>\n<p>If you would like to know more about Arduino sensors, make sure you check some of the following guides:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-bmp180-barometric-sensor-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide for BMP180 Barometric Sensor with Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-real-time-clock-rtc-module-with-arduino-ds1307-and-ds3231\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide for Real Time Clock (RTC) Module with Arduino (DS1307 and DS3231)<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-ds18b20-temperature-sensor-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide for DS18B20 Temperature Sensor with Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-soil-moisture-sensor-yl-69-or-hl-69-with-the-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide for Soil Moisture Sensor YL-69 or HL-69 with Arduino<\/a><\/li>\n<\/ul>\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post shows how to use the tilt sensor module with the Arduino. The tilt sensor is many times referred to as inclinometer, tilt switch or rolling ball sensor. Using &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide for the Tilt Sensor (inclinometer) with Arduino\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/guide-for-the-tilt-sensor-inclinometer-with-arduino\/#more-27205\" aria-label=\"Read more about Guide for the Tilt Sensor (inclinometer) with Arduino\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":28575,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[267,2,302,230,269,264,215,10],"tags":[],"class_list":["post-27205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-project","category-arduino","category-0-guide","category-guide","category-guide-project","category-project","category-sensors","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/10\/DSC09409.jpg?fit=700%2C735&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/27205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=27205"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/27205\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/28575"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=27205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=27205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=27205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}