{"id":995,"date":"2024-01-08T19:00:00","date_gmt":"2024-01-08T22:00:00","guid":{"rendered":"https:\/\/fedablio.com.br\/blog\/?p=995"},"modified":"2024-03-17T15:10:01","modified_gmt":"2024-03-17T18:10:01","slug":"bussola-eletronica-com-arduino","status":"publish","type":"post","link":"https:\/\/fedablio.com.br\/blog\/arquivos\/995","title":{"rendered":"B\u00fassola eletr\u00f4nica com Arduino"},"content":{"rendered":"\n<div style=\"text-align: justify;\">\n\n<p>\n<strong>1. Fa\u00e7a o carregamento do c\u00f3digo<\/strong>\n<\/p>\n\n<pre>\n#define PINO_LED 2\n#define TEMPO 1000\n\nvoid setup() {\n  pinMode(PINO_LED, OUTPUT);\n}\n\nvoid loop() {\n  digitalWrite(PINO_LED, HIGH);\n  delay(TEMPO);\n}\n<\/pre>\n\n<p>\n<strong>2. Fa\u00e7a a montagem do circuito<\/strong>\n<\/p>\n\n<img decoding=\"async\" src=\"https:\/\/fedablio.com.br\/blog\/wp-content\/uploads\/2023\/11\/bus-elet-ard-01.png\" width=\"75%\" height=\"75%\">\n\n<p>\n<strong>3. Fa\u00e7a o carregamento do c\u00f3digo<\/strong>\n<\/p>\n\n<pre>\n#include &lt;MechaQMC5883.h&gt;\n#include &lt;Wire.h&gt;\n\nMechaQMC5883 compass;\nint x = 0;\nint y = 0;\nint z = 0;\nint angle = 0;\n\nvoid setup(){\n  Serial.begin(9600);\n  Wire.begin();\n  compass.init();\n}\n\nvoid loop() {\n  compass.read(&x,&y,&z);\n  angle = (atan2(x, y) \/ 0.0174532925);\n  if(angle < 0){\n    angle += 360;\n  }\n  angle = 360 - angle;\n  Serial.println(angle);\n  delay(1000);\n}\n<\/pre>\n\n<p>\n<strong>4. Fa\u00e7a a montagem do circuito<\/strong>\n<\/p>\n\n<p>\nO m\u00f3dulo GY 273 utiliza o protocolo I2C (SDA para os dados e SCL para a sincroniza\u00e7\u00e3o) como forma de comunica\u00e7\u00e3o. J\u00e1 no Arduino, voc\u00ea pode encontrar o protocolo I2C nas portas A4 e A5.\n<\/p>\n\n<img decoding=\"async\" src=\"https:\/\/fedablio.com.br\/blog\/wp-content\/uploads\/2023\/11\/bus-elet-ard-02.png\" width=\"75%\" height=\"75%\">\n\n<p>\n<strong>5. Fa\u00e7a o carregamento do c\u00f3digo<\/strong>\n<\/p>\n\n<pre>\n#include &lt;MechaQMC5883.h&gt;\n#include &lt;Wire.h&gt;\n\nMechaQMC5883 compass;\nint x = 0;\nint y = 0;\nint z = 0;\nint angle = 0;\n#define PINO_LED 2\n\nvoid setup(){\n  pinMode(PINO_LED, OUTPUT);\n  Serial.begin(9600);\n  Wire.begin();\n  compass.init();\n}\n\nvoid loop() {\n  compass.read(&x,&y,&z);\n  angle = (atan2(x, y) \/ 0.0174532925);\n  if(angle < 0){\n    angle += 360;\n  }\n  angle = 360 - angle;\n  if(angle > 140 && angle < 170){\n    digitalWrite(PINO_LED, HIGH);\n  }\n  digitalWrite(PINO_LED, LOW);\n}\n<\/pre>\n\n<p>\n<strong>6. Monte os circuitos dos passos 2 e 4 no mesmo Arduino\/protoboard<\/strong>\n<\/p>\n\nSeja feliz. \n\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Fa\u00e7a o carregamento do c\u00f3digo #define PINO_LED 2 #define TEMPO 1000 void setup() { pinMode(PINO_LED, OUTPUT); } void loop() { digitalWrite(PINO_LED, HIGH); delay(TEMPO); } 2. Fa\u00e7a a montagem do circuito 3. Fa\u00e7a o carregamento do c\u00f3digo #include &lt;MechaQMC5883.h&gt; #include &lt;Wire.h&gt; MechaQMC5883 compass; int x = 0; int y = 0; int z = 0; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,28],"tags":[193],"class_list":["post-995","post","type-post","status-publish","format-standard","hentry","category-arduino","category-robotica","tag-bussola-arduino"],"_links":{"self":[{"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/posts\/995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/comments?post=995"}],"version-history":[{"count":16,"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/posts\/995\/revisions"}],"predecessor-version":[{"id":1083,"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/posts\/995\/revisions\/1083"}],"wp:attachment":[{"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/media?parent=995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/categories?post=995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fedablio.com.br\/blog\/wp-json\/wp\/v2\/tags?post=995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}