Random Nerd Tutorials
Shares

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

Shares

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.

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

Parts Required

parts

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!

Thanks for reading,

Rui

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

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off