Arduino – Control DC Motor via Bluetooth

In this project we will control a DC motor with a smartphone via bluetooth.

This project is great to learn more about:

  • DC motors
  • Interfacing Arduino with your smartphone
  • Bluetooth
  • L293D IC

If you don’t have the L293 IC you can make the same circuit using the H bridge, anyway I really recommend you to read more about that and the IC datasheet. There’s plenty of tutorials about that. Also If you don’t have a bluetooth module yet you can see my review about this bluetooth module and where to buy one. So Let’s start…

Parts required


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


I can only TX and RX cables after you upload the Arduino code.


Two common mistakes

  • You need to remove the RX and TX cables when you’re uploading the sketch to your Arduino.
  • Sometimes people connect the TX from the bluetooth module to the TX of the Arduino… that’s wrong and it won’t work. Make sure you connect it properly, the TX into RX and the RX into the TX.

If the HC-05 Bluetooth Module asks for a password, It’s ‘1234’.

Upload this code below

Make sure you remove the wires from RX and TX otherwise the code won’t upload properly!

 * Control DC motor with Smartphone via bluetooth
 * created by Rui Santos,

int motorPin1 = 3; // pin 2 on L293D IC
int motorPin2 = 4; // pin 7 on L293D IC
int enablePin = 5; // pin 1 on L293D IC
int state;
int flag=0;        //makes sure that the serial only prints once the state
void setup() {
    // sets the pins as outputs:
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(enablePin, OUTPUT);
    // sets enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
    // initialize serial communication at 9600 bits per second:
void loop() {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){     
      state =;   
    // if the state is '0' the DC motor will turn off
    if (state == '0') {
        digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
        digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
        if(flag == 0){
          Serial.println("Motor: off");
    // if the state is '1' the motor will turn right
    else if (state == '1') {
        digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
        digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
        if(flag == 0){
          Serial.println("Motor: right");
    // if the state is '2' the motor will turn left
    else if (state == '2') {
        digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
        digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
        if(flag == 0){
          Serial.println("Motor: left");

View raw code

For the android communication with our bluetooth module I’ve used the BlueTerm app, It’s completely free, so you just need to go to “Play store” and download it. Then you just need to connect your smarthphone with the bluetooth module. Remember to remove the TX and RX cables. (you can see in youtube video below how that’s done).

I’ve only set 3 commands to control the DC motor:

  • ‘0’ – Turns off the DC motor
  • ‘1’ – DC motor rotates to right
  • ‘2’ – DC motor rotates to left

Watch the video demonstration

Thanks for reading, you can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.

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!

160 thoughts on “Arduino – Control DC Motor via Bluetooth”

  1. Good stuff. Great Tutorial.
    How can I make my robot, be controlled through bluetooth?
    Here’s my robot,
    I want just 5 commands right, left , forward, back and stop

    • Yes you can do that by using two L293D ICs…you just need to change the code a bit… And it will work just fine 🙂 i will make a full tutorial about that soon… Im just waiting for a few parts that will arrive in one or two weeks… So make sure you subscribed to receive the updates about my robot. By the way nice robot you have! I’ve subscribed to you

      • Just Subscribed!
        Yes, I’m using 2 SNY motor drivers equivalent to the l293D… The only thing I’m having trouble is choosing an affordable bluetooth Module, and writing the android App(never did before) but I guess I will download yours when you do the new one?

        Also, I’m trying to find a way to make my ping sensor ping wirelessly so I wont need wires like my video shows.

      • Hi sir, I am doing a project in which i want to turn on and off a 9v waterpump using mit app inventor. I am able to turn on the pump but i cant off it.Can u tell some fix’s for it

          • mit app inventor and I solved that problem and can u tell how to add an external power source for the motor i have a 9 volt one
            Thank you

          • Hi.
            You can connect the external power source (+) to pin 8 of the L293D IC.
            Connect the external power source (-) to one of the GND pins, for example pin 4.
            Search for the LD293D IC pinout before making any connections.

  2. This is probably the most affordable bluetooth module out there Hc-05 the one Im using. you can buy one for 8$ on ebay. You can use my code but you need to add a new motor to the code and define the forward and reverse button . I will post the robot in 1/2weeks Im waiting for one IC and some others parts i need. You just need to change my code a bit. For the android you will need the blueterm app or any app similar to do that , so you can connect your arduino to the bluetooth module.. I can write the code for you… Its pretty quick

  3. I just purchased the Hc-05 on ebay, takes 10 days delivery. I have all the code written for both of my motors already, all I need to do is some simple tweeks, I can do that pretty simply.

    But I never used the Blueterm app before(I have an iphone, but can get an android), I was wondering instead of sending “0” “1” “2”, there would be actual buttons (Arrows) for the directions.

  4. Nice 🙂 btw usually the HC-05 requires a pass and its ‘1234’.
    you can use an iphone you just need to find a similar app…
    If you’re familiar with the Arduino IDE, what the blueterm app actually does it connects your smartphone to your arduino via Bluetooth, and it does a serial communication between the devices. So you don’t need to type anything in the serial monitor with your computer, but instead you type on your smartphone
    there are some apps with the 4 buttons that do the exact same job but I’ve never used any… but usually someone made that app just for one particular robot, the easy way is to use an app as blueterm.
    there are some examples in that website, lot’s of those apps work with an accelerometer which I thinks its really good
    My idea for my robot is to control a robot with 2 DC motors through bluetooth with my ipad (with the 4 buttons)
    But as I said before it will require some time as I don’t have the parts yet and I need to learn more about the control with the 4 buttons ….

    • Me too i have an Ipad, I will also look into it. That even sounds like a better idea, thanks for all your help, I will be checking back constantly for updates!

      and when I get my bluetooth, and get it working with my robot, ill check back for help, if i need any, and I will let u know how it goes!

      Thank you

  5. Just last question.

    from the android bluetooth perspective.
    how do you:
    Set 3 commands to control the DC motor:
    ’0′ – Turns off the DC motor
    ’1′ – DC motor rotates to right
    ’2′ – DC motor rotates to left

    Do you do it on the android phone in the app or how?

    • The commands are set in the arduino code… In the arduino code its where you define the keys that will trigger the movement you want. If you read my code. In the if statements its where i define which keys i want to be pressed and read. You can define whatever key you want (numbers… Letters) the android app just sends the key.

      • Hi, I’m Thomson

        i have a project to make a robot. maybe like huss project.
        but i use arduino leonardo. i use dual motor controller. but i wanna it run on my iPad. i don’t know how to make it work on my ipad. i need your help. and how to make ipad app to control the robot.
        may you give me best solution.
        which the best one, Arduino leonardo or arduino uno?
        thanks for your article it’s very useful for me
        send me by email.

        • Hi Thomson!
          You can use the Arduino uno or the Arduino Leonardo they both are capable to do that project, you can read this post for more information and see the advantages between the 2 boards

          But in conclusion for that project it doesn’t make much difference they’ll both work just fine 🙂

          I didn’t made the app I’m running on my smartphone… And I don’t know much about iOS programming, I was thinking in making one but actually I’ll only be able to do that If I’ve buy a Mac or something otherwise would be really hard to create one app. with just my ipad… or with my linux computer with a virtual machine…
          I didn’t found any similar app for my iphone/ipad that’s why I used my android…
          Actually I don’t know any free app that does the same as Blueterm..

  6. Hi Rui !
    Great project. I am new to the Arduino community and I am getting started on a personnal porject in whitch I would like to control a :
    – a small speaker that display a sound
    – a small fan
    via bluetooth.
    I would like that device to be as small as possible and powerd by a battery.
    Witch hardware Arduino would you advise me ta base it on ?
    Thanks so much for your answers !

    • Hi Vladimir! Thanks for your support, I’m really glad you enjoyed it!
      You can buy any Arduino to control the fan and the speaker, I would recommend you to buy the Arduino Uno or the Arduino Duemilanove. You can buy an original or a clone, It’s easy to find on ebay.
      I don’t know what you want to do when you said control a small speaker, I don’t know what’s your project about.
      But with the Bluetooth module, a smartphone and an Arduino You can control the fan and the speaker for sure!
      And the Arduino Can run with a 9V battery !
      If you have more questions just let me know or just talk about your project!

      • Thanks for those elements. It helps a lot.
        The idea it to have the sound go thru the running fan to study how disformed it souds like while the beat frequence is modified and the fan speed is as well. (listen to music thru a fan, you’ll understand what I am talking about).
        On the hardware configuration, I have been looking further, and there is still a challenge :
        1. The bluetooth needs to be able to transfer data and music which will be stored on the smartphone that commands it
        2. I need to make sure that the arduino is “smart” enough to understand a music signal AND data signals that controls teh fan speed. And it has to transfer the music part to the autoamplified speaker.
        So, still not sure what hardware configuation to use (especially, which bluetooth receiver between the large choice), but if you have any ideas, tey are more than welcomed 😉 !!!
        Thanks !

        • To be honest I don’t know exactly how you can do that, but If I understood the real goal of your project, I must tell you that probably the Arduino It’s not the best platform to do that.
          You can’t send music like a mp3 file or something to your Arduino trough bluetooth, I don’t know if there’s any shield that allows that… but with the Arduino itself you can’t.
          The most similar project I can think about It’s to create the song you want to analyse in the Arduino IDE using the Tone function and control the PC fan with that sound (Basically the voltage could be connected to a buzzer/speaker and you could hear the tones of the music, or simply connected to a Fan controlled by the voltage )

          I don’t think I’ve helped you much, I’m sorry…

  7. I got to the last step but when I enter the values (0,1,2) nothing happens. All I see is a number on my phone. On the video the commands show up as “Motor:right” for 1. All I get is 1 on my phone.

      • Hey that worked but I cannot control the motor with my phone. When I use the serial monitor I am able to control the motor and the inputs (the number 0,1,2) appear on the screen of my phone. It seems like the circuit is connected correctly and the bluetooth module is working as well, but when I try to control the motor with my phone nothing happens, I just get a number as I told you before.


  8. thats really weird… if it’s working with your computer should be working with your android, i don’t know what can be done then…
    but it says something like this: ‘connected to linvor’?

    • I don’t know what can be wrong because it seems that everything is correct… and a lot of people actually tried this and worked…
      and if it works with the arduino serial monitor the circuit is correct. it can be a problem with the bluetooth module I guess
      the last thing that it can be a mistake (the TX from the bluetooth module goes into the RX from your arduino and the RX from the bluetooth goes into the TX from the arduino).

  9. Hi rui ganesh here i m doin mtechmrj named model based design of parellel park asssist system using simulink but now i m planned do hardware implementaion i want to use remote control car i hav to control both speed and steeering of motor i hav finished with simulink if you dont mind suggest me which arduino board i hav to use for my project since i heard that board support simulink please do suggest or email me please

  10. Hi Rui,

    Im having trouble uploading the code to Arduino, when i verify it, i get an error message saying: expected constructor, destructor or type conversion before ‘void’. and its highlighting the ‘int state;’ line of coding which is the problem. Many thanks for you help.

    • did you copy exactly all the code(all the “{ }”)? which Operative system you’re working on? you’re arduino IDE is updated? which arduino board you’re uploading too?
      I’m just asking that because it’s really weird because a lot of people already tried this project and it worked…

    • Thanks, I’m glad you found them useful! make sure you subscribe to any of my news sources like youtube or websites newsletter so you can be notified when I release new projects!

  11. Hi..Mr.Rui,
    just I want to know about how can I get the bluetooth application that you use it in the video for controlling on the Android mobile?


  12. Hi!
    Hey man i’ve got a problem with the bt module….the thing is if i write on the monitor serial, the led turns on (i modified your original code for just a led…you know, i’m trying to keep it simple just to test it) but the thing is, when i try to use my android phone (running the blueterm app and after connecting to the module (it says: conected: linvor) the led just won’t work :/ any ideas?

    • Firstable sorry for the late delay replyng to your comment, I’ve missed it, just found it today.
      Please check the wire from your bluetooth module, the most common mistake is this:
      bluetooth module: TX pin -> RX pin from the arduino
      bluetooth module: RX pin -> TX pin from the arduino

      Then I also recommend to open your Arduino IDE and your serial monitor and send the commands for example “0” and “1”. Whataver you defined and see if the circuit is working. If it working then try via bluetooth

      Good Luck!
      Rui Santos

  13. I’ve seen other versions where people use resistors to drop the voltage coming from the arduino. This isn’t necessary? I don’t want to ruin my HC-05. Thanks!

    • If you’re using a power supply you can use one resistor.
      but if you’re using the USB to power your arduino, don’t worry .
      the HC-05 can handles 3.6V to 6V

      Thanks for commenting!

  14. Hi Rui Santos, thank you for your sharing how to do arduino project here firstly. I had tried to use of your arduino uno codes in virtual simulation of Proteus for controlling 2 DC motor using L293D and Atmega328p. However, the simulation program prompted me error message and I don’t understand why the error occurred since I had sorted out all possible problems before. Could I send you the proteus simulation file for your reference and then can you point out how I can slove the simulation problem please? I would like to complete the simulation firstly before launching the hardware circuit development processes. Many thanks.

    • Hi Peter.
      Thanks for trying my projects!
      I’ve never used Proteus… my circuit is working with the Arduino IDE.
      I’m sorry I don’t have the time to do that.

      This next weeks I’ll be on exams and finishing some projects.
      Good luck with that,
      and I’m sorry not being much helpful.
      Rui Santos

  15. 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?

    • 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

  16. Greetings from Greece!
    I make arduino projects as a hobby for my own. I found interesting the BT communication. Is there any recommended tutorial about makind android apps with BT, developing using Eclipse?

    Thank you.

    • Hi George.
      I don’t know any tutorial for that at the moment.
      I also never made any Android apps using Eclipse.

      Sorry, maybe on youtube you can find what you’re looking for.
      Thanks for stopping by,

  17. Hii rui…
    first upon I m a diploma student …so I don’t have too much knowledge about electronics so I wanted to ask u that is the project compatible with atmega 328 chip…and which Bluetooth. Module should I use

    • Hi Sank,
      yes this project is compatible with the atmega328 chip.
      That’s the one I’m using in my Arduino UNO board.
      The bluetooth module is describer in the part list. you can use the HC-05 or HC-06 bluetooth modules

      Thanks for asking,

  18. HI,

    • the operating voltage is from 3.3V to 6V but make sure you read the datasheet of your bluetooth module.
      Thanks for asking and please don’t use caps lock next time.
      Have a nice day,

      • hi Rui Santos,
        i’m new to Arduino..
        just want to ask you..
        1) if I’m using HC-06 bluetooth, do i need to change any code from the arduino?
        2) what is the voltage required to make the dc motor works?

        • 1) It will work with any bluetooth module that works with serial communication, so the HC-06 works just fine
          2) It depends on your DC motors those DC motor work great with 3.3V or 5V.

  19. Hi rui…could you provide the presentation report or project report on this project …which can include project’s application,construction ,working,cost…etc…
    you may also provide a ppt also…
    please do my work it is very essential…we have to submit a project report just in 7 dayd…
    please rui…
    please rui…
    please rui…

    • Sorry sank,
      I can’t make the project for you…
      I’m already working on my own stuff.
      Good luck with your project,

  20. Why I am new to Arduino. Why we need to remove TX and RX of BT module while Uploading code. What will happen if we don’t do tat.

    • Hi Deepak,
      you need to remove the TX and RX because when you’re uploading a new code the arduino needs to receive the data from your computer.
      and if you have something connected to those pins the arduino can receive the information from your computer.
      I hope this helps.

  21. Hi Rui,
    I am new to Arduino world and I am doing a project very similar with this one. But it says ‘programmer is not responding’ when I tried to upload the code. Do you know how to fix this?

    • Hi Xuyi,
      Do you have the bluetooth device connected to the arduino during the uploading process?
      You need to disconnect the bluetooth (TX and RX cables) while you’re uploading

  22. hi Rui Santos.. im now doing for a project.we want to control the speed of the motor by using bluetooth apps.any suggestion from you?type of motor we need to use? Dc motor or fan from laptop cooler?can you help me to show the coding if you can.thank you

    • Hi Zul,
      you can use the same setup of my project.
      The L293D works fine for controlling the speed.
      Then you can change the arduino code so it increases the speed of the Dc motor…

  23. Hi Rui
    This project was great! I saw a video in youtube about controlling d speed of d motor using android application. I searched a lot for d code or way to do it bt could not find it. Can u hwlp me out in any way of how to do it???
    Plz reply asap.
    Thanks in advance! 🙂

  24. great work rui…im very much impressed by ur projects..guidelines ,videos u provide r really awesome…keep rocking buddy.

  25. Hi Rui,

    Im working on a project and i was wondering what bluetooth module i would use with an 11.1V lipo battery powering my Mega2560 board


    • Hi Kallum,
      how many current does that lipo battery provides?
      That’s usually the problem, not enough current to power up the bluetooth module.
      But that’s easy just choose any bluetooth module that works with serial communication and works at a lower current than your lipo battery

    • Hi Nihit,
      Yes you can control an LED.
      Basically after you establish a serial communication between your bluetooth module and android device, Send some characters that the arduino will receive and with a if statement, simply control an LED with a digitalWrite().

  26. Hello,
    Can you provide me simple source code how to connect android to micro-controller and to send a simple data like a byte.

    Thank you.

  27. Hello Rui Santos,
    Your project is certainly fantastic. But I have question for you, how to control DC motor without any commands, just detect the bluetooth device and automatically the dc motor will turn ON.

    Hope to get your positive feedback ASAP! Thank you in advance:)

    • You need to change the android app.
      In the block where it shows that the android is connected to the bluetooth module simply send a byte that the arduino will receive and turn on the DC motor

  28. Hey Rui! These are some great tutorials. Do you know how I can send a command and have it run the motor for about 5 seconds and then stop? I’ve been trying out ways with no luck. Any help will be appreciated!

  29. Hey! Someone in my Facebook group shared this site with us so I came to take a
    look. I’m definitely loving the information. I’m book-marking and will be tweeting this
    to my followers! Excellent blog and superb style and design.

  30. Hey Rui, can i know what if i wanted to do angle controlling dc motor? Like i press a button then the motor will rotate to a certain angle and stops. Btw can i where you do your simulations ?

    • Hi Eden,
      I don’t like to use any software to simulate. And I don’t think there’s a good solution out there yet.
      The Arduino can control the angle of the dc motor, but you’ll need a shaft encoder that will allow the Arduino to know what position the motor shaft is in. If you use an encoder it will indicate the current position that gives pulses to let the Arduino know that the shaft has turned one step and in which direction.
      I hope this helps,

      • Thanks Rui. One more question. Will this code work for Atmega328 alone by changing the pin numbers. I mean by programming the ATmega328 with Arduino Uno.

        • Hi Vorg,
          Sorry for taking so long to answer. I have been working for long hours for the past weeks…
          Have you re-checked all the troubleshooting tips?

          Are you connecting the wires properly?
          Upload again the arduino code and before you attach the bluetooth module,
          open the arduino IDE serial monitor and send the commands (0, 1, etc)
          to see if the motor is moving properly..

  31. Hi sir Rui Santos, I was trying to make one like yours and we copy the flow on your schematic but me and my girl tried to tested it and upload the codes to arduino without connecting the TX and RX, but the bluetooth didn’t detect or connected, we try it several’s and reset the device but it did not work :(.

  32. Hi sir Rui Santos, I was trying to make one like yours and we copy the flow on your schematic but me and my girl tried to tested it and upload the codes to arduino without connecting the TX and RX, but the bluetooth didn’t detect or connected, we try it several’s and reset the device but it did not work :(.

    bye the way im using arduino uno rev3, Bluetooth Module HC-06 (Slave) and L293D IC.

  33. Hi,
    Very nice project. I’m new to Arduino.
    I’d like to use Bluetooth with a serial as you used, Plus a serial for debugging to the built-in monitor. Can you show me how to add such a serial for monitoring ?
    thanks in advance

    • Hi Shlomo,
      If you’re using an Arduino UNO you can’t establish two serial communications at once.
      With an Arduino Mega2560 for example you’ll have four hardware UARTs,
      I hope this helps,

      • Hello Rui Santos,
        I have built the similar project and I was wondering to add the feature of controlling the speed of the dc motor as well rather than just the direction or the 1/0 input.
        How can we control the speed of the motor with serial input so that we have a good range of rpm. And, I tried it with the potentiometer by varying input voltage to the dc motor, it works fine. But then I want to control it via my bluetooth app with a slider function. Suggest something.

        Thanks! 🙂

        • Hi Akhil,
          You can do that easily. Instead of sending a 0 or a 1.
          You make a slider in MIT app builder that sends a value from 0 to 255 the arduino receives that value via bluetooth (serial) and it controls your motor with PWM.
          I hope this helps,

          • okay, thanks! But I’m also using a couple of 230V AC bulbs via two 6v relays and the relays are already drawing enough current out of my arduino. Can the motor and the bulbs be in running mode at the same given the current condition…?


  34. what extra coding lines i have to include in this source code if i want to control the motor’s speed in addition to direction using android app?

  35. Hi, i want to know what is your arduino board connecting to? And why can’t i find the signal of my arduino board by blueterm?

  36. Hey Rui I just recently made this but I’m having trouble connecting my phone to the HC-05. I did not have the RX and TX cables in whenever I uploaded the code but when I scan for the module on my phone I can’t find it what should I do?

    • You can download the Android app in this blog post.
      Download the .zip folder and extract it. IT contains a .apk file (that’s the Android app) simply copy that file to your Android phone and install it.
      I hope this helps!

  37. I have project almost same as the above one, additionally I’ll be using 9V battery to power. I wanted to ask how should make the right connections and is it possible that I work this out with RemoteXY so that I can have dedicated interface and buttons to make it more user friendly in place of Blueterm. Please guide.
    Thank you.

  38. Hi there, whenever I do the motor off command through the bluetooth it prints properly, but when I input 1 or 2, it only prints M or Mot, and nothing happens to the motor itself, what should I do?


Leave a Reply to Najam Cancel reply

Download Our Free eBooks and Resources

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