0% found this document useful (0 votes)
92 views48 pages

Obstacle Avoiding Robot Using Pid Controller

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views48 pages

Obstacle Avoiding Robot Using Pid Controller

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

THAI NGUYEN UNIVERSITY OF TECHNOLOGY

FACULTY OF INTERNATIONAL TRAINING

LUONG VAN KHOI


K195905228010
TRAN HUY PHI
K195905218010

SENIOR DESIGN I
OBSTACLE AVOIDING ROBOT USING PID
CONTROLLER

SUPERVISOR: Dr. NGUYEN MINH Y

THAI NGUYEN 2023


THIS REPORT HAS BEEN APPROVED BY THE:
Supervisor: Dr. Nguyen Minh Y

Signed
………………….………………………………………………………………………
Date:
………………….………………………………………………………………………
Faculty Dean:
…………………………………………………………………………………………
Signed
………………….………………………………………………………………………
Date:
………………….………………………………………………………………………
Composition of the committee (optional):

Prof.Dr……………................................ Thainguyen University of Technology

Prof.Dr……………................................ Thainguyen University of Technology

Prof.Dr……………................................ Thainguyen University of Technology

Prof.Dr……………................................ Thainguyen University of Technology

Prof.Dr……………................................ Thainguyen University of Technology

1
ACKNOWLEDGEMENT
First of all, we would like to thank my supervisor Dr. Nguyen Minh Y. Despite
of his busy schedules, he always accompanies with us to finish this project. He had
planned for our meeting once a week for asking any questions that we have faced in
the process of doing research. He has much knowledge about control algorithms,
dynamic, programing and power systems etc. He had provided us basic senses about
electrical sciences, control methods and taught us how to use the Math lab software,
arduino to simulate things related to our project. He also helped me very much to
accomplish this thesis, directed me how to write some difficult parts. Simply, I could
not look forward to a better and more enthusiastic supervisor. Besides our supervisor,
we would like to thank other teachers for supporting me to finish this project. Last
but not least, we would like to thank our family, our friends for always supporting
me spiritually.

2
CONTENT
CHAPTER 1: INTRODUCTION
1.1MOTIVATION.....................................................................................................
1.2 REVIEW…...........................................................................................................
1.3 CONTRIBUTION................................................................................................
1.4 ORGANIZATION................................................................................................
CHAPTER 2: BACKGROUND
2.1 DC MOTOR.........................................................................................................
2.1.1 Strusctures.........................................................................................................
2.1.2 Windings............................................................................................................
2.1.3. Armature mmf..................................................................................................
2.1.4 Electrical power generated by DC machine......................................................
2.2 H-BRIDGE...........................................................................................................
2.3 PULSE WIDTH MODULATION (PWM)...........................................................13
2.4 PID CONTROLLER............................................................................................
CHAPTER 3: SYSTEM AND CONTROL DESIGN
3.1 HARDWARE COMPONENTS LIST..................................................................
3.2 ARDUINO ………..…………………………………………………..………………16
3.2.1 What is Arduino UNO?......................................................................................16
3.2.2 Advantage and disavantage of Arduino.............................................................18
3.2.3 Aduino UNO R3................................................................................................19
3.3 DUAL H-BRIDGE L298N STEPPER MOTOR DRIVER MODULE................
3.3.1 What is a motor driver module..........................................................................
3.3.2 L298N dual H-bridge stepper motor driver module..........................................
3.3.3 L298N circuit.....................................................................................................
3.3.4 L298N schematic...............................................................................................
3.4 HY-SRF05 ULTRASONIC SENSOR.................................................................
3.4.1 HY-SRF05 Ultrasonic sensor pin configuration...............................................
3.4.2 Ultrasonic Sensor - Working.............................................................................
3.5 SG90 SERVO MOTOR........................................................................................

3
3.5.1 SG90 Servo motor function...............................................................................
3.5.2 SG90 servo motor working ...............................................................................30
3.6 ENCODER...........................................................................................................
3.6.1 Encoder specification........................................................................................
3.6.2 Encoder working................................................................................................
3.7 WHEELS AND BATTERY.................................................................................32

CHAPTER 4: WORKING PRINCIPLE AND RESULTS


4.1 CONTROL TWO DC MOTOR BY PID CONTROLLER..................................
4.2 READ DISTANCE BY ULTRASONIC SENSOR.............................................
4.3 OBSTACLE AVOIDING PROGRAM................................................................
4.3.1 Arduino code for obstacle avoiding robot.........................................................
4.4 OBSTACLE AVOIDING ROBOT AND SCHEMATIC DIAGRAM................
CONCLUSION..........................................................................................................

