{"id":457,"date":"2017-01-18T22:03:03","date_gmt":"2017-01-18T22:03:03","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=457"},"modified":"2019-10-20T18:26:39","modified_gmt":"2019-10-20T18:26:39","slug":"arduino-how-to-bluetooth-control-2-dc-motors-speed-and-direction-with-a-l298n","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=457","title":{"rendered":"ARDUINO How To Bluetooth Control 2 DC Motors Speed And Direction With A  L298N"},"content":{"rendered":"<p><iframe loading=\"lazy\" title=\"ARDUINO How To Bluetooth Control 2 DC Motors Speed And Direction With A  L298N\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/ZvlsLHPThl4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h1><\/h1>\n<h1><span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/www.facebook.com\/zarduino\/\"><strong>Check us out on Facebook!<\/strong><\/a><\/span><\/h1>\n<h1><a href=\"https:\/\/drive.google.com\/file\/d\/0B0ZYw2jO5Q3DVWJaVy00QWMyTHM\/view?usp=sharing\" target=\"_blank\" rel=\"noopener noreferrer\">APK Download Link<\/a>: \u00a0This is the ANDROID APP..<\/h1>\n<h1><a href=\"https:\/\/drive.google.com\/file\/d\/0B0ZYw2jO5Q3DQjBXbEVZMDY5aHM\/view?usp=sharing\" target=\"_blank\" rel=\"noopener noreferrer\">AIA DownLoad Link<\/a>: \u00a0This is the MIT APP INVENTOR \u00a0File..<\/h1>\n<p>affiliate links:<\/p>\n<h1><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=l298n&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=a4ed9cbf4f300a636a82f01f0db338b1\" target=\"_blank\" rel=\"noopener noreferrer\">If you don&#8217;t have a L298N H bridge click here to find great prices on these and other arduino stuff!<\/a><\/h1>\n<h1>ARDUINO CODE:<\/h1>\n<p>\/\/Copy and paste this into your arduino ide&#8230;.<\/p>\n<p>#define pin1 2 \/\/ motor #1 +<br \/>\n#define pin2 3 \/\/ motor #1 &#8211;<br \/>\n#define pw1 9 \/\/ motor #1 pwm<br \/>\n#define pin3 4 \/\/ motor #2 +<br \/>\n#define pin4 5 \/\/ motor #2 &#8211;<br \/>\n#define pw2 6 \/\/ motor #2 pwm<br \/>\nvoid setup() {<br \/>\npinMode(pin1, OUTPUT);<br \/>\npinMode(pin2, OUTPUT);<br \/>\npinMode(pin3, OUTPUT);<br \/>\npinMode(pin4, OUTPUT);<br \/>\npinMode(pw1, OUTPUT);<br \/>\npinMode(pw2, OUTPUT);<br \/>\nSerial.begin(9600);<br \/>\ndigitalWrite(pin1, LOW);<br \/>\ndigitalWrite(pin2, LOW);<br \/>\ndigitalWrite(pin3, LOW);<br \/>\ndigitalWrite(pin4, LOW);<br \/>\nanalogWrite(pw1, 50);<br \/>\nanalogWrite(pw2, 50);<\/p>\n<p>}<\/p>\n<p>void loop() {<\/p>\n<p>if (Serial.available() &gt;= 2 )<br \/>\n{<br \/>\nunsigned int a = Serial.read();<br \/>\nunsigned int b = Serial.read();<br \/>\nunsigned int val = (b * 256) + a;<\/p>\n<p>if (val == 100) \/\/ motor 1 reverse<br \/>\n{<br \/>\ndigitalWrite(pin1, LOW);<br \/>\ndigitalWrite(pin2, HIGH);<\/p>\n<p>}<br \/>\nelse if (val == 200) \/\/ motor #1 stop<br \/>\n{<br \/>\ndigitalWrite(pin1, LOW);<br \/>\ndigitalWrite(pin2, LOW);<br \/>\n}<br \/>\nelse if (val == 300) \/\/ motor #1 forward<br \/>\n{<br \/>\ndigitalWrite(pin1, HIGH);<br \/>\ndigitalWrite(pin2, LOW);<br \/>\n}<br \/>\nelse if (val == 400) \/\/ motor #2 reverse<br \/>\n{<br \/>\ndigitalWrite(pin3, LOW);<br \/>\ndigitalWrite(pin4, HIGH);<br \/>\n}<br \/>\nelse if (val == 500) \/\/ motor #2 stop<br \/>\n{<br \/>\ndigitalWrite(pin3, LOW);<br \/>\ndigitalWrite(pin4, LOW);<br \/>\n}<br \/>\nelse if (val == 600) \/\/ motor #2 forward<br \/>\n{<br \/>\ndigitalWrite(pin3, HIGH);<br \/>\ndigitalWrite(pin4, LOW);<br \/>\n}<br \/>\nelse if (val &gt;= 1000 &amp;&amp; val &lt;= 1255)<br \/>\n{<br \/>\nanalogWrite (pw1, val &#8211; 1000);<br \/>\n}<br \/>\nelse if (val &gt;= 2000 &amp;&amp; val &lt;= 2255)<br \/>\n{<br \/>\nanalogWrite (pw2, val &#8211; 2000);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<h1>MIT APP INVENTOR 2 BLOCK DIAGRAM 4\u00a0THE APP:: \u00a0 \u00a0Click on the picture below to enlarge it&#8230;..<\/h1>\n<p><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/blocks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-461\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/blocks.png?w=300\" alt=\"blocks\" width=\"948\" height=\"777\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/blocks.png 2412w, https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/blocks-300x246.png 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/blocks-768x630.png 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/blocks-1024x840.png 1024w\" sizes=\"auto, (max-width: 948px) 100vw, 948px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Check us out on Facebook! APK Download Link: \u00a0This is the ANDROID APP.. AIA DownLoad Link: \u00a0This is the MIT APP INVENTOR \u00a0File.. affiliate links: If you don&#8217;t have a L298N H bridge click here to find great prices on &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=457\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":10,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-457","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=457"}],"version-history":[{"count":2,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/457\/revisions"}],"predecessor-version":[{"id":1492,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/457\/revisions\/1492"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/10"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}