Build A Bluetooth Controlled Car Using Android Phone

Introduction

 
In this lesson, you will learn how to control an Android-controlled car using Bluetooth.
 
Hardware requirements
  • The Arduino Uno
  • Bluetooth sensor
  • Motor driver
  • DC motor
  • Jumper wire
  • Chassis board
Steps to follow,
 
Step 1
 
Connect the Arduino board to the laptop(or)computer.
 
Android
 
Step 2
 
Installation of Arduino software on the laptop.
 
Android
 
Step 3
 
Open the Arduino software on a computer.
 
Android
 
Step 4
 
You can see the main page of the Arduino software.
 
Android
 
Step 5
 
Then open a new page in the software.
select File→ New
 
Android
 
A new page will open in the software.
 
Android
 
Step 6
 
Then Click TOOL→ Select BOARD → then press ARDUINO/GENUINO UNO R3
 
Android
 
Set to the board, Arduino Uno.
 
Step 7
 
Again Select TOOL → Select a PORT→ COM3 ARDUINO UNO
 
Android
 
Port set the COM3
 
Step 8
 
I have given a source code that you can use or you can use own source code
 
Then select File → open → select written program →open the program
 
Android
 
You have to select a code that is on this folder.
 
Android
 
Select the program and open it.
 
Android
 
Source code
 
I have given the program code.
  1. int motorLpin1 = 2;  
  2. int motorLpin2 = 3;  
  3. int motorRpin1 = 4;  
  4. int motorRpin2 = 5;  
  5. int motorLpwm = 10;  
  6. int motorRpwm = 11;  
  7. int motorSpeed = 125;  
  8. int turn = 45;  
  9. void setup() {  
  10.     Serial.begin(9600);  
  11.     Serial.flush();  
  12.     pinMode(motorLpin1, OUTPUT);  
  13.     pinMode(motorLpin2, OUTPUT);  
  14.     pinMode(motorRpin1, OUTPUT);  
  15.     pinMode(motorRpin2, OUTPUT);  
  16.     pinMode(motorLpwm, OUTPUT);  
  17.     pinMode(motorRpwm, OUTPUT);  
  18. }  
  19. void loop() {  
  20.     String input = "";  
  21.     while (Serial.available()) {  
  22.         input += (char) Serial.read();  
  23.         delay(5);  
  24.     }  
  25.     if (input == "n") {  
  26.         stp();  
  27.     } else if (input == "F") {  
  28.         fwd();  
  29.     } else if (input == "R") {  
  30.         rev();  
  31.     } else if (input.indexOf("TL") > -1) {  
  32.         lft();  
  33.     } else if (input.indexOf("TR") > -1) {  
  34.         rght();  
  35.     } else if (input != "") {  
  36.         motorSpeed = input.toInt();  
  37.     }  
  38. }  
  39. void fwd() {  
  40.     analogWrite(motorLpwm, motorSpeed);  
  41.     analogWrite(motorRpwm, motorSpeed);  
  42.     digitalWrite(motorLpin1, 1);  
  43.     digitalWrite(motorLpin2, 0);  
  44.     digitalWrite(motorRpin1, 1);  
  45.     digitalWrite(motorRpin2, 0);  
  46. }  
  47. void rev() {  
  48.     analogWrite(motorLpwm, motorSpeed);  
  49.     analogWrite(motorRpwm, motorSpeed);  
  50.     digitalWrite(motorLpin1, 0);  
  51.     digitalWrite(motorLpin2, 1);  
  52.     digitalWrite(motorRpin1, 0);  
  53.     digitalWrite(motorRpin2, 1);  
  54. }  
  55. void lft() {  
  56.     analogWrite(motorLpwm, motorSpeed - turn);  
  57.     analogWrite(motorRpwm, motorSpeed + turn);  
  58.     digitalWrite(motorLpin1, 0);  
  59.     digitalWrite(motorLpin2, 1);  
  60.     digitalWrite(motorRpin1, 1);  
  61.     digitalWrite(motorRpin2, 0);  
  62. }  
  63. void rght() {  
  64.     analogWrite(motorLpwm, motorSpeed + turn);  
  65.     analogWrite(motorRpwm, motorSpeed - turn);  
  66.     digitalWrite(motorLpin1, 1);  
  67.     digitalWrite(motorLpin2, 0);  
  68.     digitalWrite(motorRpin1, 0);  
  69.     digitalWrite(motorRpin2, 1);  
  70. }  
  71. void stp() {  
  72.     analogWrite(motorLpwm, 0);  
  73.     analogWrite(motorRpwm, 0);  
  74.     digitalWrite(motorLpin1, 1);  
  75.     digitalWrite(motorLpin2, 1);  
  76.     digitalWrite(motorRpin1, 1);  
  77.     digitalWrite(motorRpin2, 1);  
  78. }  
Step 9
 
Verify the program or compiler.
 
Android
 
Step 10
 
Upload the code on the Arduino board.
 
Android
 
Step 11
 
Then connect the hardware components as per the connection diagram given in the figure.
 
Android
 
Complete the connection as per the diagram.
 
Step 12
 
Install the Bluetooth control robot application using the Playstore on your android phone.
 
Android
 
Step 13
 
Open the Bluetooth control application on your phone.
 
Android
 
Then select Bluetooth device in the application
 
Android
 
Connect the HC05 Bluetooth module with the Android phone application.[password=1234 (or) 0000, from Bluetooth module]
 
Android
 
Android
 
We can now operate the Arduino car using your android application.
 
Step 14
 
The Arduino car will be working successfully.
 
Android
 
Move the Arduino car to the right, left, forward, back and side using the Android application.
 
Now you completely learned to control the Bluetooth Arduino car using your Android phone.
 

Summary

 
The Arduino project using an Android Bluetooth application to control the Arduino Uno car by connecting to the Bluetooth has been created and executed.
More exciting articles are coming up next.


Similar Articles