4
LIST OF FIGURES
1. Figure 1: automatic vacuum cleaner
2. Figure 2: DC motor structure
3. Figure 3: A two-pole DC machine
4. Figure 4: DC motor equivalent circuit
5. Figure 5: H-bridge circuit diagram
6. Figure 6: Q1 and Q4 are on
7. Figure 7: Q2 and Q3 are on
8. Figure 8: Q1 and Q2 are on
9. Figure 9: Pulse width modulation
10. Figure 10: PID controller structure
11. Figure 11: types of arduino
12. Figure 12: Arduino UNO
13. Figure 13: board of an Arduino
14. Figure 14: L298N dual H-bridge motor driver module
15. Figure 15: L298N circuit
16. Figure 16: L298N’s specification
17. Figure 17: L298N schematic
18. Figure 18: HY-SRF05 ultrasonic sensor
19. Figure 19: SG90 servo motor
20. Figure 20: PWM period in motor
21. Figure 21: 334 pulses Encoder
22. Figure 22: Encoder code disk
23. Figure 23: rubber wheel
24. Figure 24: castor wheel
25. Figure 25: battery
26. Figure 26: speed measurement on arduino
27. Figure 27: motor speed graph
28. Figure 28: ultrasonic wave transmission by ultrasonic sensor
29. Figure 29: distance measurement on arduino
30. Figure 30: working principle program
31. Figure 31: the completed product
32. Figure 32: schematic diagram

5
ABSTRACTS
In Industrial Age as today, robots are increasingly widely used not only in the
production but also in the human life. They are the important part which can help
modern humans in general and workers in particular in every aspect of life such as in
construction, in delivery, in transport, etc. Robots can work in severe weather
conditions and full of obstacles terrain where humans work difficultly. This project
describes about an obstacle-avoiding robot vehicle which can detect obstacles by an
ultrasonic sensor. The robot is made using ultrasonic sensor and it is controlled by
Arduino microcontroller. Ultrasonic sensor fixed in front portion of the robot vehicle.
The Servo Motor scans the angle from 0 to 180 degree, simultaneously the ultrasonic
sensor detecting the obstacle ahead. It gets the data from surrounding area through
mounted sensors on the robot and is sense the obstacles and deviate its path to choose
an obstacle free path. The sensor will be sent the data to the controller to decide the
movement of the robot wheel. The robot wheel movement and direction will be
based on the sensing of the ultrasonic sensor and also using a wheel encoder. This
vehicle is used for detecting obstacles and avoiding the collision. In the future, this
project’s application will be developed in much equipment such as line detection
vehicles, automatic vacuum, a fire truck using a fire detector, etc.

6
CHAPTER 1:
INTRODUCTION

1.1 MOTIVATION
The project is designed to build an obstacle avoidance robotic vehicle using
ultrasonic sensors for its movement. An Arduino Uno is used to achieve the desired
operation. A robot is a machine that can perform task automatically. Robotics is
generally a combination of computational intelligence and physical machines
(motors). Computational intelligence involves the programmed instructions. The
project proposes robotic vehicle that has an intelligence built in it such that it guides
itself whenever an obstacle comes ahead of it. This robotic vehicle is built, using an
Arduino Uno. An ultrasonic sensor is used to detect any obstacle ahead of it and
sends a command to the Arduino. In today’s world robotics is a fast growing and
interesting field. Robot has sufficient intelligence to cover the maximum area of
provided space. Automatically obstacle avoiding Robots are robots that can perform
desired tasks in unstructured environments without continuous human guidance. The
obstacle detection is primary requirement of this autonomous robot. The robot gets
the information from surrounding area through mounted sensors on the robot.

1.2 REVIEW
• Obstacle avoiding robots can be used in almost all mobile robot navigation
systems.
• Development of line detection vehicles using line detection sensors.
• A fire truck uses a fire detector
• They can be used for household work like automatic vacuum.
• They can also be used in dangerous environments, where human penetration
could be fatal

Figure 1: Automatic vacuum cleaner


7
1.3 CONCLUTION
In this topic, I design an automatically obstacle-avoiding robot with three
wheels in industrial areas. The topic has many applications such as: tracking,
delivering goods, applying in automatic vacuum, bringing many benefits to people.
• Solving problems in delivering goods in industrial area
• Calculate, design and write algorithms for avoiding obstacles
• Help students apply the knowledge learned in the training program to scientific
research and work with real systems; improve professional knowledge and skills;
the ability to proficiently use tools, components and software supporting
specialized electrical engineering.

1.4 ORGANIZATION
• Chapter 2: Background
• Chapter 3: System and control design
• Chapter 4: Working principle and Results

8
CHAPTER 2:
BACKGROUND

2.1 DC MOTOR
A DC motor is a machine that converts electrical energy into mechanical
energy. The most common types rely on the forces produced by magnetic fields. DC
motors were the first type widely used, since they could be powered from existing
direct-current lighting power distribution systems. A DC motor's speed can be
controlled over a wide range, we can change the speed and the direction of the motor
by using other electronic devices with pulse width modulation method (PWM),
actually we control the pulse-width of the voltage apply on the motor. The DC
machine is a versatile electromechanical energy conversion device characterized by
superior torque characteristics and a wide range of speed. Its efficiency is very good
over its speed range. DC currents are required for both its field winding, located on
the stator, and its armature winding on the rotor. The DC machine is more cost than
comparable AC machines, and its maintenance cost are also higher. Because of their
costs, DC machines are not widely used in industry. Their use is limited to tough
jobs, such as in steel mills and paper mills. They are also used as motors for control
purposes.
2.1.1 Structures
• Stator: Electrical or permanent magnets, provided magnetic field
• Rotor: Coils (winding) mounted on the shaft
• Commutator: Brushes (carbon)

Figure 2: DC Motor Structure


2.1.2 Windings
DC machines have two sets of electrical winding:
• Field winding: on the stator
• Amature winding: on the rotor.
9
Figure 3: A two-pole DC machine

