Menu Close

Motor Controlling with HC-05

This tutorial of Robo India explains how to control DC motor using Bluetooth module HC-05 with Arduino.

1. Introduction 

The Motor Driver is a module for motors that allows you to control the working speed and direction of two motors simultaneously .This Motor Driver is designed and developed based on L293D IC.

In this tutorial, we can control rotation of motors with bluetooth app by using HC_05 module.

 2.  Hardware required

S.No.ItemQuantity
1Arduino UNO 1
2Motor Driver 1
3DC Motor 2
4Female to Male Jumper wire 12
59-12v Battery 1
6HC-05 1

3. Connections

Make the following connections-

4. Bluetooth Mobile app

You may download the Nodemcu MOTOR control App on Playstore

or

Users can also scan this QR code on your smartphone to download the app.

5. Programming:

Here is the code to run this circuit.

You may download this code (Arduino Sketch) from here.

// Tutorial on Motor Control By Robo India
// Hardware used HC-05 and Motor Driver connected with motors

#include <SoftwareSerial.h>
SoftwareSerial BlueTooth(5, 6);    // (TXD, RXD) of HC-06
char BT_input;                    // to store input character received via BT.
int motorPin1 = 8;                // pin 2 on L293D IC
int motorPin2 = 9;                // pin 7 on L293D IC
int motorPin3 = 10;               // pin 15 on L293D IC
int motorPin4 = 11;               // pin 10 on L293D IC

void setup()  
{
  BlueTooth.begin(9600);  
  Serial.begin(9600);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() 
{
  if (BlueTooth.available())
  {
   BT_input=BlueTooth.read();
    if (BT_input=='s')
    {
      digitalWrite(motorPin1, LOW);   
      digitalWrite(motorPin2, LOW);   
      digitalWrite(motorPin3, LOW);   
      digitalWrite(motorPin4, LOW);   
      Serial.println("Motors are Off");
    }
    else if (BT_input=='b')
    {
      digitalWrite(motorPin1, LOW);   
      digitalWrite(motorPin2, HIGH);  
      digitalWrite(motorPin3, LOW);   
      digitalWrite(motorPin4, HIGH);  
      Serial.println("Motors are rotating left");
    }
    else if (BT_input=='f')
    {
      digitalWrite(motorPin1, HIGH); 
      digitalWrite(motorPin2, LOW); 
      digitalWrite(motorPin3, HIGH); 
      digitalWrite(motorPin4, LOW); 
      Serial.println("Motors are rotating right");
    }
   else if (BT_input=='r')
    {
      digitalWrite(motorPin1, HIGH); 
      digitalWrite(motorPin2, LOW); 
      digitalWrite(motorPin3, LOW); 
      digitalWrite(motorPin4, HIGH); 
      Serial.println("First Motor is rotating right & Second is left");
    }
    else if (BT_input=='l')
    {
      digitalWrite(motorPin1, LOW); 
      digitalWrite(motorPin2, HIGH); 
      digitalWrite(motorPin3, HIGH); 
      digitalWrite(motorPin4, LOW); 
      Serial.println("First Motor is rotating Left & second is right");
    }
  }
 
}





6. Output

After uploading the code, go to the mobile phone and turn ON bluetooth and pair your phone with HC-05. For doing this go to Settings->Bluetooth->Scan device->select HC-05 and pair it. Pass code to pair is ‘1234’.

Than open the app in your mobile phone, click on scan button to connect with HC-05.

So now, If you press forward button both motor start rotating right (CW). If you press backward button both motors get start rotating left (ACW). If you press the left button first motor move forward direction and the another motor move backward direction and so on.

If you press the accelerate button, then the movement of your phone control the movement of motors and the other button will get disabled.

You can also see the rotation of motors on Serial Monitor as well, while controlling them through app.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply