Bluetooth Controlled Robotic car

Published by Diyelex in the blog Diyelex's blog. Views: 22

I have just started with the youtube channel, so I decided to make a Bluetooth controlled robotic car. As am an electronics engineer I have knowledge about electronics. but I don't know how to build a custom android application. so Before making the project I learn about MIT app inventor and try to make one app which was a great success it is quite easy to do. In this article, we will learn how to make a custom Android application and how to configure the Bluetooth module with Arduino.
Hardware requirements:

  • Arduino Uno
  • Bluetooth HC-05
  • l298n motor Driver
  • acrylic sheet
  • wheels x2
  • geared dc motor x2
  • mini breadboard
  • 4.7k, 2.2k resistor
  • jumper wires
  • 12v battery
  • 9v battery
  • switch
Step 1:
Building Chassis
I used an acrylic sheet length of 18cm and width of 13cm. First, I positioned all parts that going to be mounted on the chassis. then I used a hot glue gun to stick the parts to acrylic you can use spacers or screws. after mounting all parts I stick the caster wheel at the bottom of the chassis.

Step 2:
Make the connection according to the circuit diagram. we can use separate power for Arduino. Motor driver and 12v battery connected through the switch. As we can see in the circuit diagram there is 2.2k and 4.7 k resistor connected to the pins of the bluetooth module. the main reason for this is the HC-05 Bluetooth module uses a logic level of 3.3v. While transmitting data from HC-05 to Arduino there is no problem because Arduino is capable of receiving data from 3.3v logic, but while receiving any data from Arduino to HC-05 Arduino uses 5v logic which may damage our Bluetooth module, to convert 5v logic level to 3.3v we use a voltage divider method. Make sure that there is common ground between motor driver and Arduino otherwise motor not work.

Step 3:

Code (Text):
  1. /*
  2.               Author:DIYelex
  3.               date: 3/8/2019
  4. */
  6. #include <SoftwareSerial.h> // TX RX software library for bluetooth
  7. SoftwareSerial mySerial(2, 3);  // Connect the TXD pin of BT module to pin 2 of the Arduino and the RXD pin of BT module to pin 3 of Arduino.
  8. int Rightmotor1 = 4; //pin 1 of Rightmotor
  9. int Rightmotor2 = 5; //pin2 of Rightmotor
  10. int leftmotor1 = 6;//pin1 of leftmotor
  11. int leftmotor2 = 7;//pin2 of leftmotor
  12. int en1=9; //enable pin for Rightmotor
  13. int en2=10; // enable pin for leftmotor
  14. String readString;
  15. void setup()
  16. {
  17.   pinMode(Rightmotor1,OUTPUT);  // attach Right Motor 1st wire to pin 4
  18.   pinMode(Rightmotor2,OUTPUT); // attach Right Motor 1st wire to pin 5
  19.   pinMode(leftmotor1,OUTPUT);// attach Right Motor 1st wire to pin 6
  20.   pinMode(leftmotor2,OUTPUT);// attach Right Motor 1st wire to pin 7
  21.   pinMode(en1,OUTPUT);  //attach motor drivers rightmotor enable pin to PWM pin 9 of arduino
  22.   pinMode(en2,OUTPUT);//attach motor drivers leftmotor enable pin to PWM pin 10 of arduino
  23.   Serial.begin(9600); //Setup usb serial connection to computer
  24.   mySerial.begin(9600);//Setup Bluetooth serial connection to android
  25. }
  27. void loop()
  28. {
  29.   while(mySerial.available()){
  30.     delay(50);
  31.     char data =;//store the data come from bluetooth to char data
  32.     readString+=data;
  33.   }
  35.   if(readString.length() > 0) {
  36.     Serial.println(readString); ///Print the data to serial monitor which is given by bluetooth
  38.     if(readString == "Forward"){ //if forward received do following
  40.       digitalWrite(Rightmotor1, HIGH);  ////////////FORWARD ////////////////////////
  41.       digitalWrite(Rightmotor2, LOW);
  42.       digitalWrite(leftmotor1, HIGH);
  43.        digitalWrite(leftmotor2, LOW);
  44.        analogWrite(en1,200);// for controlling speed of Rightmotor vary the value from 0 to 255
  45.        analogWrite(en2,200);// for controlling speed of leftmotor vary the value from 0 to 255
  47.      }
  49.     if(readString == "Back"){  //if Back received do following
  51.       digitalWrite(Rightmotor1, LOW);  ////////////BACK/////////////////////////////
  52.       digitalWrite(Rightmotor2, HIGH);
  53.       digitalWrite(leftmotor1, LOW);
  54.        digitalWrite(leftmotor2, HIGH);
  55.        analogWrite(en1,200);
  56.        analogWrite(en2,200);
  58.      }
  61.     if(readString == "Left"){  //if left received do following
  62.        digitalWrite(Rightmotor1, HIGH);/////////////LEFT////////////////////////////
  63.       digitalWrite(Rightmotor2, LOW);
  64.       digitalWrite(leftmotor1, LOW);
  65.        digitalWrite(leftmotor2, HIGH);
  66.        analogWrite(en1,80);
  67.        analogWrite(en2,80);
  69.      }
  72.     if(readString == "Right"){   //if Right received do following
  73.       digitalWrite(Rightmotor1, LOW);/////////////RIGHT////////////////////////
  74.       digitalWrite(Rightmotor2, HIGH);
  75.       digitalWrite(leftmotor1, HIGH);
  76.        digitalWrite(leftmotor2, LOW);
  77.        analogWrite(en1,80);
  78.        analogWrite(en2,80);
  80.     }
  82.     if(readString == "Stop"){  //if stop received do following
  83.       digitalWrite(Rightmotor1, LOW); ///////////stop/////////////////
  84.       digitalWrite(Rightmotor2, LOW);
  85.       digitalWrite(leftmotor1, LOW);
  86.        digitalWrite(leftmotor2, LOW);
  88.     }
  90.     readString = "";
  91.   }
  92. }
Step 4:
Android application
Now we have to build Bluetooth applications that would be capable of controlling your robot car. If you wish to download my application you can download it from github: The Bluetooth car

How I created this application was through App Inventor 2, The images above show both the "Designer" & "Block" view of my application so you can build and change thing up if you wish!

Steps for configuring bluetooth

  • First turn on the switch of robot car
  • Go to setting Click on the Bluetooth
  • TabTurn Bluetooth on Wait for your phone to find the HC-05 Bluetooth module
  • Once it has been found click it and input the password by default it should be either "1234" or "0000"
  • Now open the application Bluetooth car Application and click the " Bluetooth image" button
  • You should see the HC-05 Module (If not re-try the steps above) click on the Module
  • The Application will then return automatically to the main screen and you can see the green text "connected"
  • At this point, the HC-05 Modules Red LED should now be constantly on instead of pulsing meaning a device is currently connected.

Thanks for Reading

watch this project video on youtube
You need to be logged in to comment