2.1.3. Armature mmf


• The axis of the armature mmf is 900 from the axis of the field winding.
• The stator (field) winding mmf: Fs.
• The rotor (armature) winding mmf: Fr
2.1.4 Electrical power generated by DC machine
If the losses of the DC machine are neglected, from the energy conservation
principle, the electrical power is equal to the mechanical power:
𝑬a𝑰a = 𝑾m𝑻m
𝑬a𝑰a = electrical power
𝑾𝒎𝑻𝒎 = mechanical power
At steady state, the mechanical torque Tm is equal to the electromagnetic torque
Te.
Equivalent circuit:

10
Figure 4: DC motor equivalent circuit

2.2 H-BRIDGE
An H bridge is an electronic circuit that enables a voltage to be applied across a
motor in either direction. These circuits are often used in robotics and other
applications to allow DC motors to run forwards or backwards. In general an H-
bridge is a rather simple circuit, containing four switching element. The switching
elements (S1, S2, S3, S4) can be relay, BJT or MOSFET. The diodes (D1, D2, D3,
D4) are called catch diodes, with the load at the center, in an H-like configuration:

Figure 5: H-bridge circuit Diagram


The top-end of the bridge is connected to a power supply (battery for example)
and the bottom-end is grounded. In generally all four switching elements can be
turned on and off independently, though there are some obvious restrictions. Though
the load can in theory be anything you want, by far the most pervasive application if
H-bridges is with a brushed DC or bipolar stepper motor (steppers need two H-
bridges per motor) load. In the following I will concentrate on applications as a
brushed DC motor driver.
Static Operation:

11
If Q1 and Q4 are turned on, the left lead of the motor will be connected to the
power supply, while the right lead is connected to ground. Current starts flowing
through the motor which energizes the motor in the forward direction and the motor
shaft starts spinning.

Figure 6: Q1 and Q4 are on

If Q2 and Q3 are turned on, the reverse will happen, the motor gets energized in
the reverse direction, and the shaft will start spinning backwards.

Figure 7: Q2 and Q3 are on

In a bridge, you should never ever close both Q1 and Q2 (or Q3 and Q4) at the
same time. If you did that, you just have created a short-circuit (really low-resistance
path between power and GND). This condition is called ‘shoot-through’ and is an
almost guaranteed way to quickly destroy your bridge, or something else in your
circuit.

12
Figure 8: Q1 and Q2 are on

2.3 PULSE WIDTH MODULATION (PWM)


PWM is a technique for getting analog results with digital means. Digital
control is used to create a square wave, a signal switched between on and off. This
on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on versus the time that the signal
spends off. The duration of "on time" is called the pulse width. To get varying analog
values, you change, or modulate, that pulse width. In the graphic below, the green
lines represent a regular time period. This duration or period is the inverse of the
PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz,
the green lines would measure 2 milliseconds each. A call to analogWrite() is on a
scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on),
and analogWrite(127) is a 50% duty cycle (on half the time) for example

13
Figure 9: Pulse width modulation

2.4 PID CONTROLLER

Figure 10: PID controller structure

14
A PID controller is an instrument used in industrial control applications to
regulate temperature, flow, pressure, speed and other process variables. PID
(proportional integral derivative) controllers use a control loop feedback mechanism
to control process variables and are the most accurate and stable controller. PID
control is a well-established way of driving a system towards a target position or
level. It's a practically ubiquitous as a means of controlling temperature and finds
application in myriad chemical and scientific processes as well as automation. PID
control uses closed-loop control feedback to keep the actual output from a process as
close to the target or setpoint output as possible.

15
CHAPTER 3:
SYSTEM AND CONTROL DESIGN

3.1 HARDWARE COMPONENTS LIST


• LM298N Motor Driver Module
• HC-SR04 Ultrasonic Sensor
• SG90 RC Servo Motor
• Encoder
• Battery
• Wheels
• Castor Wheel
• Arduino UNO R3
• Wires
3.2 ARDUINO
The list of Arduino boards includes the following such as:
• Arduino Uno (R3)
• LilyPad Arduino
• Red Board
• Arduino Mega 2560
• Arduino Leonardo
• Arduino Fio
• Arduino Erthenet
• Arduino Pro
• Arduino BT
• Arduino Nano
• Arduino Mini

16
Figure 11: Types of Arduino
3.2.1 What is Arduino UNO?
• The Arduino Uno is an open-source microcontroller board based on the
Microchip ATmega328P microcontroller and developed by Arduino.cc. The
board is equipped with sets of digital and analog input/output (I/O) pins that
may be interfaced to various expansion boards (shields) and other circuits.
• There are 14 digital I/O pins and 6 analog pins incorporated on the board that
make this device unique and stand out from others.
• Out of 14 digital I/O, 6 are used for PWM (pulse width modulation).
• A crystal oscillator of 16MHz frequency is added on the board.
• This board comes with USB cable port that is used to connect and transfer
code from computer to the board.
• DC power jack is coupled with the board that is used to power the board.
Some version of Arduino board lacks this feature like Arduino Pro Mini
doesn’t come with DC power jack.

17
Figure 12: Arduino UNO

