0% found this document useful (0 votes)
39 views17 pages

Obstacle Avoidance Robot

The document describes a line following and obstacle avoidance robot project submitted by three students. It includes the components required, code for Arduino to control the robot, and conclusions about designing such a robot.

Uploaded by

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

Obstacle Avoidance Robot

The document describes a line following and obstacle avoidance robot project submitted by three students. It includes the components required, code for Arduino to control the robot, and conclusions about designing such a robot.

Uploaded by

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

27/04/24

Line Follo wing and Obstacle Avoidance Robot

SUBMITTED TO: MARYAM IQBAL


BAHRIA SCHOOL OF ENGINEERING AND APPLIED SCIENCES
Linear Control System

Complex Engineering Project Part 1:

Name Enrollment

Muhammad Haider Sultan 01-133212-066

Mohammad Hamza 01-133212-049

Abdul Ahad Abbasi 01-133212-001

Project name: Obstacle avoidance and line following Robot.

Instructor name: Engr .Maryam Iqbal.


Department of Electrical Engimneering

Bahria School of Engineering and Applied Science

H-11 Campus,Islamabad

Obstacle avoidance and line following Robot.

Transient Response:

"The transient response of a system is its short-term behaviour immediately following a change in its
input or initial conditions."

In essence, it's how a system reacts right after something changes.

Steady State Response:

"The steady state response of a system is its stable and unchanging behaviour after

it has fully adjusted to a new set of conditions or a constant input."

Stability of a System:

Stability of a system refers to its ability to maintain its intended behaviour or state over time, even
when subjected to disturbances or changes in its environment. If a system is stable, it will settle into a
predictable and consistent pattern or state after being perturbed, without exhibiting unbounded or divergent
behaviour.
Equation:

As we haven’t designed the robot yet but with simulations done with the code the following are responses
recorded through Python.

Code of Python for Responses and Stability:

import numpy as np

import matplotlib.pyplot as plt

from scipy import signal

numerator = [1]

denominator = [1, 1, 1]

sys = signal.TransferFunction(numerator, denominator)

t_step = np.linspace(0, 10, 1000) # time vector for simulation


u_step = np.ones_like(t_step)

t, y_step = signal.step(sys, T=t_step)

plt.figure(figsize=(18, 6))

plt.subplot(1, 3, 1)

plt.plot(t, y_step, label='Step Response')

plt.title('Transient Response of the System')

plt.xlabel('Time')

plt.ylabel('Output')

plt.grid(True)

plt.legend()

steady_state_response = y_step[-1]

print("Steady State Response:", steady_state_response)

plt.subplot(1, 3, 2)

plt.plot(t, y_step, label='Step Response')

plt.title('Steady State Response of the System')

plt.xlabel('Time')
plt.ylabel('Output')

plt.grid(True)

plt.legend()

poles = sys.poles

if all(np.real(pole) < 0 for pole in poles):

print("System is stable.")

else:

print("System is unstable.")

plt.subplot(1, 3, 3)

plt.plot(np.real(poles), np.imag(poles), 'rx', label='Poles')

plt.plot([0], [0], 'bo', label='Zero (Origin)')

unit_circle = plt.Circle((0, 0), 1, color='g', fill=False, label='Unity Circle')

plt.gca().add_artist(unit_circle)

plt.title('Pole-Zero Plot with Unity Circle')

plt.xlabel('Real')

plt.ylabel('Imaginary')

plt.axvline(0, color='k', linestyle='--')

plt.axhline(0, color='k', linestyle='--')


plt.grid(True)

plt.legend()

plt.tight_layout()

plt.savefig('combined_response_and_stability.png') # Save the plot as an image

plt.show()

Responses Result from Python

Responses Result from MATLAB


Components Required:

1. Arduino uno ultrasonic sensor Hc-sr04 with case to obstacle avoidance.


2. 2 x Ir Sensor for tracing the line.
3. L293d motor driver shield for controlling the motor.
4. Servo motor SG90.
5. 4 x Bo motor with wheel. (chassis)
6. Jumper wire
7. 12v battery

Code For Arduino:

1)Defining all the Pins:

#define enA 10//Enable1 L298 Pin enA

#define in1 9 //Motor1 L298 Pin in1

#define in2 8 //Motor1 L298 Pin in1

#define in3 7 //Motor2 L298 Pin in1

#define in4 6 //Motor2 L298 Pin in1

#define enB 5 //Enable2 L298 Pin enB

#define L_S A0 //ir sensor Left

#define R_S A1 //ir sensor Right

#define echo A2 //Echo pin

#define trigger A3 //Trigger pin


#define servo A5

Initial Setup:

int Set=15;

int distance_L, distance_F, distance_R;

void setup(){

Serial.begin(9600);

pinMode(R_S, INPUT);

pinMode(L_S, INPUT);

pinMode(echo, INPUT );

pinMode(trigger, OUTPUT);

pinMode(enA, OUTPUT);

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

pinMode(enB, OUTPUT);

analogWrite(enA, 200);

analogWrite(enB, 200);

pinMode(servo, OUTPUT);

for (int angle = 70; angle <= 140; angle += 5) {

servoPulse(servo, angle); }

for (int angle = 140; angle >= 0; angle -= 5) {


servoPulse(servo, angle); }

for (int angle = 0; angle <= 70; angle += 5) {

servoPulse(servo, angle); }

distance_F = Ultrasonic_read();

delay(500);

void loop(){

Line Follower and Obstacle Avoiding:

distance_F = Ultrasonic_read();

Serial.print("D F=");Serial.println(distance_F);

//if Right Sensor and Left Sensor are at White color then it will call forword function

if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 0)){

if(distance_F > Set){forword();}

else{Check_side();}

//if Right Sensor is Black and Left Sensor is White then it will call turn Right function

else if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 0)){turnRight();}

