Header Ads

Android app controlled Robotic Car Project with Arduino and Simple DC motor (with Code)

Bluetooth Controlled DC Motor Arduino Robot Car

Here I am going to show you how to build a simple and easy robot in just 1 hour or less. It's very convenient for university students and electronics hobbyist.
You need an Arduino UNO or Nano for this project because both have the same pin diagram. Hope you can create a complete project following this article.

Robot
The Complete Robot

Components
  • Arduino UNO / Nano,
  • Motor driver L293d
  • HC-05 Bluetooth module,
  • Two DC Motor,
  • Breadboard or PCB,
  • Jumper wire, (male to male and male to female)
  • a 9V battery,
  • Robot Chassis (3 wheels), Front-wheel 360 (ball is better),
  • One 330 uF capacitor, One 100 uF capacitor.
  • Android phone,
  • App Name-  HC-05 Bluetooth Terminal.



Connections of Arduino and Other Modules


First of all, we need to see the Arduino pin diagram carefully.

arduino uno
Arduini UNO or Nano Pinout



Then we need to know the Motor Driver (L293d) pin diagram.

motor driver l293d pinout
L239d Motor Driver Pinout

Then we need to know the Bluetooth Module (HC-05) pin diagram.

Bluetooth Module (HC-05)
Bluetooth Module (HC-05)


Connect Motor Driver to the Arduino board.

connection m driver to arduino
Motor Driver to Arduino connection

We defined Digital Pin 9, 11 and 3, 4 as Motor Pin Output on our Arduino board.
Pin 7 and 10 as enable pin. (see the code for clear concept).

Set up Bluetooth Module to Arduino board.


Bluetooth module connection to Arduino Board
Bluetooth module connection to Arduino Board
  • Connect VCC with 3.3V of Arduino, please do not connect it with 5V as that can burn the module!!
  • Connect GND with any GND of Arduino.
  • Connect Rx pin with Tx of Arduino
  • Connect Tx pin with Rx of Arduino.
Before providing the code, I want to help you concerning the name of the android apps. There are so many apps but most of them don't support smoothly.
I used "Bluetooth Terminal", it's a light-weight app and works very well. Just go to play store and search "hc05 bluetooth terminal".


app
App - Bluetooth Terminal


Source Code


           
#define mp1 11  //motor pin -- mp
#define mp2 9
#define en1 10  // enable pin -- en
#define en2 7
#define mp3 3
#define mp4 4
char val;

//by Sk rezwan-- for any problem, contact- knowledgetube.net

void setup() {
  Serial.begin(9600);  //bluetooth connection block.
  
pinMode(mp1,OUTPUT);   //Sets digital pin 11 as output pin
pinMode(mp2,OUTPUT);   //Sets digital pin 9 as output pin
pinMode(mp3,OUTPUT);
pinMode(mp4,OUTPUT);
pinMode(en1,OUTPUT);   //Sets en pin 10 as output pin
pinMode(en2,OUTPUT);
Serial.println("welcom to my car");  //displays welcome message to the phone screen
}

void loop() {
   if( Serial.available())     // if data is available to read
  {
    val = Serial.read();         // read it and store it in 'val'
  }
  if( val == 'd' )               // backward (down)
  {
    digitalWrite(mp1, HIGH);  
    digitalWrite(mp2,LOW);
    digitalWrite(en1,HIGH);
    digitalWrite(mp3, HIGH);  
    digitalWrite(mp4,LOW);
    digitalWrite(en2,HIGH);
    Serial.println("backward");
    delay(100);
   }
   else if( val == 'u' )            // forward (up)
  {
    digitalWrite(mp1, LOW);  
    digitalWrite(mp2,HIGH);
    digitalWrite(en1,HIGH);
    digitalWrite(mp3, LOW);  
    digitalWrite(mp4,HIGH);
    digitalWrite(en2,HIGH);
    Serial.println("forword");
    delay(100);
   }

   else if( val == 'r' )             // turn right
  {
    digitalWrite(en1,LOW);
    digitalWrite(mp3, LOW);  
    digitalWrite(mp4,HIGH);
    digitalWrite(en2,HIGH);
    Serial.println("right");
    delay(100);

   }
   else if( val == 'l' )             // turn left
  {
    digitalWrite(en1,LOW);
    digitalWrite(mp1, LOW);  
    digitalWrite(mp2,HIGH);
    digitalWrite(en1,HIGH);
    Serial.println("left");
    delay(100);
   }

    else if( val == 'o' )             // Off / stop
  {
    digitalWrite(en1,LOW);
    digitalWrite(en2,LOW);
    digitalWrite(mp1, LOW);  
    digitalWrite(mp2,LOW);
    digitalWrite(mp3, LOW);  
    digitalWrite(mp4,LOW);
    Serial.println("stop");
  }
  else { 
    digitalWrite(en1,LOW);
    digitalWrite(en2,LOW);
    digitalWrite(mp1, LOW);  
    digitalWrite(mp2,LOW);
    digitalWrite(mp3, LOW);  
    digitalWrite(mp4,LOW);
  }
  val='0';                    // robot won't run constantly

}
    

Just copy and paste the code to Arduino IDE, upload and run the Robot.


Thanks. Hope this article will help you to increase your robotics skills.

No comments

Powered by Blogger.