• This board comes with two voltage regulator i.e. 5V and 3.3V which provides
the flexibility to regulate the voltage as per requirements as compared to
Arduino Pro Mini which comes with only one voltage regulator.
• There is no much difference between Arduino Uno and Arduino Mega except
later comes with more memory space, bigger size and more I/O pins.
• Arduino software called Arduino IDE is used to program the board which is a
common software used for all boards belonged to Arduino family.
• Availability of Atmega16 on the board makes it different than Arduino Pro
Mini which uses USB to serial converter to program the board.
• There is a reset button and 4 hardware serial port called USART which
produces a maximum speed for setting up communication. [1]
3.2.2 Advantages and Disadvantages of Arduino
*Advantages:
• Ready to Use: Arduino comes in a complete package form which includes the
5V regulator, a burner, an oscillator, a micro-controller, serial communication
interface, LED and headers for the connections. Just plug it into USB port of
your computer and then you can start to code.

18
• Examples of codes: Another big advantage of Arduino is its library of
examples present inside the software of Arduino.
• Effortless functions: Another advantage of Arduino is its automatic unit
conversion capability. You can say that during debugging you don't have to
worry about the unit conversions. Just use your all force on the main parts of
your projects.
• Large community: There are many forums present on the internet in which
people are talking about the Arduino. Engineers, hobbyists and professionals
are making their projects through Arduino.
*Disadvantages:
• Structure: During building a project you have to make its size as small as
possible. But with the big structures of Arduino we have to stick with big
sized PCB’s.
• Cost: The difference between the costs is mainly due to this programmer
reason. Still if you need one package then the cost difference will be as less as
nearly $5 and it will rise when you have to use many packages.
• Easy to use: if you started your journey of micro-controllers with Arduino
then it will be very difficult for you to make the complex intelligent circuitries
in future. The easy to use hardware/software of Arduino unable a person to
learn the basics of many things likes Serial communication, ADC, I2C etc. [2]

3.2.3 Arduino Uno R3


The UNO is the best board to get started with electronics and coding. The UNO
is the most used and documented board of the whole Arduino family.
Structure
Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage
(recommended) 7-12V
Input Voltage (limit) 6-20V

19
Digital I/O Pins 14 (of which 6 provide PWM output)
PWM Digital I/O Pins 6
Analog Input Pins 6
DC Current per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
32 KB (ATmega328P) of which 0.5 KB
Flash Memory used by bootloader
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz
LED_BUILTIN 13
Length 68.6 mm
Width 53.4 mm
Weight 25 g

* Details of components on the board

Figure 13: Board of an Arduino

20
Power USB
Arduino board can be powered by using the USB cable
from your computer. All you need to do is connect the USB
cable to the USB connection (1).

Power (Barrel Jack)


Arduino boards can be powered directly from the AC
mains power supply by connecting it to the Barrel Jack (2).

Voltage Regulator
The function of the voltage regulator is to control the
voltage given to the Arduino board and stabilize the DC
voltages used by the rocessor and other elements.

Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time
issues. How does Arduino calculate time? The answer is, by
using the crystal oscillator. The number printed on top of the
Arduino crystal is
16.000H9H. It tells us that the frequency is 16,000,000
Hertz or 16 MHz.

Arduino Reset
You can reset your Arduino board, i.e., start your program
from the beginning. You can reset the UNO board in two ways.
First, by using the reset button (17) on the board. Second, you
can connect an external reset button to the Arduino pin labelled
RESET (5).

21
Pins (3.3, 5, GND, Vin)
• 3.3V (6) − Supply 3.3 output volt
• 5V (7) − Supply 5 output volt
• Most of the components used with Arduino board works
fine with 3.3 volt and 5 volt.
• GND (8)(Ground) − There are several GND pins on the
Arduino, any of which can be used to ground your circuit.
• Vin (9) − This pin also can be used to power the Arduino
board from an external power source, like AC mains power
supply.

Analog pins

The Arduino UNO board has five analog input pins A0


through A5. These pins can read the signal from an analog
sensor like the humidity sensor or temperature sensor and
convert it into a digital value that can be read by the
microprocessor.
Main microcontroller
Each Arduino board has its own microcontroller (11).
You can assume it as the brain of your board. The main IC
(integrated circuit) on the Arduino is slightly different from
board to board. The microcontrollers are usually of the
ATMEL Company. You must know what IC your board has
before loading up a new program from the Arduino IDE. This
information is available on the top of the IC. For more details
about the IC construction and functions, you can refer to the
data sheet.
ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header
for the Arduino consisting of MOSI, MISO, SCK, RESET,
VCC, and GND. It is often referred to as an SPI (Serial
Peripheral Interface), which could be considered as an
"expansion" of the output. Actually, you are slaving the output

22
device to the master of the SPI bus.

Power LED indicator


This LED should light up when you plug your Arduino
into a power source to indicate that your board is powered up
correctly. If this light does not turn on, then there is something
wrong with the connection.

TX and RX LEDs
On your board, you will find two labels: TX (transmit)
and RX (receive). They appear in two places on the Arduino
UNO board. First, at the digital pins 0 and 1, to indicate the
pins responsible for serial communication. Second, the TX and
RX led (13). The TX led flashes with different speed while
sending the serial data. The speed of flashing depends on the
baud rate used by the board. RX flashes during the receiving
process.
Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of
which 6 provide PWM (Pulse Width Modulation) output.
These pins can be configured to work as input digital pins to
read logic values (0 or 1) or as digital output pins to drive
different modules like LEDs, relays, etc. The pins labeled “~”
can be used to generate PWM.

