Arduino – Control 2 DC Motors Via Bluetooth (Perfect To Build a Robot)

In this tutorial I’ll show you how to control 2 DC motors via bluetooth with an Android app created with MIT App Inventor 2. MIT App Inventor is a great platform to get you started with Android development.

In a previous tutorial (click here to see that project), I was controlling 1 DC motor using an app called “BlueTerm”. That app did the job, but it’s not ideal to send constantly different commands in an easy manner.

The app that you’re going to build is perfect to control any Arduino pin or to integrate with your own robot car. You can edit this app for your specific needs.

Bluetooth module HC-05

To establish the bluetooth communication between your smartphone and your Arduino, you need a bluetooth module. This project uses the HC-05 bluetooth module (as shown in the figure below).

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).

By default the HC-05 bluetooth module operates at a baud rate of 9600.

Creating your Android app

The Android App will be created using a free web application called MIT App Inventor. MIT App Inventor is a great place to get started with Android development, because it allows you to build simple apps with drag-n-drop.

You need a Google account to sign up for MIT App Inventor and here’s the login page: http://ai2.appinventor.mit.edu.

Click here to download the .aia file, then watch the video below:

If you go to the Projects tab, you can upload the .aia file for this project

With MIT App Inventor you have 2 main sections: designer and blocks. The designer is what gives you the ability to add buttons, add text, add screens and edit the overall app look.

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.

I recommend that you start by following this project and using the app without modifying it.

If want to make any changes to the app, when you’re done and you want to install the app in your smartphone, go to the Build tab.

  • You can either generate a QR code that you can scan with your smartphone and automatically install the app in your smartphone.
  • Or you can download the .apk file, connect your smartphone to your computer and move the .apk file to the phone.

Simply follow the installation wizard to install the app and it’s done!

Code

For this project, you don’t need to install any Arduino libraries. So, 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.

/*
 * created by Rui Santos, https://randomnerdtutorials.com
 * Control 2 DC motors with Smartphone via bluetooth
 */
 
int motor1Pin1 = 3; // pin 2 on L293D IC
int motor1Pin2 = 4; // pin 7 on L293D IC
int enable1Pin = 6; // pin 1 on L293D IC
int motor2Pin1 = 8; // pin 10 on L293D IC
int motor2Pin2 = 9; // pin 15 on L293D IC
int enable2Pin = 11; // pin 9 on L293D IC
int state;
int flag=0;        //makes sure that the serial only prints once the state
int stateStop=0;
void setup() {
    // sets the pins as outputs:
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(enable1Pin, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2, OUTPUT);
    pinMode(enable2Pin, OUTPUT);
    // sets enable1Pin and enable2Pin high so that motor can turn on:
    digitalWrite(enable1Pin, HIGH);
    digitalWrite(enable2Pin, HIGH);
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}

void loop() {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){     
      state = Serial.read();   
      flag=0;
    }   
    // if the state is 'F' the DC motor will go forward
    if (state == 'F') {
        digitalWrite(motor1Pin1, HIGH);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);
        if(flag == 0){
          Serial.println("Go Forward!");
          flag=1;
        }
    }
    
    // if the state is 'R' the motor will turn left
    else if (state == 'R') {
        digitalWrite(motor1Pin1, HIGH); 
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        if(flag == 0){
          Serial.println("Turn LEFT");
          flag=1;
        }
        delay(1500);
        state=3;
        stateStop=1;
    }
    // if the state is 'S' the motor will Stop
    else if (state == 'S' || stateStop == 1) {
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        if(flag == 0){
          Serial.println("STOP!");
          flag=1;
        }
        stateStop=0;
    }
    // if the state is 'L' the motor will turn right
    else if (state == 'L') {
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);
        if(flag == 0){
          Serial.println("Turn RIGHT");
          flag=1;
        }
        delay(1500);
        state=3;
        stateStop=1;
    }
    // if the state is 'B' the motor will Reverse
    else if (state == 'B') {
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, HIGH);
        digitalWrite(motor2Pin1, HIGH);
        digitalWrite(motor2Pin2, LOW);
        if(flag == 0){
          Serial.println("Reverse!");
          flag=1;
        }
    }
    //For debugging purpose
    //Serial.println(state);
}

View raw code

Note: before uploading the code, make sure you have the TX and RX pins disconnected from the bluetooth module!

Parts Required

parts

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematics

Follow the schematic diagram in the following figure to wire your circuit.

DC motor Schematics

dc

Launching your app

If you haven’t generated the .apk file in a previous step, you can click here to download the .apk file (which is the Android app installation file). Move that file to your smartphone and open it. Follow the installation wizard to install the app.

Turn on your smartphone’s Bluetooth.

Tap on the newly installed app. Press the “Connect” button to connect your application to your Arduino Bluetooth module.

Now you can easily control the 2 DC motors with your app:

Watch this video demonstration

Troubleshooting:

  • Remove the RX and TX cables when you’re uploading a new sketch to your Arduino board
  • People often connect the TX from the bluetooth module to the TX of the Arduino, that won’t work. Make sure you connect: TX goes to RX and RX goes to TX.
  • If the HC-04/HC-06&HC-05 bluetooth module asks for a password, it’s ’1234′.

Wrapping up

I hope you found this useful.

Do you know a friend that would like to see this project? Make sure you share this project with your friend!

Do you want to learn more about building apps for Arduino? Get access to our course: Android Apps for Arduino with MIT App Inventor 2.

Thanks for reading,

Rui

P.S. If you don’t have a bluetooth module, read my HC-05 review here.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

