Capstone Project Final-Term
Capstone Project Final-Term
CAPSTONE PROJECT
BLUETOOTH CONTROLLED CAR USING ARDUINO
UNO OSTACLE AVOIDING
XE ĐIỀU KHIỂN BLUETOOTH SỬ DỤNG ARDUINO
UNO TRÁNH VẬT CẢN
MENTOR
PhD. TRI NHUT DO
HO CHI MINH CITY, 2023
1
TABLE OF CONTENTS
Chapter 1. INTRODUCTION…..……………………………………………………….3
Chapter 2. INGREDIENT DESCRIPTION……………………………………………..4
2.1.Arduino Uno………………………………………………………………………....4
2.2.Module Bluetooth HC-05……………………………………………………………8
2.3.Motor Driver L298N ………………………………………………………………..10
2.4. Ultrasonic sensors HC-SR04………………………………………………………..12
2.5.Secondary Ingredients……………………………………………………………….14
Chapter 3.SYSTEM DESIGN…………………………………………………………..16
3.1.Circuit map………………………………………………………………………….16
3.2.Flow chart…………………………………………………………………………..17
3.3.Block Diagram……………………………………………………………………...19
3.4. Operating principle ………….…………………………………………………….19
3.5.Controlled app bluetooth…………………………………………………………...20
3.6.Code………………………………………………………………………………...20
Chapter 4.RESULT……………..………………………………………………………26
Chapter 5.CONCLUSION……………………………………… ……………………..27
REFERENCES………….………………………………………………………………28
LIST OF FIGURE………………………………………………………………………29
2
Chapter 1: INTRODUCTION
In the recent days, the process of being developing is drastically improved, particularly
increased in the communication fields such as Bluetooth, other remote-controlled cars
and robots. In every country technology is currently developing with many users,
especially in India every people are using different operating systems which are available
in several smart phones. In olden days the communication between devices should be
transmitted in wired and risky way without seeking any help of any person. But in present
world the communication between devices is improved in wireless manner without risk
and fast are kept feasible manner with taking help of persons. Android operating system
is used to communicate between Smartphone hardware and several mobile applications.
This designed model is controlled with the help of Bluetooth using Smartphone.
Due to limited time and understanding, we certainly have some shortcomings in the
process. We hope you will give us your sincere feedback.
3
Chapter 2: INGREDIENT DESCRIPTION
2.1.Arduino Uno
Arduino Uno is an open control board based on the Microchip ATmega328
microcontroller developed by Arduino.cc. The board is equipped with Digital and Analog
input/output sets that can interface with various board extensions. The Arduino Uno
circuit is suitable for those who are new to and passionate about electronics,
programming... Based on the open platform Arduino.cc, it allows you to easily build your
own project as quickly as possible (set up robots, autonomous vehicles). operation,
control to turn off LED lights...).
Figure 1
4
Specifications
Contrller chip ATmega328P
Operating voltage 5V
Input
7-12V
voltage(recommended)
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
LED_BUILTIN 13
Length 68.6 mm
Width 53.4 mm
Weight 25 g
5
Power
LED: There is 1 LED integrated on the circuit board and connected to pin D13. When the
pin has a high value (HIGH), the LED will light up and the LED will turn off when it is
low (LOW).
VIN: This pin is used to supply external power (supply voltage from 7-12VDC).
5V: Output voltage 5V (maximum current on each pin is 500mA).
3.3V: Output voltage 3.3V (maximum current on each pin is 50mA).
GND: Is the pin that carries the negative electrode on the board.
IOREF: Measures the operating voltage of the microcontroller on Arduino UNO and can
read the voltage on the IOREF pin. The IOREF pin is not used as a power supply pin.
Figure 2
Memory
ATmega328 microcontroller:
32 KB of Flash memory: of which the bootloader occupies 0.5KB.
6
2 KB for SRAM: (Static Random Access Menory): values of declared variables will be
saved here. The more variables you declare, the more RAM memory it takes up. When
the data source on SRAM is lost, it will be lost.
1 KB for EEPROM: (Electrically Eraseble Programmable Read Only Memory): This is
where data can be read and written to and data will not be lost when the power is lost.
7
Figure 3
8
Figure 4
It consists of 6 pins which are STATE, RXD, TXD, GND, VCC, and EN as mentioned
on the back of the module.
STATE pin: This pin defines the state of the module whether it is paired or not with
another device.
RxD pin: This pin uses serial UART communication. This pin is used to send AT
command when the module is in command mode.
TxD pin: This pin uses serial UART communication. This pin is used to push out
responses to AT command when the module is in command mode.
Vcc pin: This pin is used to supply power to the module to make it work. It is typically
connected to the 5V pin on the Arduino board. Its voltage range lies between 3.6v to 5v.
GND pin: This pin is used to connect the module to the ground of the Arduino board.
EN pin: This pin is used to switch between command and data mode. The module will be
in command mode if this pin is set to HIGH. Similarly, the module will be in data mode
if this pin is set to LOW.
There is an enale pin that allows switching between command line and data mode.
The module has UART protocol for easy communication with any microcontroller or
system.
Communication range is up to 8 - 10 meters but will decrease when there are obstacles.
9
The device uses a 5V power source.
+9600
+19200
+38400
+57600
+115200
+230400
+460800
HC-05 application:
+In wireless headsets and mice, HC05 is available for fast wireless communication.
+In IoT instead of using WiFi network, some devices also have Bluetooth
10
Figure 5
It consists mainly of all the connections from connecting the motor to controlling it.
VCC: Pin used to provide the supply to the board. Its operating supply voltage range
from 4-46 volts.
GND: Pin used to connect the board to the ground of the supply. To ensure the proper
functioning of the board when interfacing it with an Arduino that is already powered, it is
essential to establish a connection between the ground of the board and the ground of the
Arduino.
5V: Since the board has an inbuilt 5-volt voltage regulator. This pin provides a constant
5-volt output to power internal logic circuitry as well as to power other devices
simultaneously like microcontrollers.
ENA & ENB: These pins are used to control the speed of the motor. Pulling the specified
pins HIGH will initiate the rotation of the motors at maximum Speed, whereas pulling
them LOW will halt their movement. However, by utilizing Pulse Width Modulation
(PWM), it becomes possible to control the speed of the motors. Typically, the module is
equipped with a jumper on these pins. When the jumper is installed, the motors operate at
maximum speed. If you desire to programmatically regulate the motor speed, removing
the jumpers and connecting the pins to the Arduino's PWM-enabled pins is necessary.
IN1 & IN2: These pins are used to control the motors’ spinning direction and to stop
them. These two pins are assigned to control one side motor while the IN3 & IN4 are
11
assigned to control the other motor. Putting logic HIGH-LOW to IN1 & IN2 will create a
spin in the forward direction while LOW-HIGH reverses the spin. Similarly, the same is
applicable for IN3 & IN 4. Putting logic LOW-LOW & HIGH-HIGH will cause the
motor to stop. And these pins are connected to the digital pins of the Arduino.
OUT-1 & OUT-2: This pin is used to connect to the Motors. One motor is connected to
OUT-1 & another one to OUT-2. You can connect the motor up to a voltage range of 5v
to 35volt. Keep in mind that you will get approximately a 2-volt decrement by whatever
voltage you are applied to VCC.
Figure 6
Ultrasonic sensor HC-SR04 is a modular sensor. This sensor is usually just a circuit
board, operating on the principle of receiving and transmitting ultrasonic waves by two
high-frequency speakers.
The HC-SR04 ultrasonic sensor is often combined with Arduino, PIC, AVR,... to run a
number of applications such as: detecting obstacles on robot vehicles, measuring object
distances,...
-Ultrasound transmitter:
12
+The structure of the ultrasonic transmitter and receiver are special ceramic speakers that
emit high-intensity ultrasound at a frequency of usually 40kHz for distance measurement
needs.
+ In principle, these speakers need a high voltage source to play well (manufacturer
announced = 30V). On the power circuit, IC MAX232 is used as a buffer. This IC will
take the signal from the controller, amplify the amplitude to +/-30V to power the above
speaker. This IC will be switched on and off through a transistor to limit current
consumption.
The receiver is a ceramic speaker that is only sensitive to one frequency, such as 40KHz.
Through a series of components such as OPAM TL072, NPN transistor... This signal is
continuously amplified in amplitude and finally passed through a comparator, combined
with the signal from the controller to send to the controller.
Microcontrollers (PIC16F688, STC11,...) are used to generate pulses and calculate the
time from transmitting to receiving ultrasonic waves if a TRIG signal is received.
Figure 7
13
To measure distance with the HC-SR04 ultrasonic sensor, we will emit a very short pulse
(5 microSeconds) from the Trig pin. Next, a HIGH pulse at the Echo pin will be
generated and transmitted by the sensor until a reflected wave is received at this pin. At
this time, the width of the pulse will be equal to the time the ultrasonic wave is emitted
from the sensor and reflected back.
In air, the speed of sound reaches 340 m/s (constant), equivalent to 29.412
microSeconds/cm (106 / (340*100)).
Once we have calculated the time, we will divide it by 29.412 to get the distance value.
Current: 15mA
Frequency: 40 KHZ
Figure 8
14
Figure 9
Figure 10
15
Figure 11
16
Chapter 3:System design
3.1.Circuit map
Figure 12
3.2.Flow chart
17
Figure 13
Figure 13 suggests flow chart of the designed model.
In the above figure represents flow chart of the designed model. There are many
steps of the flow chart I have been mentioned below.
Step1: Before starting the process the designed model it has the feasibility of a
primary checking of the power supply.
If there is any power supply “available” then it activates the robot car to start
the initialization of the several codes which is given by instructor. If in case the
power supply is not supplied to the designed model then it will move to starting
process and again repeat the initial checking of the power supply.
Step2: After the step 1 process completed, my designed robot car is moves to
initialization of the coding which is given by instructor. If in case coding has
several errors while initialization and stop the process of step 2 and again repeat
the process of step 1.
Step 3: After the step 2 process completed, then it sends the data to robot car then
my designed model starts moving the robot car in several directions which is
given by instructor.
18
Step4: Now then repeat the entire process to send the data and move several
directions. Suppose the instructor giving the several commands to the robot car
then it sending the data and repeat the process.
Step5: After successfully completed all steps then the entire process will come to
end.
3.3.Block Diagram
Ulatrasonic sensor
Forward DC Back DC
motor motor
Figure 14
19
The wireless interfacing between the robot and the smartphone is facilitated by the
Bluetooth connectivity feature of the bot which is implemented by using the HC-05
module.
On our Bluetooth Enabled Smartphone, the mobile App has a control interface. This
interface allows the user to send commands to the robot car, specifying the desired
actions or movements.
Upload the Code to Arduino and check the blinking LEDs of the BT module.
Open the Application, turn on the Bluetooth of the smartphone, and paired App with BT
module named “HC-05”.
If the Application is Successfully paired, the red mark at the left top corner will change to
Green.
Figure 15
Once the connection is established and the control interface is ready, the user can
wirelessly control the robot car using the Smartphone device. The control signals are
transmitted over Bluetooth and received by the Arduino board, which then interprets
them and controls the motors accordingly, executing the desired movements.
3.6.Code
#include "SoftwareSerial.h"
#include "NewPing.h" //Ultrasonic sensor function library.
20
int ENB = 10;
int val;
int carSpeed = 100;
int cm = 0;
int duration=0;
int iterations=2;
int middleDistance = 0;
int DIS = 25;
#define Trig A4
#define Echo A5
#define maxDistance 400
void setup(){
HC05.begin(9600);
Serial.begin(9600);
pinMode(Trig,OUTPUT);
pinMode(Echo,INPUT);
pinMode(ENA,OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENB,OUTPUT);
Stop();
delay(100);
}
void loop()
{
middleDistance = readPingM();
Serial.print(" Distance Middle is: ");
Serial.print(middleDistance);
if (middleDistance <= DIS)
{
goForward = false;
Stop();
delay(100);
}
21
while (HC05.available() > 0)
{
val = HC05.read();
Serial.println(val);
Serial.println("");
switch (val)
{
case 'F':if (middleDistance >= DIS) {forward();}; break;
case 'B':backward(); break;
case 'L':left(); break;
case 'R':right(); break;
case 'I':forwardRight(); break;
case 'G':forwardLeft(); break;
case 'J':backwardRight(); break;
case 'H':backwardLeft(); break;
case 'S':Stop(); break;
case '0':carSpeed = 0; break;
case '1':carSpeed = 25.5; break;
case '2':carSpeed = 51; break;
case '3':carSpeed = 76.5; break;
case '4':carSpeed = 102; break;
case '5':carSpeed = 127.5; break;
case '6':carSpeed = 153; break;
case '7':carSpeed = 178.5; break;
case '8':carSpeed = 204; break;
case '9':carSpeed = 229.5; break;
case 'q':carSpeed = 255; break;
}
}
}
int readPingM()
{
delay(10);
duration = sonar1.ping_median(iterations);
cm=(duration/2)*0.0343;
if(cm>=400)
{
cm=400;
}
if(cm<=2)
{
cm=400;
}
return cm;
22
}
23
goForward = false;
Serial.println("Turn Right");
Serial.println("");
analogWrite(ENA,carSpeed-20);
analogWrite(ENB,carSpeed-20);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
24
digitalWrite(IN4, LOW);
}
void backwardLeft() //Lui Trai
{
goForward = false;
Serial.println("Backward Left");
Serial.println("");
analogWrite(ENA,carSpeed-20);
analogWrite(ENB,carSpeed-20);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
25
Chapter 4:RESULT
Video: https://drive.google.com/file/d/1Q8hmxTXuWrkKrO-ksL-
qdNAcWiMbDC0E/view?usp=sharing
26
Chapter 5: CONCLUSION
1.Application:
- Automatic car + line detection
- Self-driving cars use IMU sensors
-…
2. Evaluation and direction of topic development
Robots and smart phone are a perfect match for us to realize smart living not only
at work, but in our homes, with the aid of easily available and widely used
technology, the Bluetooth. As the mobile devices are becoming more advanced,
using them for controlling Robots and other wireless devices is likely to be a huge
trend. It can be concluded that this idea of smart living will let us control our
surroundings remotely and wirelessly. With the ever increasing problems, our
knowledge has to expand to adapt better to the changes all around us. In the same
way it is hoped that this activity is a small step that would lead us to further
enhancements and goals
27
REFERENCES
1, https://mecsu.vn/ho-tro-ky-thuat/module-dieu-khien-dong-co-l298n.lGG
2, https://mecsu.vn/ho-tro-ky-thuat/module-bluetooth-hc05.8wL
3, https://academicprojectworld.com/how-to-build-4wheel-bluetooth-controlled-
robotic-car-using-arduino/
4, http://arduino.vn/bai-viet/42-arduino-uno-r3-la-gi
5, https://huphaco.vn/cam-bien-sieu-am-hc-sr04/
28
LIST OF FIGURE
Figure 1:Arduino UNO……………………………………………………………………4
Figure 2:Power of Arduino UNO…………………………………………………………6
Figure 3:Pin of Arduino UNO……………………………………………………...8
Figure 4:Module Bluetooth HC-05…………………………………………………9
Figure 5:Motor driver L298N……………………………………………………..11
Figure 6:Ultrasonic sensors HC-SR04……………………………………………12
Figure 7: Size and wave of HC-SR04 ultrasonic sensor………………………….13
Figure 8:Pin 18650………………………………………………………………..14
Figure 9: Battery base……………………………………………………………..15
Figure 10:Chassis………………………………………………………………....15
Figure 11: Circuit wire……………………………………………………………16
Figure 12:Circuit map…………………………………………………………….17
Figure 13:Flowchart………………………………………………………………18
Figure 14:Block diagram………………………………………………………….19
Figure 15:Controlled bluetooth app……………………………………………….20
29