AREF
AREF stands for Analog Reference. It is sometimes, used
to set an external reference voltage (between 0 and 5 Volts) as
the upper limit for the analog input pins.

3.3 DUAL H-BRIDGE L298N STEPPER MOTOR DRIVER


3.3.1 What is a motor driver module?
A motor driver module is a simple circuit used for controlling a DC motor. It is
commonly used in autonomous robots and RC cars (L2938N and L293D are the most
regularly utilized motor driver chips). A motor driver module takes the low voltage
input from a controller like Arduino. This input logic controls the direction of DC
motors connected to the driver. To put it in simple words, you can control the

23
direction of DC motors by giving appropriate logic to the motor driver module. The
motor driver module consists of a motor driver IC, which is the heart of the module.
The IC alone can control the DC motor but using the module makes the interfacing
with Arduino easy. All microcontrollers operate on low-level voltage/current signals,
unlike motors. For instance, the Arduino or PIC microcontroller can output a
maximum voltage of 5V or 3.3V. But a decent DC motor needs at least 5V or 12V.
Also, the output current limit of Arduino is relatively very low. Hence the output of
Arduino is not enough to power up the motors. To solve this problem the use of a
motor driver is essential. We bridge the gap between the Arduino and motor by
introducing a motor driver between them. And to supply the voltage/current required
to operate the motor, an external supply is connected to the motor driver module. [3]
3.3.2 L298N dual H-bridge stepper motor driver module
This dual bidirectional motor driver, is based on the very popular L298 Dual
HBridge Motor Driver Integrated Circuit. The circuit will allow you to easily and
independently control two motors of up to 2A each in both directions.It is ideal for
robotic applications and well suited for connection to a microcontroller requiring just
a couple of control lines per motor. It can also be interfaced with simple manual
switches, TTL logic gates, relays, etc. This board equipped with power LED
indicators, on-board +5V regulator and protection diodes.

Figure 14: L298N Dual H-Bridge Motor Driver Module

The L298N motor driver is based on the H-bridge configuration (an H-bridge is
a simple circuit that lets us control a DC motor to go backward or forward.), which is
useful in controlling the direction of rotation of a DC motor. It is a high current dual
full H-bridge driver that is constructed to receive standard TTL logic levels. It can
also be used to control inductive loads e.g. relays, solenoids, motors (DC and
stepping motor), etc.

24
3.3.3 L298N circuit

Figure 15: L298N circuit

Table of PINOUT of L298N Motor Driver IC:


Pin Name Function
1, 15 Sense A, Between this pin and the ground, a sense
Sense B resistor is connected to control the current of the
load.
2, 3 Output 1, Outputs of the Bridge A; the current that
Output 2 flows through the load connected between these
two pins is monitored at pin 1.
4 VS Supply Voltage for the Power Output
Stages. A noninductive 100nF capacitor must be
connected between this pin and ground.
5, 7 Input 1, Input TTL Compatible Inputs of the Bridge A.
2
6, 11 Enable A, TTL Compatible Enable Input: the L state
Enable B disables the bridge A (enable A) and/or the bridge
B (enable B).
8 GND Ground
9 VSS Supply Voltage for the Logic Blocks.
(A100nF capacitor must be connected between
this pin and ground.)
10, Input 3, Input TTL Compatible Inputs of the Bridge B.
12 4

25
13,14 Output 3, Outputs of the Bridge B. The current that
Output 4 flows through the load connected between these
two pins is monitored at the pin.

Figure 16: L298N’s specifications


*Specification
• Driver: L298N
• Driver power supply: +5V~+46V
• Driver Io: 2A
• Logic power output Vss:
+5~+7V (internal supply +5V)
• Logic current: 0~36mA
• Controlling level:
Low -0.3V~1.5V
High: 2.3V~Vss
• Enable signal level:
Low: -0.3V~1.5V
High: 2.3V~Vss
• Max power: 25W (Temperature 75o C)
• Working temperature: -25C~+130C
• Dimension: 60mm*54mm
• Driver weight: ~48g

26
3.3.4 L298N schematic

Figure 17: L298N schematic

*Pins of IC L298N
• 4 pins INPUT: IN1, IN2, IN3, IN4 are connected in turn to the pins 5, 7, 10, 12
of the L298. This is the control signal pins.
• 4 pins OUTPUT: OUT1, OUT2, OUT3, OUT4 (corresponding to INPUT pins)
are connected to the pins 2, 3, 13, 14 of the L298. These pins are connected to
the engine.
• ENA and ENB legs used to control the H-bridge circuit in L298. If at logic "1"
(powered with 5V) then enables active H-bridge circuit, if at logic "0", the H-
bridge circuit is not working.
• The L298N is a dual H-Bridge motor driver which allows speed and direction
control of two DC motors at the same time. The module can drive DC motors
that have voltages between 5 and 35V, with a peak current up to 2A.

27
3.4 HY-SRF05 ULTRASONIC SENSOR

Figure 18: HY-SRF05 Ultrasonic Sensor

3.4.1 HY-SRF05 Ultrasonic Sensor Pin Configuration