345 thoughts on “Arduino – Control 2 DC Motors Via Bluetooth (Perfect To Build a Robot)”

  1. i already did it for my sumobot project… but i get the idea from your previous video that control one dc motor.. and i’m really thankful to to this site… may i ask you if the android app that you use in this video is your own code..?

    Reply
    • Thanks for trying my projects!
      Yes this Android app was created by me using MIT App Inventor.
      your can download all my source code for free. (just click share and a download link will unlock)
      (I know we already talked through facebook, but I want to reply also through my blog! : ) )

      Reply
  2. Hi my friend!

    I had a problem in this proyect… when a charge the code, in the botton it says “avrdude: stk500_getsync(): not in sync: resp=0x00”

    And one motor star to move without pressing “1” or “2”, etc…
    What could probably be?

    Reply
    • Hey Henry! Thanks for stopping by and try my project!

      Just two quick questions.
      Are you using the exact same parts as me? (and you followed my exact schematics?)
      which version of the Arduino IDE you’re using?

      The DC motors should only be moving after you pressed some buttons.

      (before even connecting your Bluetooth module)
      First try to control the DC motors with the serial monitor by sending ‘1’, ‘2’, etc . And they should be working just fine.

      Please let me know if it’s working!

      Reply
  3. hi rui… i want try this tutorial. but do u have full source code app in android ? and what apps to use that’s apps? ECLIPSE ? or ANDROID STUIDO ? .

    thank’s

    Reply
    • Hi! Thanks for taking the time to leave a comment!
      Yes you can definitely do that!
      I recommend you to use the IC because it’s easier and It looks more “clean”
      But if you prefer to use a Dual H-Bridge it will work exactly the same!

      Let me know if this helped you.
      Good luck with your project,
      Rui Santos

      Reply
  4. hi rui

    can i use Bluetooth Serial Module (HC-05 Master/Slave mode) in this project ? becuse i’m not sure this module have 6 pin.

    thank you so much :’D

    Reply
  5. Hi Rui

    just to let you know. Ive Powered my HC-07 Module with 3.3v and without using voltage divider for the output of the arduino. it worked well for 5 min only. then the HC-07 STOP working. i think the my bluetooth module has burnt or damaged permanently :(.

    im thinking to use Order LC-05 to try it. What do you think

    http://www.aliexpress.com/item/LC-05-bluetooth-serial-interface-module-wireless-serial-interface-module-through-the-wireless-module-free-shipping/638543403.html

    Reply
  6. HI Rui
    I’ve got a question, does your arduino code just works with the hc-05 bluetooth module or I can use another one like the hc-06 ,this one has 4 pins?

    Thanks a lot for the tutorial

    Reply
    • Hi David,
      thanks for taking the time to watch my tutorials.
      I think by default it will work.
      They are exactly the same. but the HC-05 has some pins, and the HC-06 you need to solder wires.
      But they work the same.
      Good luck with your project,
      Rui Santos

      Reply
  7. hola soy de chile y me encanto tu tutorial el problema es que no me deja bajar la aplicación desde mi teléfono… como lo puedo instalar?

    Reply
    • Hi,
      I don’t speak Spanish. but I know Portuguese. So I understood what you said.
      My app is available to download here: https://randomnerdtutorials.com/download
      Simply enter your email and you’ll receive a secret download page with all my projects.

      Or you can simply click the like button and the code will unlock.

      thanks for stopping by!

      Reply
    • Hi Andi.
      For what I’ve heard that LC-05 Bluetooth module works with my project.
      I’ve not tried it myself but it should work.
      the password and bluetooth configurations might be different.

      The programming is done in the Arduino.
      you don’t need to programm the Arduino Module.

      Thanks for taking the time to read my projects!

      Reply
  8. Hi Rui

    I wanna ask you something more about the password, when i pair the bluetooth modul they ask about pass but stil not work to connected. The bluetooth module dont ask about the pass. What i must to do?

    Thanks

    Reply
    • Hi Andi.
      First go to your bluetooth settings and pair your smartphone with the Bluetooth module.
      (Use the password ‘1234’ or ‘0000’.)
      As soon as it’s paired. Go to the ArdBlue app and click: “Choose device to connect to” and choose your bluetooth module.

      I hope this solves your questions.
      Rui Santos

      Reply
  9. Hi RuiSantos,

    I have got a problem when I tried to set up the hardware of what you introduced above; however, I found out that there were signals of int1 and int4 were locked to turn on the LED light and one of motors was continuously running forward only (another one was stopped) when I used generic motors to connect L298 development board module, which was connected to Arduino Uno development board. I could not control pinint1 to pinint4 by using your Skretch programme.

    I tried not to supply power to motor and only run your sktech program to send signal to control pinint1 to pinint4 of L298, it was successful for me to see the response of the MCU controling normal.

    Could you tell me what wrong with my hardware setting? Does noise come from the motor since the ground is commonly connected between L298 and Arduino Uno?
    How can I solve this problem please?

    Best regards,

    Peter

    Reply
    • Can you tell me exactly which motor board are you using?
      (Send me a link with the information)

      You’re debugging all your code using the Arduino IDE? right?

      which DC motors are you using?

      Reply
      • Hi Rui,

        I fixed the problem already since being careless of matching pins between Atmega328 and L293D. I am using motor drive of L293D of Sparkle Brand to connect Arduino Uno. Thank you for your reply.

        Reply
  10. Hi Rui,

    I am urgent to know your opinion for the problem solving since this will become reference for my college project please. Thanks you very much.

    Peter

    Reply
  11. Hi Rui,

    I am urgent to need knowing your opinion since I will take your tutorial case as a example for my owned project. Could you reply me as soon as possible please?

    Thanks,

    Peter

    Reply
    • Boas Daniel,

      Sim a ideia por de trás do programa é o mesmo,
      só tens que mudar o código do Arduino e em vez de controlares um DC motor é um stepper motor.
      Tenta procurar um exemplo de Arduino com stepper motors para teres mais umas ideias!

      Abraço,
      Rui

      Reply
  12. Hai Rui,

    i have a problem with this arduino. My dc motor can run if i connect with my laptop (usb) but with 9v battery cannot run. Blueterm not response if i enter numbers with 9v battery, but with usb, the blueterm is completely response and my dc motor run (left, right, off). Why?

    Reply
    • Hi, thanks for trying my projects..
      The problem is simple.
      The 9V battery don’t have enough current for your circuit, you will need another type of battery that can handle more current.

      The bluetooth module and DC motors takes to much current from the 9V battery

      Reply
    • Hi, thanks for trying my projects..
      The problem is simple.
      The 9V battery don’t have enough current for your circuit, you will need another type of battery that can handle more current.

      The bluetooth module and DC motors takes to much current from the 9V battery.

      Reply
    • Hi,
      thanks for your feedback.
      That question requires almost an entire tutorial.
      What I can tell you right now is that it works like it does with the Arduino… The bluetooth module will establish a communication via the TX and RX pins.
      and your smartphone will establish a communication with the bluetooth module.

      It will also depend in which PIC you’ll be using. you need to read the datasheet…

      Reply
  13. hi..is it possible to power up arduino like in your project with 18v dc supply (2 9v dc battery connected in series)??since it doesnt work in 9v dc supply??and what can you advice to me to power up my bluetooth controlled robot..
    thanks morepower..

    Reply
    • Don’t do that… That’s not a good idea. Too much current probably.
      One way to do that is using AA batteries with some battery holder.

      The best way is to get a LiPo rechargeable battery for the Arduino.
      Here are some that might be good for your project:
      http://www.adafruit.com/category/44

      before you buy anything make sure you get the right for your motors too.
      the problem with the 9V batteries is that they don’t have much current. It’s better to use AA batteries in series 🙂

      I hope this helps bryle!
      Have a nice day,
      Rui

      Reply
      • Hi, Thanks you for your remind. Yes, it may be lack of current for 9Vlot battery. In adddition, I had use your Android app and would like to add on new things on it. However, I do not how to open your attahced files such as .src and project.perproties Could you tell me how I can open your generic Android app source code in App Inventor please? I know that I have to use App Inventor on MIT wedsite, is there an off-line App Inventor for me to run the changing of the source code on Window platform please?

        Reply
        • hi Peter, I’m almost sure it’s lack of current… that’s the problem with 9V batteries…

          I’ve made a video using MIT app inventor.
          It runs on the browser and windows at the same time.
          (You create the screen and look of your app on the browser. The functions, what your app actually does is programmed with a windows application.)
          https://randomnerdtutorials.com/how-to-use-app-inventor-with-arduino/

          Please watch the video on that post where I explain everything. Let me know if you have any questions!

          Rui

          Reply
  14. thanks a lot rui..for helping..
    im kind of confious sir ,about the IC of L293D..cause there’s another one IC the L293DNE??you think it really matters if i use the L293DNE IC..thanks for helping sir

    Reply
    • Hi Bryle,
      I’m glad I could help.
      Some IC’s have different versions, the L293D as some variations just like the L293DNE.
      I just took a quick look and they seem to work exactly the same.
      But before you test anything check both IC’s datasheets and compare the pins Inputs and Outputs and voltages.

      Reply
  15. Hi Rui,
    Could you tell me which development platform for me to edit soruce code for BlueArd please? Is it Eplice or Oracle Java Development Platform?
    Since I would like to edit source code for BlueArd, could you share with me whether there is an off-line App Inventor application software to use? Sometimes I can’t do interface development by online-MIT App Inventor. Thanks

    Reply
    • Hi Peter,
      When you download that .zip folder it comes with 3 files.

      Arduino Sketch
      BlueArd.apk
      BlueArd Source files (for editing purpose)

      The BlueArd.apk is the app installation file.
      If you want to edit the app simply upload the BlueArd Source files into MIT APP Inventor.

      You need to be online to use MIT App Inventor…

      Reply
      • Hi Rui,

        Thank you for your answer; howver, is it possible for me to edit the source code of the app by using off-line App Inventor or other opensource freeware please?

        In addition, I’ve got another problem that I could contorl turn left and right of the mobile robot using Android cell phone; but the robot could not be morved forward and backward, somethimes left wheel was moving meanwhile right wheel was not moving in parallel speed. I wonder whether the circuit power could not supply to motors via L293D since I am using 9 Vltage battery to supply power the whole MCU control circuit board and L293D.
        My tutor told me that it shall be supplied of power to motors vis L293D independently.
        Could you share with me your opinion please?
        Many thanks.

        Reply
      • Hi Rui,

        I had followed your suggestion to open BlueArd project source code, but the online program prompted me error since your project.property file is not .aia file.
        I could not attach the print screen for your reference; would you advise where I can download your a completed update projecy source codes please?
        Thanks

        Reply
        • yup you’re right my source files no longer work with MIT app Inventor…
          They updated their entire website.
          I need to create everything again from scratch…
          Right now I don’t have the time do that… in 2 weeks or something I’ll create a new source code.

          Sorry. They erased all my projects that I thought were saved :S

          Reply
          • Hi Rui,

            Yes. MIT App Inventor updated to version 2; but finally I could find out the old version to edit your soure codes. Many thanks.

  16. Hey,
    I am using a single 9v battery and following your tutorial exactly. Also I am using 2 12v dc motors (60rpm). Is the 9v battery suuficient to run the motors? If not, what alternative can i use?

    Reply
    • Hi Piyush,
      No… the 9V battery won’t be able to handle that.

      I would recommend you to get some Lipo rechargeable batteries for your project!

      Reply
  17. Hey Rui,
    I purchased an hc 05.. but it has 6 pins.. There are 2 voltage pins.. 5v and 3.3v.. Which pin should i connect to my arduino..also do i need a voltage divider to connect my hc 05 rx tx pins to arduino?

    Reply
  18. Hi sir rui thanks again for helping..sir can you help me where to put voltage divider and how to make voltage divider?like providing me schematics that i can easily understand cause im a newbie in arduino and also to electronics..please help me sir..merry christmas sir

    Reply
  19. hello friend have a doubt everything works but the part where you press STOP, FORWARD and BACKWARD not work, only works for the left and right and not to do, please a solution, I did all the step to the tutorial is not wrong if the APP
    arduino or codes.
    please help me is for my final semester project please.
    congratulations and greetings from grasias por conpartir PERU 2014 and happy new year hope your prompt help.

    Reply
    • Hi Kishuko.
      Thanks for trying my project!

      Does the stop, forward, backward commands work when you’re testing you’re project using only the Arduino Serial monitor?

      Happy new year,
      Rui

      Reply
    • Hi Bryle,
      Please first read the update on top of this page.
      then you need to download the source code provided.

      it include a .zip folder with 3 files inside.
      Unzip it and you need to upload the BlueArd Source files into App inventor.

      Reply
  20. Rui,

    Thanks for this great tutorial. I have downloaded your source code and have it setup. I am hoping to add in some buttons for lights and other functions, but was wondering how you figured out which byte number to send to correspond to the arduino pin. Button1 (GO!) = 49, which drives motors forward.

    I’m happy to send you the code when I have it implemented.

    Thanks

    Reply
      • How did you figure out which byte number to send to correspond to the arduino pin. Example: Button1 (GO!) = 49, which drives motors forward from a pin.

        If I wanted to turn on a light using digital input 8, what byte would I send?

        Reply
        • That byte has nothing to do with the Arduino digital pins…
          if you want to turn on a light using the digital pin 8 you can create an if statement for example.
          if(state==’0′ ){
          digitalWrite(8,HIGH);
          }

          and the Android app would send a 49 to the arduino via bluetooth.
          if you want to turn off for instance you can do this.

          if(state==’1′){
          digitalWrite(8,LOW);
          }
          The Android app will send a 50 via bluetooth.

          this is just an example you can send any values you want and you arduino code can do whatever you want.
          I hope this helps,
          Rui

          P.S. Please download all my code, upload it to the App Inventor (read the update at the top of the page) and you’ll see how it works 🙂

          Reply
  21. Hey Rui,
    I am following your project and using 2 12v DC motors. I am making an independent robot so won’t be providing power through USB. I am thinking of providing external power supply to Vc pin of l293d which provide power for the motors only instead of directly connecting it with the 5v pin of arduino. So what do you suggest as a power supply for arduino and power supply for the motors separately?

    Reply
    • Hi Simon,
      As you said you need an external power supply.
      If it’s to control something that need to be in movement like a robot.
      I would get a Lipo rechargeable battery to power up those motors.

      Otherwise just find a 12V wall chart power supply
      I hope this helps

      Reply
  22. gudeve sir rui..
    what exact current do i need to run the motor like a robot??
    i tried to connect the motor on a four 1.5v battery, and 9v battery for arduino and bluetooth module..it runs, but when i tested it on ground the motor seems cannot handle the load..please help..godbless sir

    Reply
    • You need to read the datasheet from your DC motor…
      and see how much voltage and current it needs to work properly.
      Then search for the right battery for that…

      Reply
  23. hi rui, first of all great project man….but there is a problem with BLUEARD…..it shows an error….. “Need BLUETOOTH_ADMIN permission: neither user 10115 nor current process has android.permission BLUETOOTH_ADMIN”

    Reply
  24. j’ai un module JY-MCU Bluetooth Wireless Serial Port Module for Arduino que je l’ai acheté de ce site: et je veux savoir est qu’il marche ou pas ainsi s’il vous plait vous pouvez m’envoyer le code source sur mon mail:

    Reply
  25. which platform u r using to create apk file….even im using ecllipse
    i downloaded ur apk files but how can i edit those files…pls guide me throgh out this project plzzz….and send me the coding for arduino

    Reply
  26. hi rui i need ur assistance through out my project so pls help me….i want make an car controlled over bluetooth using android app….so send me details about it
    and which platform u r using to create android app…im using eclipse…and send the details of everypart that needs to tis project…thank you

    Reply
  27. hey rui
    i want screen shot of appiinventor bluetooth connection designer block……
    and i want to learn how to creat app in app inventor ….

    Reply
  28. Dear Random Archive BlueArd Source (for editing purpose), I can not open from the MIT App Inventor please point me how I can edit?

    Reply
    • The source for this project can only be edited with MIT App inventor Classic version.
      It won’t open with AI2.
      (Please read the top of this page and you’ll understand where you need to go)

      Thanks for trying my project!
      Rui

      Reply
  29. Hi Rui Santos,
    I have a question, why pin Vcc Bluetooth HC-05 has been given 5V DC from pin 5V DC Arduino (as a reference datasheet Bluetooth HC-05 max 3.3V) ? It could be damage, isn’t it?
    Thanks for your explain.

    Reply
  30. Hi, I am creating a app used in bluetooth control wheelchair via arduino in my project. Your design inspire me a lot, thank you!
    However, I have a problem, I downloaded your source which used in app inventor and arduino code.When I ran it, the app said my android phone was connected bluetooth with arduino but it had no response when I clicked the button on my phone. The strange thing is that it responses correctly when I enter signal by serial monitor like “1”,”2″,”3″. I can’t find out the problem, do you have any idea?

    Reply
    • Did you connect the TX from the bluetooth Module to the RX of the Arduino? (and vice versa)

      Can you elaborate a bit more otherwise it can be a compatibility problem with your smartphone…

      Reply
    • Hi jezreel,
      I’ve only tested this project with this bluetooth module.
      If you already have a different one you should try.
      This project should work just fine with any bluetooth module, because all of them establish a serial communication with the Arduino.

      Have a nice day,
      Rui

      Reply
  31. Nice app U got there! I have one dc motor to control! that should be a problem! i would love to change your app so there were 4 buttons !2 of them just the way it is – on a push it sends a comand but 2 of them would be working like so – when i push it and hold it – it would send letter A to arduino and on a release it would send lower case coreseponding comand letter , in this case a! and for other button B,b! BUT THERE IS ONE PROBLEM – i don`t know how to make such a button witch works on touch and release….

    Reply
    • Thanks Kaspras,
      I’m glad you found my app useful.

      I recommend you to test my project first and see if it’s working for you.
      Then open my app with MIT App inventor and start getting familiar with the programming environment.
      It’s pretty easy to do what you’re looking for.
      They have pre-built in functions to trigger actions On click buttons for example.

      Have a nice day,
      Rui

      Reply
  32. Still can`t find a way to edit a button to make it work like i need to….on a push it would send a capital A and on a release it would send lower case letter a !

    Reply
  33. Changed to my needs your app… except i can`t find info on how to create a button witch sends on comand when i press the button and hold but then when i release it sends another. like rc car control button

    Reply
  34. Hi,
    does this bluetooth module HC-06 works correctly with this project?
    The link is here
    fabtolab.com/HC-06-bluetooth-module?search=HC-06%20Bluetooth%20Module

    Reply
  35. How to seperate those 2 comands – i`ve added them but i need that seperation…PLEASE take a look and try to explain to this dum man what he need to do to make this finaly work… http://tinypic.com/r/wwnty9/8
    Would even these comands go to arduino serial like when i send them trough arduino serial monitor?

    Reply
    • I don’t have the time to make the code for everyone who asks me sorry.
      There’s simply not enough time in the day to do that.
      I already told you you can use the long click function to do that.
      and you can use a NOT logic block for example to see when you stop pressing the buttons.

      I guess you can change most of the arduino code to do exactly that. and don’t worry so much with the app.

      Sorry for not being able to help you much more than this.
      Have a nice day,
      Rui

      Reply
  36. Hallo Rui,

    first of all thank you for your awesome description!!
    I had made some more buttons in the App and build some LEDs that can show the way, but now i don’t know how to set my arduino that the motors only run when i press the bottons on the app without using a stop botton…

    Do you know a way to to this?

    Thanks a lot
    Stefan

    Reply
    • Hi Stefan,
      Please read some of the comments above.
      I think that can be accomplished with the LongClick feature of the buttons.
      and the change the arduino code to be able to do that.

      Thanks for asking,
      Rui

      Reply
  37. Sir when i m trying to connect with HC05 module with my phone using blueArd app then it showing…

    Runtime error
    Need BLUETOOTH_ADMIN permission:Niether user 10113 nor currentprocess has android permission. BLUETOOTH_ADMIN

    pls sort out my issue.

    its paired and working good with serial monitor.but not working with app blueArd(not connecting actually).sor out plz

    Reply
    • Can you try this project with another smartphone?
      It might be a compatibility problem with yours i guess.
      Or you have to root your android…

      Reply
  38. Hi Rui
    How to change the baud rate of the bluetooth module? Mine (HC-06) has default baud rate of 38400. I want to change it to 9600, need you valuable advice.
    Thanks in anticipation…

    Reply
  39. hey there
    awesome work bro!
    just wanna ask one thing if I want to activate an alarm whenever I stop the motors, does it possible with extra components and if yes please help me!

    Reply
    • Yes,
      That’s something you can easily do.
      Open my arduino code provided-
      Simply add a new OUTPUT in the Arduino (a new digital pin). That way you can control some type of buzzer.
      Then in the “if” statement related to the “STOP” button
      Simply activate that buzzer everytime it’s pressed the button

      I hope this helps!

      Reply
  40. Hi Rui Santos
    I want to use the captor LM35 in the program but i didn’t found his library , can you help me please!!thanks for anticipation .

    Reply
    • Hi Ayoub,
      Can you send me a link for the part you want a library?
      And I’ll see if I can’t find.
      Have a nice day,
      Rui

      Reply
  41. Hi, currently I’m working on this similar project but controlling the mobile robot through the accelerometer sensor. Now, I’m facing problem on my Bluetooth connection. I successfully pairing both my android and arduino uno. On the serial monitor it shows the data but my DC motor is not rotate. I dont know why. Do I need to setup or configure anything with the Bluetooth module?? This is my first time using arduino with bluetooth connection and I’m really noob. Help me pls..

    AS for this project, I’m using:

    1.Arduino Uno
    2.Cytron Bluetooth Module (http://www.cytron.com.my/viewProduct.php?pcode=BLUEBEE) + XBee Shield (http://www.cytron.com.my/viewProduct.php?pcode=SHIELD-XBEE)

    Reply
    • Hi!
      What app are you using?
      have you started making the code for the accelerometer?
      If you’re trying to use the bluetooth project for the first time.
      I recommend you to test my project first as an example and see if it works for you.
      Then later start creating your own projects.

      I hope this helps,
      Rui Santos

      Reply
      • Thanks for reply Mr. Rui Santos,

        At the moment I develop my own apps using MIT App Inventor..In fact, I also try to use the available apps by downloading them..sadly both of the apps didn’t work. What do you mean code for accelerometer? Is it the arduino code or the apps code?

        Reply
  42. hi
    im doing the project control of dc motors using smart phone
    i can control the motors by serial monitor.but not work on my smart phone.(using galaxy duos)
    please help

    Reply
  43. Hello!
    could you help to build an app like that by sharing the screen shots of “DESIGNER” AND “BLOCK”?
    THANKING IN ADVANCE

    Reply
  44. Hey Rui Thanks for the awesome tutorial..

    I am trying to implement the same project using the same parts and arduino duemilanove now the problem is i am able to control the motors via the serial monitor of the ide but not via Bluetooth neither app or blueterm. I have tested the bluetoth module for communication via the led blink example.
    also when i input commands via the serial monitor the commands motor left , right etc appear on the blueterm on my mobile but not being able to enter anything on the mobile

    Reply
    • Hi Zeon,
      Have you tried all the steps I tell you on the tips?
      Are the bluetooth cables connected to the Arduino properly?
      TX from the Arduino goes to the RX of the Bluetooth module, etc…

      Reply
  45. If I remove Arduino’s Atmega328 IC and build the same circuitry on the breadboard by using 16MHz crystal and other components (that we can use to make arduino uno on breadboard)?

    Reply
  46. f I remove Arduino’s Atmega328 IC and build the same circuitry on the breadboard by using 16MHz crystal and other components (that we can use to make arduino uno on breadboard)the would program or sketch uploaded on it work?

    Reply
    • yeah It will work just fine Pritesh.
      You can find plenty of information if you search on the web for something like, Arduino on a breadboard.

      Reply
  47. Boas Rui , é o seguinte eu fiz a ligação certa como metes-te ai mas quando ligo o arduino ao computador para alimentar o arduino começa a fazer um barulho sabes como resolve-lo ?

    Reply
  48. Hey Rui !!!
    This is my error : “Runtime Error : need BLUETOOTH_ADMIN permission”.
    I think it may be in your BlueArd.
    Can you help me ???
    What is problems??
    Tks .

    Reply
    • Hi Taichi,
      that’s a problem with your bluetooth setting. that never happened to me though.
      so make sure you go through all the bluetooth settings and enable all the permissions

      Reply
    • Hi Tamojit.
      Using my app and if you change the arduino code to work similar to that vido you sent me you can control the speed of your DC motor just fine 🙂

      Reply
  49. Hi Rui,

    I’m trying to add a couple more buttons to the app that you built for the motor control. I’m controlling three different motors (each with different drivers) and I need two more buttons to control forward and backward movement. I’ve got two motors working like a charm, no problem. The issue that I’m running into is that I don’t know what “number” to assign for the bluetoothclient byte to send to the android. I figured it would just continue on from the previous ones, 54…55…56, but that didn’t work.

    Can you help me?

    Reply
    • Hi Zsolt,
      If you read this tutorial: learn.adafruit.com/adafruit-motor-shield
      You can combine my project with that tutorial and control your the DC motor with the shield.

      I hope this helps,
      Rui

      Reply
  50. Do you mind if I quote a couple of your articles as long as I
    provide credit and sources back to your weblog?
    My website is in the very same niche as yours and my visitors would certainly benefit from
    a lot of the information you present here. Please let me know if this alright with you.

    Many thanks!

    Reply
  51. Hi, Rui Santos
    this is my first write to you, I am working on “LED On-Off application” this is very simple application.I am using HC-05 bluetooth module, arduino UNO and Android development tools like Eclipse.
    I have tried lots of android application but does not work for me.
    can you please help me in developing a simple LED on-off two button application in android.
    I have tried below application
    http://digitalhacksblog.blogspot.in/2012/05/arduino-to-android-turning-led-on-and.html
    but it get crashed on pressing “On button”
    thanks.

    Reply
    • Hi Lalit,
      Unfortunately I don’t work with android development so I can’t help you much…
      I’ve just created a few simple apps with MIT App Inventor and that’s all…

      Have a nice day,
      Rui

      Reply
  52. Hi,
    Excellent Work!!!!!!!
    But can’t find this BLUEARD App, so can u please help me with the download of BLUEARD app.

    Reply
      • Thank You!!!!!!!!!!!!! For sharing this Page.
        Actually we are doing you’re project as a Mini Project
        in our institute. We really liked this….. Its a great website created by you, helping young engineers.
        We may need your help in future too, so your cooperation will be highly appreciated by my friends and me

        thanks again!!!!!!!!!!!!!!!!!!

        Reply
  53. Ola, estou a tentar fazer este projecto mas infelizmente não funciona.
    Quando carrego num botão na app, o arduino parece receber a informação mas os motores não andam… tenho o HC-07 e o linvor, qual o melhor?
    qual será o problema?

    Reply
    • Olá Cintia,
      Qualquer modulo de bluetooth que funcione por comunicaçao serial deve funcionar bem com o meu projeto.
      Um dos problemas comuns poder ser que o seu modulo de bluetooth venha mal configurado/ou com outra configuraçao por defeito.

      Para este projeto funcionar com o arduino tem que configurar a baud rate do modulo de bluetooth para 9600

      Reply
  54. hi rui santos
    firstly i would like to thank u for sharing your experiences and project idea’s in web
    and i have done this project and it is working perfectly fine, and now i’m willing to add few more buttons to that app so that i can perform few more tasks, can u please send that .aia file of 2 dc motor control to me so that i can improve this project little.

    once again thank u

    Reply
  55. Hi Rui, if is to add in 2 limit switch between the motor to let it toggle forward and reverse, is it possible?

    Reply
  56. hi Rui..i already try your project.i got this problem..the motor wont rotate when i press 2.. but it functioning well when im press 1 or 0..can you help me.

    Reply
  57. hi.. i have problem with the motor. the motor cannot function well. only one motor can rotate at one time. i use bluetooth spp and bluebee. is it effect the circuit??

    Reply
    • This project works with the Leonardo.
      But the serial communication with the Leonardo is a bit different. So You need to change my arduino code to receive the data properly via serial

      Reply
  58. Hi! Thanks for these awesome tutorials!! When I try to connect my phone to Bluetooth it cannot find any nearby Bluetooth devices to connect to. Do you know what the problem is?

    Reply
        • It might be, I’m not sure though.
          It should work just fine… Read the feedback from the seller from where you bought the item.,,
          Otherwise if you follow my exact steps it should work just fine.
          Please read carefully my tips on this blog post

          Reply
  59. Ok this time I redid the circuit using your,single DC motor tutorial. I connect via blueterm and it actually worked! But then I got more problems. It would disconnect and I would have to reconnect. Then it would say it was connected but when I tried to send a command it would disconnect again. Now it won’t connect at all.
    The company is sending me a new one since they actually sent me the wrong one that had six pins instead of four. It should still work though, even with six. So for now I’ll just assume it’s defective and wait for my new one. I hope it at least works.
    Thanks for the great tutorials!

    Reply
  60. Hey how would I send a command that only makes the DC motor turn on for 10 seconds then turn off? I’ve tried several methods but none seem to work. Thanks!

    Reply
  61. thanks for the tutorial but can you please tell me what changes do i need to make so it would go forword as long as i press the botton on my mobile?

    Reply
    • Hi Alex,
      I don’t think that works with MIT App Inventor.
      I know MIT app inventor has a long button click feature… but I’m not sure if it would work as I’ve never tested myself

      Reply
    • Hi Liviu,
      I think that shield has a few project examples or it probably comes with a custom library,
      Compare their project examples with my code.
      You might need to add their library and just change a couple of lines from my code where I control the DC motor.
      But my bluetooth app will work just fine with your shield

      Reply
  62. I just like the valuable info you provide for
    your articles. I’ll bookmark your blog and test again right here frequently.
    I am rather certain I’ll be informed many new stuff right here!

    Best of luck for the next!

    Reply
  63. sir can you help me with my project . . .i want to add a water sprinkler to your project . . . when i click “GO!” the sprinkler will turn on . . and stop after a few seconds . . .

    Reply
  64. When I connected the Arduino TX cable to bluetooth TX and the Arduino RX to bluetooth RX, on the serial monitor numbers 1,2,3,4,5 work fine. But when I connected the Arduino TX cable to bluetooth RX and the Arduino RX to bluetooth TX, on the serial monitor numbers 1,2,3,4,5 don’t work. Why?

    Reply
    • Hi Zsolt,
      That’s impossible, unless the pins are labeled incorrectly.
      The Arduino transmits information with the pin TX and the bluetoth module receives that information with the RX pin. (And vice-versA)

      Reply
      • Ruis master why his software can not be used when connected to bluetooth hc-05?
        whether the application program of android is wrong ..?

        Reply
        • Sorry Doni, I didn’t understand your question, what do you mean?
          (If you want to upload the code into your arduino, you can have your bluetooth module connected to your arduino, because the Arduino needs to have the RX pins available so it can receive the code you are uploading with your computer)

          Reply
  65. Hi Rui,
    On the serial monitor numbers 1,2,3,4,5 work fine as your description. I can connected the phone to bluetooth, but with the phone I couldn’t control motors.
    What can be the problem?

    Thanks your help!

    Reply
  66. Hi Rui,
    Your application did help me a lot in my project, however, I want to change it a little bit. I want my application to send the ASCI value as long as the button is pressed and when the button is released it would stop sending the value, I want to control my robot with that application but without a stop button, well I am a little new to the android programming and I need your little help to do that. Can you help? Thanks in Advance.

    Reply
  67. i make all the connections well and when i send “1””2″ecc. from the serialmonitor the motors works but when i try to control them from bluetooth don’t happen anything what i’m doing wrong?

    Reply
  68. Hi rui,

    I have one problem to modify your android app.
    I download all those codes which you was given. How to modify when i extract the files it came an APK file, arduino sketch and source code for APK. Where can i use that apk source code to modify your android app with my convenience.

    Reply
  69. Hi Rui,
    I tried this project today and it worked well. Why is it that when I connect the motor pins directly to arduino pins, the motor won’t work but after using a motor driver IC, it works fine. Where does the current required come from even when no other external power supply is used?
    Also, I need the motor to turn off after 5 sec of operation. I tried”delay(5000);” but that has not solved the problem. Any bright ideas.

    Thanks 🙂

    Reply
  70. hello rui,
    as i watched your video controlling the 2 motors …
    wen you gave go (forward) command both the motors started spinning ..
    i want to use this for a rc car which will work on bluetooth…
    so if both motors spin wen i give forward command the car wont go as i want…

    so please help me out of this …!!
    if u can please message me on “[email protected]” it would be nice.

    thank you

    Reply
  71. i m using arduino duemilanove s/n 129013 board and bluetooth module s/n 134504 can u please help me how to make connections between arduino and bluetooth module and how to get mac address

    Reply
  72. hello Rui,
    I ma fan of yours great projects…we all are implementing them in our college projects…..I had experinced a problem in implementing this project it is connecting fine with HC-05 module but when i press forward button the motors are not moving …please tell me the possible reason for the following error..please give a bit of your valuable time for my problem..

    Thanks

    Reply
  73. why i can’t connect to my robot bluetooth? when i click “choose device to connect to” on ur app, then choose my bluetooth name, then suddenly appear “Need bluetooth_Admin permission :neither user 10130 nor current process has android.permission. BLUETOOTH_ADMIN.” why?

    Reply
  74. If i need to control 2 dc motors, and I have the motor shield, I just upload the code to the Arduino and it works?

    Reply
  75. sir i have created your project with all the right connections but when i turn on the project one motor rotates and when i connect it to the phone it keeps on rotating and when i press left it stops rotating but the other one doesnt and when i press stop it rotates i have rechecked all the connections. i have even replaced the l293d ic and also reprogrammed but the problem continues. please help me out

    Reply
  76. Problem : I have connected circuit as given in your diagram but the motors do not corresponds when i try to check by entering 1,2,3 …..
    in the serial monitor . What’s the problem can you explain it ?
    Help me as i am new

    Reply
      • Thx , a lot Bro .I could control the two DC motors with smartphone because of you .Thx once again .

        PROBLEM : But , When i tested it at that time I Supplied Power through the ‘Cable connected to Computer’. BUT I Want to Power through “9V Battery” . So where should I Plug the ‘Battery’ .Please Help me as early as Possible !!!!!!!!

        Reply
          • I am using HC-05 Module and Arduino Uno , so how much power should I supply and where should I plug the Battery.I am supplying 3.3 V to HC module through arduino.
            Please give me solution to this problem
            Where should I plug the Battery ????

  77. hi i,
    like ur project and am about to do it i hope.
    but i have one question before i start wich program i use to edite the sorce file for the app
    and in wich programing language its written.

    regards,

    Reply
  78. Hi Rui, I really like your stuff and I just published a bluetooth app specifically for controlling Arduino robots. Let me know what you think and if it’s helpful.
    Heres the link – play.google.com/store/apps/details?id=appinventor.ai_mark.Jarvis

    Reply
  79. Hello,
    Very nice projet, but I was wondering if there any possible way to make one motor go Ahead and the other one Reverse so that we can have a perfect turn,
    thanks 🙂

    Reply
  80. Rui, baixei seu programa para ver como ele é feito pra aprender um pouco, mas o app inventor classic não está mais funcionando… tem outra forma que eu possa ver seu aplicativo? Queria entender os códigos pra aprender… Obrigado e parabéns pela iniciativa!

    Reply
    • You can use this tool to convert App Invento Classic to App Inventor 2: convert.appinventor.mit.edu

      Olá matheus,
      Pode utilizar esta ferramenta para converter: convert.appinventor.mit.edu

      Reply
    • I don’t that file, please read the top description of this blog post.
      This was done for an older version of the MIT app inventor…
      You can also search for Convert classic MIT app inventor to aia file
      Thanks,
      Rui

      Reply
  81. bro my connections are working i checked in the serial monitor but the motors are not working can u help me in this…. thank u

    Reply
  82. Hey Sir,

    Thank you for detailed explanations and for all you effort. I also appreciate that you answer all the comments…

    Since I am using your .apk for communication between smartphone and my hc06 I am getting this errror on my phone:

    Need BLUETOOTH_ADMIN permission: neither user 10083 nor current process has android.permission BLUETOOTH_ADMIN

    then it ends the applicaiton.

    Can you help me what might be the issue??

    Your sincerely,
    Alihan

    Reply
  83. Hi Rui,

    I’d like to modify the app you made for this, but it can no longer be imported into the newer MIT app inventor. I even tried the converter they have, but that did not work. Do you have an updated version of the app source code?

    Kind regards,
    James

    Reply
  84. hi
    I am using motor controller l293d but I have that board motor controller so what is t the wiring for that you can tell me please.

    Reply
  85. sir….,
    is it possible to run 4 motors, two motors for vehicle moving and another two motors are run for some special purpose. if it is possible give me some explanation it is helpful to my project.
    thank you sir

    Reply
  86. Thanks, Rui, this is exactly what I needed to get started. Although I will be using a downloaded app (there are plenty, each sending different set commands), your code is pretty universal and basically helps me put things together and expand it in the future, perhaps by adding the obstacle avoiding feature (in an if/else statement, I suppose statement), etc.

    Guess my first making will be motorized strandbeast (check it out on youtube, guys, it is pretty awesome) and a three-wheeler … which shall be a great encouragement for forther endeavours

    Reply
  87. Can I replace the L293D IC with an L298N motor driver to control my two DC motors? Do I have to change the code at all if I do?

    Reply
    • Hi.
      That module should work just fine with the code provided.
      You just need to make sure you wire the DC motor to the motor driver properly.
      Regards,
      Sara 🙂

      Reply
  88. Olá Rui.

    Primeiro que tudo, obrigado pelo teu esforço em disponibilizares este conteúdo de graça. Muito obrigado.

    Estou a experimentar o teu projeto e, sem mexer em nada no programa, o meu motor assinalado com “motor2” no pin 1 não funciona. Simplesmente parece que não recebe a ordem. Estou a tentar com o Serial Monitor e ainda não passei para o módulo Bluetooth.
    O que é que poderá ser?

    Mais uma vez obrigado pelo teu site,
    Pedro

    Reply
    • Se não consegue controlar o motor a partir do Arduino IDE Serial monitor significa que algo está errado no seu circuito ou que o chip de controlar os motores não está bem ligado. Recomendo verificar uma segunda vez todas as conexões

      Reply
  89. Please help me. How can i make to motor motor to rotate slowly.Please help.Very important for my project. The setup is all set but i want the motor to run slowly.

    Reply
    • Hi Bhanu.
      Instead of using the digital digitalWrite() function and using HIGH and LOW, use the analogWrite function, for example:
      analogWrite(motorPin, motorValue);
      In which motor value is a value between 0 and 255 (255 is maximum speed). This way you can control the speed.
      Regards,
      Sara

      Reply
    • Hi.
      This code was built for the companion MIT App Inventor.
      It won’t work with a different application, unless it sends the exact same commands to the Arduino.
      Regards,
      Sara 🙂

      Reply
  90. Hi,
    thanks for your feedback.
    That question requires almost an entire tutorial.
    What I can tell you right now is that it works like it does with the Arduino… The bluetooth module will establish a communication via the TX and RX pins.
    and your smartphone will establish a communication with the bluetooth module.

    It will also depend in which PIC you’ll be using. you need to read the datasheet…

    Reply
  91. Hi

    I tried this project.I powered Arduino with power bank and Dc motors with 4AA batteries.I used L298N motor driver module.But dc motors not running.I check dc motors with direct current and its working.Bluetooth Module and Motor Driver is also working.Can you help me with this?

    Reply
  92. Hi! i am interested in your project! May I know which schematic diagram you are using? I am currently using tinkercad, however, there are limited components in there.

    Reply
  93. Having trouble with this at the moment. Anyone trying in project in 2023/2024?
    I have a Bluetooth connection but the motors aren’t running when I press on a command and I’m getting the message “Broken Pipe.”
    Any tips for this issue?
    I’m pretty sure I wired everything right, unless there’s some certain things you gotta do when uploading the code on IDE.

    Reply
  94. I have followed this tutorial: https://randomnerdtutorials.com/arduino-control-2-dc-motors-via-bluetooth/ and made no changes at all to the instructions. However, when I use the app, everytime I press forward, it will keep going forward forever and will not STOP even when I press STOP and then after this a broken pipe error will occur? Is there a way to remedy this or how can I alter the code so that the forward button only drives motors forward for a couple of seconds?
    Help would be much appreciated.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.