//if Right Sensor is White and Left Sensor is Black then it will call turn Left function

else if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 1)){turnLeft();}

delay(10);

}
void servoPulse (int pin, int angle){

int pwm = (angle*11) + 500; // Convert angle to microseconds

digitalWrite(pin, HIGH);

delayMicroseconds(pwm);

digitalWrite(pin, LOW);

delay(50); // Refresh cycle of servo

Ultrasonic_read:

long Ultrasonic_read(){

digitalWrite(trigger, LOW);

delayMicroseconds(2);

digitalWrite(trigger, HIGH);

delayMicroseconds(10);

long time = pulseIn (echo, HIGH);

return time / 29 / 2;

void compareDistance(){

if(distance_L > distance_R){

turnLeft();

delay(500);

forword();

delay(600);
turnRight();

delay(500);

forword();

delay(600);

turnRight();

delay(400);

else{

turnRight();

delay(500);

forword();

delay(600);

turnLeft();

delay(500);

forword();

delay(600);

turnLeft();

delay(400);

void Check_side(){

Stop();
delay(100);

for (int angle = 70; angle <= 140; angle += 5) {

servoPulse(servo, angle); }

delay(300);

distance_R = Ultrasonic_read();

Serial.print("D R=");Serial.println(distance_R);

delay(100);

for (int angle = 140; angle >= 0; angle -= 5) {

servoPulse(servo, angle); }

delay(500);

distance_L = Ultrasonic_read();

Serial.print("D L=");Serial.println(distance_L);

delay(100);

for (int angle = 0; angle <= 70; angle += 5) {

servoPulse(servo, angle); }

delay(300);

compareDistance();

void forword(){ //forword

digitalWrite(in1, LOW); //Left Motor backword Pin

digitalWrite(in2, HIGH); //Left Motor forword Pin

digitalWrite(in3, HIGH); //Right Motor forword Pin


digitalWrite(in4, LOW); //Right Motor backword Pin

void backword(){ //backword

digitalWrite(in1, HIGH); //Left Motor backword Pin

digitalWrite(in2, LOW); //Left Motor forword Pin

digitalWrite(in3, LOW); //Right Motor forword Pin

digitalWrite(in4, HIGH); //Right Motor backword Pin

void turnRight(){ //turnRight

digitalWrite(in1, LOW); //Left Motor backword Pin

digitalWrite(in2, HIGH); //Left Motor forword Pin

digitalWrite(in3, LOW); //Right Motor forword Pin

digitalWrite(in4, HIGH); //Right Motor backword Pin

void turnLeft(){ //turnLeft

digitalWrite(in1, HIGH); //Left Motor backword Pin

digitalWrite(in2, LOW); //Left Motor forword Pin

digitalWrite(in3, HIGH); //Right Motor forword Pin

digitalWrite(in4, LOW); //Right Motor backword Pin

void Stop(){ //stop

digitalWrite(in1, LOW); //Left Motor backword Pin


digitalWrite(in2, LOW); //Left Motor forword Pin

digitalWrite(in3, LOW); //Right Motor forword Pin

digitalWrite(in4, LOW); //Right Motor backword Pin?

Overview of the Code:

This code is designed to control a line following and obstacle avoiding robot on Arduino. The software used
will be ARDUINO IDE.

Components Used:

1) ARDUINO Motor shield for controlling DC motors of the robot.


2) IR Sensors for detecting line.
3) Ultrasonic Sensor for detection of obstacle.

Sensors will be adjusted according to the lights then if both the sensors will be detecting line, the robot will
move forward, if only left sensor detects it’ll turn right, otherwise it’ll turn left. Same goes for the Ultrasonic
sensor. When no line is detected by IR Sensor, the Ultrasonic sensor will detect obstacles. If an obstacle is
detected within 10cm (parameter provided in the code), the robot will stop and will back up, then it’ll turn right
to avoid obstacle.

Circuit Diagram:
Conclusion:

Designing a line-following obstacle avoidance robot requires careful consideration of mechanical design, sensor
selection, and control algorithms. By integrating these elements effectively, the robot can navigate
autonomously while following lines and avoiding obstacles. It's essential to balance simplicity with
functionality to create a robust and efficient robot for real-world applications.
[1]

References

[1] MrElectroUino, "Arduino Obstacle Avoidance Line Follower Robot Projects," [Online]. Available:
https://www.instructables.com/Arduino-Obstacle-Avoidance-Line-Follower-Robot-Pro/.
[2] Mrelectrouino, "Autodesk Instructables," [Online]. Available: https://www.instructables.com/Arduino-
Obstacle-Avoidance-Line-Follower-Robot-Pro/.
[3] J. Zafar, "Line Follower Obstacle Avoiding Robot Using Arduino And L298 Motor Driver," marobotic,
[Online]. Available: https://marobotic.com/2023/10/22/line-follower-obstacle-avoiding-robot-using-
arduino-and-l298-motor-driver/.

--------------------------------------------------------------------------------

You might also like