Pin Pin Description
number name
1 Vcc The Vcc pin powers the sensor, typically with
+5V
2 Trig Trigger pin is an Input pin. This pin has to be
kept high for 10µs to initialize measurement by
sending ultrasonic wave.
3 Echo Echo pin is an Output pin. This pin goes high
for a period of time which will be equal to the time
taken for the ultrasonic wave to return back to the
sensor.
4 GND This pin is connected to the Ground of the
system.

*HC-SR04 Sensor Features


• Operating voltage: +5V
• Theoretical Measuring Distance: 2cm - 450cm
• Practical Measuring Distance: 2cm - 80cm
• Accuracy: 3mm
• Measuring angle covered: less than 15°
• Operating Current: less than 15mA
• Operating Frequency: 40Hz

28
3.4.2 Ultrasonic Sensor - Working
The HY-SRF05 Ultrasonic sensor is a 4-pin module, whose pin names are Vcc,
Trigger, Echo and Ground respectively. This sensor is a very popular sensor used in
many applications where measuring distance or sensing objects are required. The
module has two eyes like projects in the front which forms the Ultrasonic transmitter
and Receiver. The sensor works with the formula:
Distance = Speed * Time (3.1)
Next, we read the time the ECHOPIN stays HIGH (so it goes from LOW to
HIGH, then stays at HIGH depending on the time it takes for the echo to return). We
take that duration multiply to 0.034 then divide to 2 the speed of the sound is 0.034
cm/microsecond. We divide by two because the distance calculated is the distance
from our sensor to the object and back to the sensor. Hence, the distance will be
calculated by the formula:
Distance = (duration*0.034)/2 (3.2)
The Ultrasonic transmitter transmits an ultrasonic wave, this wave travels in air
and when it gets objected by any material it gets reflected back toward the sensor this
reflected wave is observed by the Ultrasonic receiver module. HY-SRF05 ultrasonic
sensor is commonly used with both microcontroller and microprocessor platforms
like Arduino, ARM, PIC, Raspberry Pie etc. The following guide is universally since
it has to be followed irrespective of the type of computational device used. Power the
Sensor using a regulated +5V through the Vcc and Ground pins of the sensor. The
current consumed by the sensor is less than 15mA and hence can be directly powered
by the on board 5V pins (If available). The Trigger and the Echo pins are both I/O
pins and hence they can be connected to I/O pins of the microcontroller. To start the
measurement, the trigger pin has to be made high for 10uS and then turned off. This
action will trigger an ultrasonic wave at frequency of 40Hz from the transmitter and
the receiver will wait for the wave to return. Once the wave is returned after it getting
reflected by any object the Echo pin goes high for a particular amount of time which
will be equal to the time taken for the wave to return back to the sensor. The amount
of time during which the Echo pin stays high is measured by the MCU/MPU as it
gives the information about the time taken for the wave to return back to the Sensor.
[4]

29
3.5 SG90 SERVO MOTOR

Figure 19: SG90 Servo Motor

3.5.1 SG90 Servo motor function


Table of wire configuration
Wire Wire color Description
number
1 Brown Ground wire connected to the ground of
system
2 Red Powers the motor typically +5V is
used
3 Orange PWM signal is given in through this wire
to drive the motor
*SG90 Servo Motor Specifications
• Operating Voltage: +5V typically
• Torque: 2.5kg/cm
• Operating speed is 0.1s/60°
• Gear Type: Plastic
• Rotation: 0°-180°
• Weight of motor: 9gm
• Package: gear horns and screws [5]
3.5.2 SG90 servo motor working
As we know there are three wires coming out of SG90 Servo motor. To make
this motor rotate, we have to power the motor with +5V using the Red and Brown
wire and send PWM signals to the Orange color wire. Hence we need something that
could generate PWM signals to make this motor work, this something could be
anything like a 555 Timer or other Microcontroller platforms like Arduino, PIC,
ARM or even a microprocessor.

30
Figure 20: PWM Period in motor

The PWM signal produced should have a frequency of 50Hz that is the PWM
period should be 20ms. Out of which the On-Time can vary from 1ms to 2ms. So
when the ontime is 1ms the motor will be in 0° and when 1.5ms the motor will be
90°, similarly when it is 2ms it will be 180°. So, by varying the on-time from 1ms to
2ms the motor can be controlled from 0° to 180°.
3.6 ENCODER
An encoder is a sensing device that provides feedback. Encoders convert
motion to an electrical signal that can be read by some type of control device in a
motion control system, such as a counter or PLC. The encoder sends a feedback
signal that can be used to determine position, count, speed, or direction. A control
device can use this information to send a command for a particular function

Figure 21: 334 pulses Encoder

31
3.6.1 encoder specification
• 334 pulses
• Operating voltage 5-12 V-DC
• Two phase A, B 90 degree apart
3.6.2 encoder working

Figure 22: Encoder code disk

A beam of light emitted from an LED passes through the Code Disk, which is
patterned with opaque lines (much like the spokes on a bike wheel). As the encoder
shaft rotates, the light beam from the LED is interrupted by the opaque lines on the
Code Disk before being picked up by the Photodetector Assembly. This produces a
pulse signal: light = on; no light = off. The signal is sent to the counter or controller,
which will then send the signal to produce the desired function.
3.7 WHEELS AND BATTERY

