{"id":1043,"date":"2017-04-26T22:35:11","date_gmt":"2017-04-26T22:35:11","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=1043"},"modified":"2019-04-02T10:23:29","modified_gmt":"2019-04-02T10:23:29","slug":"arduino-control-2-dc-motors-via-bluetooth","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-control-2-dc-motors-via-bluetooth\/","title":{"rendered":"Arduino &#8211; Control 2 DC Motors Via Bluetooth (Perfect To Build a Robot)"},"content":{"rendered":"<p>In this tutorial I&#8217;ll show you how to\u00a0control 2 DC motors via bluetooth with an\u00a0Android app\u00a0created with MIT App Inventor 2. MIT App Inventor\u00a0is\u00a0a great platform to get you started with Android development.<!--more--><\/p>\n<div class=\"filename\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-1087\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/thumbdcmotors.jpg?resize=700%2C523&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"523\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/thumbdcmotors.jpg?w=2592&amp;quality=100&amp;strip=all&amp;ssl=1 2592w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/thumbdcmotors.jpg?resize=300%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/thumbdcmotors.jpg?resize=1024%2C764&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/thumbdcmotors.jpg?w=2400&amp;quality=100&amp;strip=all&amp;ssl=1 2400w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/div>\n<p>In a\u00a0previous tutorial (<a title=\"Control DC Motor Via Bluetooth\" href=\"https:\/\/randomnerdtutorials.com\/arduino-control-dc-motor-via-bluetooth\/\">click here to see that project<\/a>),\u00a0I was controlling 1 DC motor using an app called &#8220;BlueTerm&#8221;. That app did the job, but\u00a0it&#8217;s not ideal to send constantly different commands in an easy manner.<\/p>\n<p>The app that you&#8217;re going\u00a0to build is perfect to control any Arduino pin or to integrate with your own <a href=\"https:\/\/randomnerdtutorials.com\/build-robot-car-chassis-kit-arduino\/\">robot car<\/a>. You can edit this app for your specific needs.<\/p>\n<h2>Bluetooth module HC-05<\/h2>\n<p>To establish the bluetooth communication between your smartphone and your Arduino, you need a bluetooth module. This project uses\u00a0the HC-05 bluetooth module\u00a0(as\u00a0shown\u00a0in the figure below).<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-37042\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/Bluetooth-Module.jpg?resize=200%2C181&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"200\" height=\"181\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/Bluetooth-Module.jpg?w=200&amp;quality=100&amp;strip=all&amp;ssl=1 200w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/Bluetooth-Module.jpg?resize=150%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/Bluetooth-Module.jpg?resize=80%2C72&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/Bluetooth-Module.jpg?resize=110%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 110w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/Bluetooth-Module.jpg?resize=166%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 166w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/p>\n<p>This bluetooth module works with serial data. This means that the Arduino sends information and the bluetooth module receives it via serial (and vice-versa).<\/p>\n<p>By default\u00a0the\u00a0HC-05 bluetooth module operates at a baud rate of 9600.<\/p>\n<h2>Creating your Android app<\/h2>\n<p>The Android App will be created\u00a0using a free web application\u00a0called\u00a0<a href=\"http:\/\/appinventor.mit.edu\/explore\/\" target=\"_blank\" rel=\"noopener noreferrer\">MIT App Inventor<\/a>. MIT App Inventor is a great place to get started\u00a0with Android development, because it allows you to build simple apps with drag-n-drop.<\/p>\n<p>You need a Google account to sign up for MIT App Inventor and here\u2019s the login page: <a href=\"http:\/\/ai2.appinventor.mit.edu\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/ai2.appinventor.mit.edu<\/a>.<\/p>\n<p><strong><a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Arduino_Bluetooth_DC_Motors.aia?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the .aia file<\/a>, then watch the video below:<\/strong><\/p>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/-LtbzQ-sTpQ?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><strong>If you go to the Projects tab,\u00a0you can\u00a0upload the\u00a0<a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Arduino_Bluetooth_DC_Motors.aia?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\">.aia file for this project<\/a><\/strong><\/p>\n<p><strong><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-37043\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=448%2C408&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"448\" height=\"408\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?w=448&amp;quality=100&amp;strip=all&amp;ssl=1 448w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=150%2C137&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=300%2C273&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=80%2C73&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=220%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=110%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 110w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=165%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 165w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/import.png?resize=261%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 261w\" sizes=\"(max-width: 448px) 100vw, 448px\" \/><\/strong><\/p>\n<p>With MIT App Inventor you have 2 main sections: designer and blocks.\u00a0The designer is what gives you the ability to add buttons, add text, add screens and edit the overall app look.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37041\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=313%2C519&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"313\" height=\"519\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?w=313&amp;quality=100&amp;strip=all&amp;ssl=1 313w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=90%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 90w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=181%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 181w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=48%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 48w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=133%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 133w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=60%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 60w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=144%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 144w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=250%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_design_mit_app_inventor.png?resize=294%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 294w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/p>\n<p>The blocks sections is what allows to create custom functionality for your app, so when you press the buttons it actually does something with that information.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-37040\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=823%2C314&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"823\" height=\"314\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?w=1090&amp;quality=100&amp;strip=all&amp;ssl=1 1090w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=150%2C57&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=300%2C114&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=768%2C293&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=1024%2C391&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=80%2C31&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=220%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=250%2C95&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=280%2C107&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=510%2C195&amp;quality=100&amp;strip=all&amp;ssl=1 510w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=750%2C286&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_arduino_blocks_mit_app_inventor.png?resize=975%2C372&amp;quality=100&amp;strip=all&amp;ssl=1 975w\" sizes=\"(max-width: 823px) 100vw, 823px\" \/><\/p>\n<p>I recommend that you start by following this project and using the app without modifying it.<\/p>\n<p>If want to make any changes to the app, when you\u2019re done and you want to install the app in your smartphone, go to the Build tab.<\/p>\n<ul>\n<li>You can either generate a QR\u00a0code\u00a0that you can scan with your smartphone and automatically install the app in your smartphone.<\/li>\n<li>Or you can download the .apk file, connect your smartphone to your computer and move the .apk file to the phone.<\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37044\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=416%2C122&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"416\" height=\"122\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?w=416&amp;quality=100&amp;strip=all&amp;ssl=1 416w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=150%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=300%2C88&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=80%2C23&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=220%2C65&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=250%2C73&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/build.png?resize=280%2C82&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 416px) 100vw, 416px\" \/><\/p>\n<p>Simply follow the installation wizard to install the app and it\u2019s done!<\/p>\n<h2>Code<\/h2>\n<p>For this project, you don\u2019t need to install any Arduino libraries.\u00a0So, you just have to download or copy the following code to your Arduino IDE, and upload it to your Arduino board. Make sure that you have the right Board and COM port selected.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * created by Rui Santos, http:\/\/randomnerdtutorials.com\n * Control 2 DC motors with Smartphone via bluetooth\n *\/\n \nint motor1Pin1 = 3; \/\/ pin 2 on L293D IC\nint motor1Pin2 = 4; \/\/ pin 7 on L293D IC\nint enable1Pin = 6; \/\/ pin 1 on L293D IC\nint motor2Pin1 = 8; \/\/ pin 10 on L293D IC\nint motor2Pin2 = 9; \/\/ pin 15 on L293D IC\nint enable2Pin = 11; \/\/ pin 9 on L293D IC\nint state;\nint flag=0;        \/\/makes sure that the serial only prints once the state\nint stateStop=0;\nvoid setup() {\n    \/\/ sets the pins as outputs:\n    pinMode(motor1Pin1, OUTPUT);\n    pinMode(motor1Pin2, OUTPUT);\n    pinMode(enable1Pin, OUTPUT);\n    pinMode(motor2Pin1, OUTPUT);\n    pinMode(motor2Pin2, OUTPUT);\n    pinMode(enable2Pin, OUTPUT);\n    \/\/ sets enable1Pin and enable2Pin high so that motor can turn on:\n    digitalWrite(enable1Pin, HIGH);\n    digitalWrite(enable2Pin, HIGH);\n    \/\/ initialize serial communication at 9600 bits per second:\n    Serial.begin(9600);\n}\n\nvoid loop() {\n    \/\/if some date is sent, reads it and saves in state\n    if(Serial.available() &gt; 0){     \n      state = Serial.read();   \n      flag=0;\n    }   \n    \/\/ if the state is 'F' the DC motor will go forward\n    if (state == 'F') {\n        digitalWrite(motor1Pin1, HIGH);\n        digitalWrite(motor1Pin2, LOW); \n        digitalWrite(motor2Pin1, LOW);\n        digitalWrite(motor2Pin2, HIGH);\n        if(flag == 0){\n          Serial.println(&quot;Go Forward!&quot;);\n          flag=1;\n        }\n    }\n    \n    \/\/ if the state is 'R' the motor will turn left\n    else if (state == 'R') {\n        digitalWrite(motor1Pin1, HIGH); \n        digitalWrite(motor1Pin2, LOW); \n        digitalWrite(motor2Pin1, LOW);\n        digitalWrite(motor2Pin2, LOW);\n        if(flag == 0){\n          Serial.println(&quot;Turn LEFT&quot;);\n          flag=1;\n        }\n        delay(1500);\n        state=3;\n        stateStop=1;\n    }\n    \/\/ if the state is 'S' the motor will Stop\n    else if (state == 'S' || stateStop == 1) {\n        digitalWrite(motor1Pin1, LOW); \n        digitalWrite(motor1Pin2, LOW); \n        digitalWrite(motor2Pin1, LOW);\n        digitalWrite(motor2Pin2, LOW);\n        if(flag == 0){\n          Serial.println(&quot;STOP!&quot;);\n          flag=1;\n        }\n        stateStop=0;\n    }\n    \/\/ if the state is 'L' the motor will turn right\n    else if (state == 'L') {\n        digitalWrite(motor1Pin1, LOW); \n        digitalWrite(motor1Pin2, LOW); \n        digitalWrite(motor2Pin1, LOW);\n        digitalWrite(motor2Pin2, HIGH);\n        if(flag == 0){\n          Serial.println(&quot;Turn RIGHT&quot;);\n          flag=1;\n        }\n        delay(1500);\n        state=3;\n        stateStop=1;\n    }\n    \/\/ if the state is 'B' the motor will Reverse\n    else if (state == 'B') {\n        digitalWrite(motor1Pin1, LOW); \n        digitalWrite(motor1Pin2, HIGH);\n        digitalWrite(motor2Pin1, HIGH);\n        digitalWrite(motor2Pin2, LOW);\n        if(flag == 0){\n          Serial.println(&quot;Reverse!&quot;);\n          flag=1;\n        }\n    }\n    \/\/For debugging purpose\n    \/\/Serial.println(state);\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\/MIT-App-Inventor\/Control_2_DC_Motors_Via_Bluetooth.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<p><strong><span style=\"color: #ff0000;\">Note:<\/span> before uploading the code, make sure you have the TX and RX pins disconnected from the bluetooth module!<\/strong><\/p>\n<h2>Parts Required<strong><a href=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/parts.jpg\"><br \/>\n<\/a><\/strong><\/h2>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1089\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/parts.jpg?resize=368%2C276&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"parts\" width=\"368\" height=\"276\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/parts.jpg?resize=1024%2C764&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/parts.jpg?resize=300%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/parts.jpg?w=2400&amp;quality=100&amp;strip=all&amp;ssl=1 2400w\" sizes=\"(max-width: 368px) 100vw, 368px\" \/><\/p>\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\/bluetooth-module-hc-06\/\" target=\"_blank\" rel=\"noopener noreferrer\">Bluetooth module HC-04 or HC-05 or HC-06\u00a0<\/a><\/li>\n<li>1x L293D IC<\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mini-dc-motor\/\" target=\"_blank\" rel=\"noopener noreferrer\">2x DC motors<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires\u00a0<\/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<h2>Schematics<\/h2>\n<p>Follow the schematic diagram in the following figure to wire your circuit.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/DC-motor-Schematics.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1044\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/DC-motor-Schematics.png?resize=427%2C521&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"DC motor Schematics\" width=\"427\" height=\"521\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/DC-motor-Schematics.png?w=610&amp;quality=100&amp;strip=all&amp;ssl=1 610w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/DC-motor-Schematics.png?resize=245%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 245w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/dc.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1088\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/dc.jpg?resize=430%2C321&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"dc\" width=\"430\" height=\"321\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/dc.jpg?resize=1024%2C764&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/dc.jpg?resize=300%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/dc.jpg?w=2400&amp;quality=100&amp;strip=all&amp;ssl=1 2400w\" sizes=\"(max-width: 430px) 100vw, 430px\" \/><\/a><\/p>\n<h2>Launching your app<\/h2>\n<p>If you haven\u2019t generated the .apk file in a previous step, you can\u00a0<a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Arduino_Bluetooth_DC_Motors.apk?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>click here to download the .apk file<\/strong><\/a> (which is the Android app installation file).\u00a0Move that file to your smartphone and open it. Follow the installation wizard to install the app.<\/p>\n<p>Turn on your smartphone\u2019s Bluetooth.<\/p>\n<p>Tap on the newly installed\u00a0app. Press the\u00a0\u201cConnect\u201d button to connect your application to your Arduino Bluetooth module.<\/p>\n<p>Now you can easily control the 2 DC motors with your app:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37046\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=337%2C338&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"337\" height=\"338\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?w=337&amp;quality=100&amp;strip=all&amp;ssl=1 337w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=300%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=80%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=220%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=100%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 100w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/android_app_2d_motors.png?resize=237%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 237w\" sizes=\"(max-width: 337px) 100vw, 337px\" \/><\/p>\n<h2>Watch this video\u00a0demonstration<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/3RsfA6ngLdQ?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><strong>Troubleshooting:<\/strong><\/p>\n<ul>\n<li>Remove the RX and TX cables when you\u2019re uploading a new sketch to your Arduino board<\/li>\n<\/ul>\n<ul>\n<li>People often connect the TX from the bluetooth module to the TX of the Arduino, that won&#8217;t work. Make sure you connect:\u00a0TX goes to\u00a0RX and RX goes to\u00a0TX.<\/li>\n<\/ul>\n<ul>\n<li>If the HC-04\/HC-06&amp;HC-05 bluetooth module asks for a password, it\u2019s \u20191234\u2032.<\/li>\n<\/ul>\n<h2>Wrapping up<\/h2>\n<p>I hope you found this useful.<\/p>\n<p>Do you know a friend that would like to see this project?\u00a0Make sure you share this project with your friend!<\/p>\n<p>Do you want to learn more about building apps for Arduino? Get access to our course:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/android-apps-for-arduino-with-mit-app-inventor-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">Android Apps for Arduino\u00a0with MIT App Inventor 2<\/a>.<\/p>\n<p>Thanks for reading,<\/p>\n<p>Rui<\/p>\n<p><strong>P.S.<\/strong> If you don&#8217;t have a bluetooth module,\u00a0<a title=\"Reviews - Bluetooth Module\" href=\"https:\/\/randomnerdtutorials.com\/parts-hc-05-bluetooth-module-review\/\">read my HC-05 review here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial I&#8217;ll show you how to\u00a0control 2 DC motors via bluetooth with an\u00a0Android app\u00a0created with MIT App Inventor 2. MIT App Inventor\u00a0is\u00a0a great platform to get you started &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino &#8211; Control 2 DC Motors Via Bluetooth (Perfect To Build a Robot)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-control-2-dc-motors-via-bluetooth\/#more-1043\" aria-label=\"Read more about Arduino &#8211; Control 2 DC Motors Via Bluetooth (Perfect To Build a Robot)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":1087,"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":[303,271,267,2,264,10],"tags":[184,183,180,181,182],"class_list":["post-1043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-android","category-arduino-project","category-arduino","category-project","category-a-tutorials","tag-android-app-to-control-an-arduino","tag-android-app-to-control-arduino","tag-control-arduino-via-dc-motor","tag-dc-motor-arduino","tag-how-to-control-a-dc-motor"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/09\/thumbdcmotors.jpg?fit=2592%2C1936&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/1043","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=1043"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/1043\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/1087"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=1043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=1043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=1043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}