Arduino – Control DC Motor via Bluetooth

Hi guys,

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

  • 1x Arduino (Click to see on Amazon)
  • 1x Bluetooth Module (for example: HC-05 or 06 – Click to see on Amazon)
  • 1x Smartphone (any Android will work)
  • BlueTerm application
  • 1x L293D IC
  • 1x DC motor
  • 1x Breadboard
  • Jumper Cables

IMG_0244Schematics

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

schematics

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.

Note:
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!

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.

Comments

    • says

      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

      • huss says

        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.

  1. says

    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

  2. huss says

    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.

  3. says

    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.
    http://www.dougwoods.co.uk/curation/idevices-controlling-robots-in-the-classroom/
    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 ….

    • huss says

      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

  4. huss says

    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?

    • says

      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.

      • says

        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.

        • says

          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
          http://www.doctormonk.com/2012/10/arduino-leonardo-vs-arduino-uno.html
          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..

  5. Vladimir says

    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 !
    Vlad

    • says

      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!
      :)

      • Vladimir says

        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 !

        • says

          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…

  6. Cinder says

    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.

      • Cinder says

        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.

        Thanks

  7. says

    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’?

    • says

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

  8. ganesh shetty says

    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

  9. John says

    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.

    • ruisantos16 says

      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…

        • Rui Santos says

          Hi thanks for commenting.
          you can download all my code for free just click the (facebook/tweet/google+) one of thoses buttons and the code will unlock

    • ruisantos16 says

      I’m sorry but I didn’t used any AT commands, my Bluetooth module was running by default!

    • Rui Santos says

      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!

  10. says

    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?

    Thanks

  11. says

    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?

    • Rui Santos says

      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

  12. Max Rosenblum says

    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!

    • Rui says

      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!

  13. says

    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.

    • Rui Santos says

      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

  14. Andi says

    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?

    • Rui Santos says

      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

    • Rui Santos says

      Right now. I’m not planning in create any project related to robotics.
      I’m working towards home automation projects!

  15. George says

    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.

    • Rui Santos says

      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,
      Rui

  16. sank says

    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

    • Rui Santos says

      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,
      Rui

  17. UMANG says

    HI,
    WHAT IS THE OPERATING VOLTAGE IF HC-05 BECAUSE IN SOME WEBSITES IT SAW THAT THE OPERATING VOLTAGE IS 3.3V.AT THE BACK OF MY BLUETOOTH MODULE JYU-MCU IS NOT PRINTED

    • Rui Santos says

      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,
      Rui

      • sabri says

        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?

        • Rui Santos says

          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.

  18. sank says

    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…

    • Rui Santos says

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

  19. Deepak says

    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.

    • Rui Santos says

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

  20. Xuyi Wu says

    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?

    • Rui Santos says

      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

  21. zul says

    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

    • Rui Santos says

      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…

  22. Tamojit says

    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! :-)

  23. rahul reddy says

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

  24. Kallum says

    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

    Thanks.

    • Rui Santos says

      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

    • says

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

  25. Ziad Kassam says

    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.

  26. RolandoLewis says

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

    • says

      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

  27. Sam says

    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!

    • says

      Hi Sam,
      simply make a delay of 5 seconds – for example delay(5000); – inside the if statements. and then turn off the DC motor
      I hope this helps

  28. kundalini says

    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.

  29. Eden says

    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 ?

    • says

      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,
      Rui

      • Photphotte says

        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.

      • Vorgs says

        Hey rui, can you help me pls, i follow your schematics but my bluetooth module didn’t blink or can’t connect to my android.

        • says

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

  30. Vorgs says

    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 :(.

  31. Vorgs says

    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.

Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>