These are a pair of basic, 65mm wheels with black rubber tires. These wheels
are the same ones designed to fit onto DAGUs right angle gear motors. With these
wheels you will be able to get almost any beginners robot project moving. These
wheels are sold in packs of two.

32
Figure 23: Rubber wheel

Castor wheel is a circular wheel with rubber grip fastened on DC motor shaft
by screw. Castor wheel provide help in movement of robot in any direction.

Figure 24: Castor wheel

The vehicle is powered by two 3.7 volts batteries as a primary source of an


electrical energy for the motors and as a power supply for the Arduino

Figure 25: Battery

33
CHAPTER 4:
WORKING PRINCIPLE AND RESULTS

4.1 CONTROL TWO DC MOTOR BY PID CONREOLLER


Two encoder for each motor measure the number of pulse independently then
send the signal to the Arduino, encoder disks have 334 pulse that mean for each 334
pulse motor completed rotating one round and from that calculate the speed of
motors then control it by discrete time PID controller. The parameters Kp, Ki, Kd are
particularly chose for this project.
Kp = 0.4; Ki = 1.41; Kd = 0.01.
deltaT = 500;
error = reference_speed – previous_speed;
p = error;
i = i + (error – previous_error)*(deltaT/1000)/2;
d = (error – previous_error)/(deltaT/1000);
PID = Kp*p + Ki*I + Kd*d;
The following is the measuring result of speed controlling on Arduino.
The reference speed is 0.45 m/s
After about 2 seconds motor reach the steadystate. The settling time is quite
lage but after that the system seem quite stable.

Figure 26: Speed measurement on arduino

34
Figure 27: Motor speed graph
4.2 READ DISTANCE BY ULTRASONIC SENSOR
read the time the ECHOPIN stays HIGH (so it goes from LOW to HIGH, then
stays at HIGH depending on the time it takes for the echo to return). We take that
duration multiply to 0.034 then divide to 2
Distance = (duration*0.034)/2 (4.1)

Figure 28: The ultrasonic wave transmission by ultrasonic sensor

35
The working of distance measurement is quite accurate but with the distance
under 10 cm there are some error, I assume that the distance is too small the system
can not work completely correct.
This is an an example result of distance reading:

Figure 29: Distance measurement on Arduino

4.3 OBSTACLE AVOIDING PROGRAM


The speed controlling and distance reading are combined with the following
rogram:
Robot turned on, Read distance. If distance is greater than the stopdistance
which was defined as 20cm, the car go forward. if distance is smaller than
stopdistance, servo motor turn to 180 degree makes the ultrasonic sensor turn left
then read the distance. If distance is greater than stopdistance, the car turn left and
then go forward. If distance is smaller than stopdistance servo motor turn to 0 degree
makes the ultrasonic Sensor turn right then read the distance. If distance is greater
than stopdistance, the car turn right then go forward. If distance is smaller than
stopdistance, the car turn back and then go forward

36
Figure 30: Working principle program

4.3.1 Arduino code for obstacle avoiding robot

#define encode_l 2
#define encode_r 3
#include <EduIntro.h>
ServoMotor servo(D13);
const int motorright1 = 7;
const int motorright2 = 8;
const int motorleft1 = 9;
const int motorleft2 = 10;
const int en_r = 5;
const int en_l = 6;
const int trig = 11;
37
const int echo = 12;
float pulse_r = 0;
float pulse_l = 0;
float rpmRight;
float rpmLeft = 0;
float p_r = 0, i_r = 0, d_r = 0;
float error_r;
float PID_r;
float pre_error_r;
float p_l = 0, i_l = 0, d_l = 0;
float error_l;
float PID_l;
float pre_error_l;
unsigned long t;
unsigned long t_0 = 0;
float t_d;
float rpm_r;
float rpm_l;
float speedright;
float speedleft;
int stopdistance = 20;
int duration;
int distance;
float x;
float y =1;
float z;
float s = 0;

float deltaT = 500;


float speedref_r = 0.45;
float speedref_l = 0.45;
float kp_r = 0.4; float ki_r = 1.41; float kd_r = 0.001;
float kp_l = 0.4; float ki_l = 1.41; float kd_l = 0.001;

void pulsecount_R() {
pulse_r++;
}
void pulsecount_L() {
pulse_l++;
}

