Obstacle Avoiding Robot Using Pid Controller
Obstacle Avoiding Robot Using Pid Controller
SENIOR DESIGN I
OBSTACLE AVOIDING ROBOT USING PID
CONTROLLER
Signed
………………….………………………………………………………………………
Date:
………………….………………………………………………………………………
Faculty Dean:
…………………………………………………………………………………………
Signed
………………….………………………………………………………………………
Date:
………………….………………………………………………………………………
Composition of the committee (optional):
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
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
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)
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:
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.
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.
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
13
Figure 9: Pulse width modulation
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
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]
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
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).
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
22
device to the master of the SPI bus.
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.
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.
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
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.
26
3.3.4 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
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
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
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
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.
33
CHAPTER 4:
WORKING PRINCIPLE AND RESULTS
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)
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:
36
Figure 30: Working principle program
#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;
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;
}
39
if (PID_l > 255) {
PID_l = 255;
}
if (PID_l < 0) {
PID_l = 0;
}
if (rpmLeft == 0){
i_l = 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);
}
}
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