{"id":144629,"date":"2024-07-29T17:05:43","date_gmt":"2024-07-29T11:35:43","guid":{"rendered":"https:\/\/www.electronicsforu.com\/?p=144629"},"modified":"2024-08-05T17:43:49","modified_gmt":"2024-08-05T12:13:49","slug":"compass-using-indus-board","status":"publish","type":"post","link":"https:\/\/www.electronicsforu.com\/electronics-projects\/compass-using-indus-board","title":{"rendered":"Compass Using Indus Board"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"152\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2016\/12\/Screen-Shot-2016-12-24-at-15.19.33-e1644389186872.png\" alt=\"\" class=\"wp-image-28226\"\/><figcaption class=\"wp-element-caption\">Comment errors or corrections found for this circuit, and get the chance to win big!<\/figcaption><\/figure><\/div>\n\n\n<p>A compass is a device used for navigation and geographic orientation. It typically consists of a magnetized needle or another element, such as a compass card or compass rose, which can pivot to align itself with magnetic north.<\/p>\n\n\n\n<p>In this project, we use Indus Board coin to make a compass. We program the board which uses accelerometer and magnetometer readings to calculate the heading of this compass.<\/p>\n\n\n\n<p>Additionally, we use 4 LEDs which glows in the direction of compass, which are connected with four different pins of the Indus board.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1-1024x768.jpg\" alt=\"\" class=\"wp-image-144631\" style=\"width:577px;height:auto\" srcset=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1-1024x768.jpg 1024w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1-500x375.jpg 500w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1-560x420.jpg 560w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1-80x60.jpg 80w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1-696x522.jpg 696w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/Indusboard-and-breadboard-1.jpg 1379w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Author&#8217;s Prototype<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Components required<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>S. No.<\/strong><\/td><td><strong>Name<\/strong><\/td><td><strong>Description<\/strong><\/td><td><strong>Number<\/strong><\/td><\/tr><tr><td>1.<\/td><td>Indus board coin<\/td><td>3cm sized dev board<\/td><td>1<\/td><\/tr><tr><td>2.<\/td><td>Device (laptop)<\/td><td>To program the Indus board.<\/td><td>1<\/td><\/tr><tr><td>3.<\/td><td>USB cable<\/td><td>Required to connect Indus board to the device.<\/td><td>1<\/td><\/tr><tr><td>4.<\/td><td>LEDs and resistors<\/td><td>To determine the direction of compass.<\/td><td>4<\/td><\/tr><tr><td>5.<\/td><td>Jumper wires<\/td><td>To connect push buttons to the board.<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Schematic and Real Implementation<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"515\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/board-diagram-1024x515.jpg\" alt=\"\" class=\"wp-image-144630\" style=\"width:470px;height:auto\" srcset=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/board-diagram-1024x515.jpg 1024w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/board-diagram-500x251.jpg 500w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/board-diagram-836x420.jpg 836w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/board-diagram-696x350.jpg 696w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/07\/board-diagram.jpg 1530w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Arduino Code<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\n #include &lt;Wire.h&gt; \n#include &lt;LSM303AGR_ACC_Sensor.h&gt; \n#include &lt;LSM303AGR_MAG_Sensor.h&gt; \n#if defined(ARDUINO_SAM_DUE) \n#define DEV_I2C Wire1 \/\/Define which I2C bus is used. Wire1 for the Arduino Due \n#define SerialPort Serial \n#else \n#define DEV_I2C Wire \/\/Or Wire \n#define SerialPort Serial \n#endif \n\/\/ Components \nLSM303AGR_ACC_Sensor Acc(&amp;DEV_I2C); \nLSM303AGR_MAG_Sensor Mag(&amp;DEV_I2C); \n\/\/ Function prototypes \nfloat calculateHeading(int32_t magData&#91;3], int32_t accData&#91;3]); \nconst int ledPin_n = 1; \nconst int ledPin_e = 2; \nconst int ledPin_s = 3; \nconst int ledPin_w = 4; \nvoid setup() { \n\/\/ Initialize the LEDs \npinMode(ledPin_n, OUTPUT); \npinMode(ledPin_e, OUTPUT); \npinMode(ledPin_s, OUTPUT); \npinMode(ledPin_w, OUTPUT); \n\/\/ Initialize serial communication \nSerialPort.begin(115200); \n\/\/ Initialize I2C communication \nDEV_I2C.begin(); \n\/\/ Initialize the accelerometer and magnetometer \nif (Acc.begin() != 0) { \nSerialPort.println(\"Failed to initialize LSM303AGR accelerometer!\"); \nwhile (1); \n} \nif (Mag.begin() != 0) { \nSerialPort.println(\"Failed to initialize LSM303AGR magnetometer!\"); \nwhile (1); \n} \n\/\/ Enable the sensors \nAcc.Enable(); \nAcc.EnableTemperatureSensor(); \nMag.Enable(); \n} \nvoid loop() { \n\/\/ Read accelerometer data \nint32_t accData&#91;3]; \nAcc.GetAxes(accData); \n\/\/ Read temperature \nfloat temperature; \nAcc.GetTemperature(&amp;temperature); \n\/\/ Read magnetometer data \nint32_t magData&#91;3]; \nMag.GetAxes(magData); \n\/\/ Calculate the heading \nfloat heading = calculateHeading(magData, accData); \nSerialPort.print(\"Heading: \"); \nSerialPort.print(heading, 3); \nif((0&lt;=heading and 20&gt;=heading) or (340&lt;=heading and 360&gt;=heading)){ \nSerialPort.print(\" NORTH\"); \ndigitalWrite(ledPin_n, HIGH); \/\/ pin 1 \ndigitalWrite(ledPin_w, LOW); \/\/ pin 4 \ndigitalWrite(ledPin_s, LOW); \/\/ pin 3 \ndigitalWrite(ledPin_e, LOW); \/\/ pin 2 \n} \nelse if(70&lt;=heading and 110&gt;=heading){ \nSerialPort.print(\" WEST\"); \ndigitalWrite(ledPin_w, HIGH); \/\/ pin 4 \ndigitalWrite(ledPin_s, LOW); \/\/ pin 3 \ndigitalWrite(ledPin_e, LOW); \/\/ pin 2 \ndigitalWrite(ledPin_n, LOW); \/\/ pin 1 \n} \nelse if(160&lt;=heading and 200&gt;=heading){ \nSerialPort.print(\" SOUTH\"); \ndigitalWrite(ledPin_s, HIGH); \/\/ pin 3 \ndigitalWrite(ledPin_e, LOW); \/\/ pin 2 \ndigitalWrite(ledPin_w, LOW); \/\/ pin 4 \ndigitalWrite(ledPin_n, LOW); \/\/ pin 1 \n} \nelse if(250&lt;=heading and 290&gt;=heading){ \nSerialPort.print(\" EAST\"); \ndigitalWrite(ledPin_e, HIGH); \/\/ pin 2 \ndigitalWrite(ledPin_n, LOW); \/\/ pin 1 \ndigitalWrite(ledPin_w, LOW); \/\/ pin 4 \ndigitalWrite(ledPin_s, LOW); \/\/ pin 3 \n} \nelse if(20.01&lt;=heading and 69.99&gt;=heading){ \nSerialPort.print(\" NORTH-WEST\"); \ndigitalWrite(ledPin_n, HIGH); \/\/ pin 1 \ndigitalWrite(ledPin_w, HIGH); \/\/ pin 4 \ndigitalWrite(ledPin_s, LOW); \/\/ pin 3 \ndigitalWrite(ledPin_e, LOW); \/\/ pin 2 \n} \nelse if(110.01&lt;=heading and 159.99&gt;=heading){ \nSerialPort.print(\" SOUTH-WEST\"); \ndigitalWrite(ledPin_n, LOW); \/\/ pin 1 \ndigitalWrite(ledPin_w, HIGH); \/\/ pin 4 \ndigitalWrite(ledPin_s, HIGH); \/\/ pin 3 \ndigitalWrite(ledPin_e, LOW); \/\/ pin 2 \n} \nelse if(200.01&lt;=heading and 249.99&gt;=heading){ \nSerialPort.print(\" SOUTH-EAST\"); \ndigitalWrite(ledPin_n, LOW); \/\/ pin 1 \ndigitalWrite(ledPin_w, LOW); \/\/ pin 4 \ndigitalWrite(ledPin_s, HIGH); \/\/ pin 3 \ndigitalWrite(ledPin_e, HIGH); \/\/ pin 2 \n} \nelse if(290.01&lt;=heading and 339.99&gt;=heading){ \nSerialPort.print(\" NORTH-EAST\"); \ndigitalWrite(ledPin_n, HIGH); \/\/ pin 1 \ndigitalWrite(ledPin_w, LOW); \/\/ pin 4 \ndigitalWrite(ledPin_s, LOW); \/\/ pin 3 \ndigitalWrite(ledPin_e, HIGH); \/\/ pin 2 \n} \nSerial.println(); \n\/\/ SerialPort.println(\" degrees |\"); \ndelay(10); \/\/ Adjust delay as needed \n} \nfloat calculateHeading(int32_t magData&#91;3], int32_t accData&#91;3]) { \n\/\/ Calculate tilt compensation \nfloat pitch = atan2(accData&#91;1], sqrt(sq(accData&#91;0]) + sq(accData&#91;2]))); \nfloat roll = atan2(-accData&#91;0], accData&#91;2]); \n\/\/ Tilt compensation \nfloat xh = magData&#91;0] * cos(pitch) + magData&#91;2] * sin(pitch); \nfloat yh = magData&#91;0] * sin(roll) * sin(pitch) + magData&#91;1] * cos(roll) - magData&#91;2] * sin(roll) * cos(pitch); \n\/\/ Calculate heading in degrees \nfloat heading = atan2(yh, xh) * 180 \/ PI; \n\/\/ Normalize heading to 0-360 degrees \nif (heading &lt; 0) { \nheading += 360; \n} \nreturn heading; \n} \n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><em>Author(s): Manjeet Vishwakarma, \u00a0Abhay Verma and Satywanti Kundu are B.Tech ECE students at GJUS&amp;T HISAR<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A compass is a device used for navigation and geographic orientation. It typically consists of a magnetized needle or another element, such as a compass card or compass rose, which can pivot to align itself with magnetic north. In this project, we use Indus Board coin to make a compass. We program the board which [&hellip;]<\/p>\n","protected":false},"author":55758,"featured_media":144631,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,23,776,11851],"tags":[1985,1911,110],"class_list":{"0":"post-144629","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-electronics-projects","8":"category-hardware-diy","9":"category-prototypes","10":"category-super-innovative-projects","11":"tag-diy-projects","12":"tag-do-it-yourself","13":"tag-electronics-projects"},"_links":{"self":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts\/144629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/users\/55758"}],"replies":[{"embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/comments?post=144629"}],"version-history":[{"count":2,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts\/144629\/revisions"}],"predecessor-version":[{"id":147497,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts\/144629\/revisions\/147497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/media\/144631"}],"wp:attachment":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/media?parent=144629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/categories?post=144629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/tags?post=144629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}