void setup() {
Serial.begin(9600);

38
pinMode(encode_r, INPUT);
pinMode(encode_l, INPUT);
pinMode(motorright1, OUTPUT);
pinMode(motorright2, OUTPUT);
pinMode(motorleft1, OUTPUT);
pinMode(motorleft2, OUTPUT);
pinMode(en_r, OUTPUT);
pinMode(en_l, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
attachInterrupt(1, pulsecount_R, RISING);
attachInterrupt(0, pulsecount_L, RISING);
}

void loop() {
rpm_r = (speedref_r*60)/(0.065*3.14);
rpm_l = (speedref_l*60)/(0.065*3.14);
speedright = (rpmRight*0.065*3.14)/60;
speedleft = (rpmLeft*0.065*3.14)/60;
t = millis();
if (t - t_d >= 2/1000){
digitalWrite(trig, 1);
}
if (t - t_d >= 12/1000){
digitalWrite(trig, 0);
t_d = millis();
}
duration = pulseIn (echo, HIGH, 8000);
distance = ((duration*0.034/2));
if (distance < 1){
distance = 100;
}

while (t - t_0 >= deltaT) {


rpmRight = (pulse_r / 334)*60*1000/deltaT ;
rpmLeft = (pulse_l / 334)*60*1000/deltaT;

error_l = rpm_l - rpmLeft;


p_l = error_l;
i_l = i_l + (pre_error_l + error_l)*deltaT / 2000;
d_l = (error_l - pre_error_l) / (deltaT/1000);
PID_l = kp_l * p_l + ki_l * i_l + kd_l * d_l;
pre_error_l = error_l;

39
if (PID_l > 255) {
PID_l = 255;
}
if (PID_l < 0) {
PID_l = 0;
}
if (rpmLeft == 0){
i_l = 0;
}

error_r = rpm_r - rpmRight;


p_r = error_r;
i_r = i_r + (pre_error_r + error_r)*deltaT / 2000;
d_r = (error_r - pre_error_r)/(deltaT/1000);
PID_r = kp_r * p_r + ki_r * i_r + kd_r * d_r;
pre_error_r = error_r;
if (PID_r > 255) {
PID_r = 255;
}
if (PID_r < 0) {
PID_r = 0;
}
if (rpmRight == 0){
i_r = 0;
}

t_0 = t;
pulse_r = 0;
pulse_l = 0;
}
z = t - x;
if ((y == 1)&&(z >= 1000)&&(distance < stopdistance)){
z = 0;
y = 2;
s = 1;
digitalWrite(motorright1, LOW);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, LOW);
analogWrite(en_r, 0);
analogWrite(en_l, 0);
delay(1000);
servo.write(180);

40
delay(500);
x = millis();
}
if ((y == 2)&&(z > 2000)&&(distance > stopdistance)){
z = 0;
y = 1;
s = 1;
delay(500);
servo.write(90);
delay(1000);
digitalWrite(motorright1, HIGH);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, HIGH);
analogWrite(en_r, 100);
analogWrite(en_l, 100);
delay(500);
digitalWrite(motorright1, LOW);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, LOW);
analogWrite(en_r, 0);
analogWrite(en_l, 0);
delay(500);
x = millis();
s = 0;
}
if ((y == 2)&&(z > 2000)&&(distance < stopdistance)){
z = 0;
y = 3;
s = 1;
delay(500);
servo.write(0);
delay(500);
digitalWrite(motorright1, LOW);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, LOW);
analogWrite(en_r, 0);
analogWrite(en_l, 0);
delay(500);
x = millis();
}

41
if ((y == 3)&&(z > 2000)&&(distance > stopdistance)){
z = 0;
y = 1;
s = 4;
s = 0;
delay(500);
servo.write(90);
delay(1000);
digitalWrite(motorright1, LOW);
digitalWrite(motorright2, HIGH);
digitalWrite(motorleft1, HIGH);
digitalWrite(motorleft2, LOW);
analogWrite(en_r, 100);
analogWrite(en_l, 100);
delay(500);
digitalWrite(motorright1, LOW);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, LOW);
analogWrite(en_r, 0);
analogWrite(en_l, 0);
delay(500);
x = millis();
}
if ((y == 3)&&(z > 2000)&&(distance < stopdistance)){
z = 0;
y = 1;
s = 4;
s = 0;
delay(500);
servo.write(90);
delay(1000);
digitalWrite(motorright1, HIGH);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, HIGH);
analogWrite(en_r, 100);
analogWrite(en_l, 100);
delay(900);
digitalWrite(motorright1, LOW);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, LOW);
digitalWrite(motorleft2, LOW);

42
analogWrite(en_r, 0);
analogWrite(en_l, 0);
delay(500);
x = millis();
}
if (s == 0){
digitalWrite(motorright1, HIGH);
digitalWrite(motorright2, LOW);
digitalWrite(motorleft1, HIGH);
digitalWrite(motorleft2, LOW);
analogWrite(en_r, PID_r);
analogWrite(en_l, PID_l);
}
}

4.4 OBSTACLE AVOIDING ROBOT AND SCHEMATIC DIAGRAM

Figure 31: The completed product

43
Figure 32: Schematic Diagram

44
CONCLUSION
PID control system is ubiquitous in industrial, medical, military, automotive,
utility and many other applications - and sometimes appear in our daily lives. In this
very project PID controller is used to control the stability when it operate.This
project presented a simple, cost effective obstacle-avoiding robot for an unmanned
land mover. Two pairs of heterogonous sensors were employed to detect obstacles
along the path of the mobile robot. A degree of accuracy and minimum probability
of failure were obtained. The evaluation on the autonomous system shows that it is
capable of avoiding obstacles, ability to avoid collision and change its position. It is
evident that, with this design more functionality This project will be helpful in hostile
environment, defense and security sectors of the country.

45
REFERENCE
[1] What is a Microcontroller? Programming, Definition, Types & Examples -
The Engineering Projects
[2] L298N Motor Driver Pin Diagram, Working, Datasheet & Arduino
Connection (etechnophiles.com)
[3] PID controller - Wikipedia
[4] DC motor - Wikipedia
[5] What is a DC Motor - Equivalent Armature Circuit - Circuit Globe

46

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy