Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

AIMST UNIVERSITY

FACULTY OF ENGINEERING AND COMPUTER


TECHNOLOGY
SCHOOL OF ENGINEERING

Robotics Project Report


(Obstacle Avoiding Robot)

OCT SEMESTER 2020


Robotics
B. Eng. (Hons) in Electrical and Electronics Engineering
ARUNRAJ A/L SURES
E16101106
INTRODUCTION

Going by the basic definition of obstacle avoidance, it means to be able to identify and detect any kind of
interference, which can also be termed as obstacles, and either avoid collision into it or even maneuver its
path around it. Such a project would be very helpful in helping robots in factories, warehouses, or even in
day to day house chores. Our project uses ultrasonic sensors in support with Arduino Uno development
board, which houses ATmega328 microcontroller chip. It works on a very simple principle. An ultrasonic
sensor has a source and an echo receiver. It sends bursts of ultrasonic signals and the echo receiver
receives it and determines how far or how close any object reflecting the signals is in front of it. It is
controlled by an Arduino Uno board, which is programmed to control the motors in the car, to stop or
proceed as per information received by the sensor. The programming involved follows a very simple
algorithm. If a distance is fixed as a threshold, say 10cm by the ultrasonic sensor, it will give a high signal
if distance is more than it, otherwise it give a low signal. If the signal received is high, the Arduino signals
the motor driver module to move forward, or else stop. If the signal received is low, that is, if any
obstruction is found, first the car moves to right, and if the signal is still low, it moves to left. If the car is
obstructed on both sides, it reverses back and then takes a turn.

LITERATURE REVIEW

I reviewed some technical papers and found that many different kinds of mechanism and methodology can
be and has been used, including one using IR and PIR sensors, as reported by Aniket D Adhvaryu, in
“Obstacle-avoiding robot with IR and PIR motion Sensors.The project proposed the use of PIR sensors as
it was more sensitive compared to others in detecting human beings (and other objects radiating infrared
signals) but was less accurate in handling general obstacles like walls and objects lying around. A remotely
controlled device, as planned and developed by Vaghela Ankit, Patel Jigar and Vaghela Savan in “Obstacle
Avoidance Robotic Vehicle Using Ultrasonic Sensor, Android and Bluetooth For Obstacle Detection,
shows the versatility that this project has. This device can be used in modular forms, and can be adapted to
perform different kinds of tasks, having many different kinds of application, and in different work
environments. This project shows the control of an obstacle avoiding robot vehicle in conjunction with
manual control. This shows the future scope this project has.
COMPONENTS USED

1 Arduino Uno 1

2 5V DC Motors 2

1 HC-SR04 Ultrasonic Sensors

1 LM298N Motor Driver Module

1 Stator Motor

1 Sensor Shield

3 Wheels

1 Chasis

Power Source for Arduino and Motors

Connecting Wires
COMPONENTS DESCRIPTION

Arduino Uno

Arduino Uno is a development board housing an ATmega328 microcontroller, and has fourteen digital and
6 analog pins as input-output ports, for connections to different peripherals [3]. It has an open sourced
design which makes it much cost effective, and was introduced in 2005 to provide an easy and inexpensive
way for students, hobbyists and professionals alike to create devices working with different actuators and
sensors. It requires an external power source with voltage in the range of 9-12V. Apart from the fourteen
digital and six digital pins, it also has a USB connection, a power jack, and a reset button

HC-SR04 Ultrasonic Sensor

HC-SR04 Ultrasonic Sensor It is an ultrasonic range finder, which works on the principle of a RADAR,
but instead of using radio waves, it uses ultrasonic sound waves. It consists of a transmitter which emits
ultrasound of the frequency 40 KHz [4], and an echo receiver which receives reflected sound waves. The
time difference between emitting and receiving of the waves gives the distance between the sensor and the
surface off which waves are reflecting. It works in the range of 2-400cm in 15o effective measuring angle.
It has 4 pins, one for +5V power supply, one neutral, or ground pin, one signal pin to trigger the transmitter
and one echo pin to obtain the results.
LM298N Motor Driver Module

LM298N Motor Driver Module LM298N is a motor driver module shield, which can be interfaced with
Arduino Uno board. It is a high voltage, high current dual full bridge driver. It can be operated in the range
of 5-35V and has a current output of 2-3A. It has a voltage drop of about 2V, which is due switching
transistors in HBridge circuit. It can be used to run 2 DC motors at once.

Sensor Shield

The Sensor Shield's purpose is make it easy to connect cables and devices to the correct Arduino pins. It is
not an active device. It simply connects the Arduino pins to many connectors that are ready to use to
connect to various devices like Servos and Sensors with simple cables
CIRCUIT DIAGRAM

BlockDiagram
Results
Project Demonstration link

https://drive.google.com/file/d/1W1AC-FfiOAbBYa7MyIUrhkUjiAOxTZMG/view?usp=drivesdk

View in 720p for better resolution

CONCLUSION

The above Arduino controller and ultrasonic sensor were studied and the HcSR-04 ultrasonic sensor was
selected, as the controlling result are satisfying for its use in the automobile prototype system bring
developed. It was used to sense the obstacle and avoidance them. On successful implementation of
obstacle avoidance algorithm was successfully carried out too with minimal errors, by coding the
algorithm in python. Obstacle avoidance is a very good application to be used in vehicle preventing many
accidents and loss of life.
Appendix

(source code used)

#include <Servo.h>

// Pins
#define TRIG_PIN A0
#define ECHO_PIN A1

//Define all the connections maps to the L298N


#define enA 13
#define in1 12
#define in2 11
#define in3 7
#define in4 6
#define enB 5
#define servoPin 2

class Motor{

int enablePin;
int directionPin1;
int directionPin2;

public:

//Method to define the motor pins


Motor(int ENPin,int dPin1,int dPin2){
enablePin = ENPin;
directionPin1 = dPin1;
directionPin2 = dPin2;
};

//Method to drive the motor 0~255 driving forward. -1~-255 driving backward
void Drive(int speed){
if(speed>=0){
digitalWrite(directionPin1, LOW);
digitalWrite(directionPin2, HIGH);
}
else{
digitalWrite(directionPin1, HIGH);
digitalWrite(directionPin2, LOW);
speed = – speed;
}
analogWrite(enablePin, speed);
}
};

Motor leftMotor = Motor(enA, in1, in2);


Motor rightMotor = Motor(enB, in3, in4);
Servo myservo; // create servo object to control a servo

void motorInitiation(){
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Set initial direction and speed
digitalWrite(enA, LOW);
digitalWrite(enB, LOW);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}

//Variables
// Anything over 400 cm (23200 us pulse) is "out of range"
const unsigned int MAX_DIST = 23200;
bool ObsticalAhead = false;
int servoPos = 90;

enum Directions { Forward, TurnLeft, TurnRight, TurnAround,Brake};

Directions nextStep = Forward;

unsigned long t1;


unsigned long t2;
unsigned long pulse_width;
float cm;
float inches;

//SETUP
void setup() {

// The Trigger pin will tell the sensor to range find


pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);

// We’ll use the serial monitor to view the sensor output


Serial.begin(9600);
myservo.attach(servoPin);
motorInitiation();
Directions nextStep = Forward;
}

void loop() {

checkDistance();
checkDirection();
drive();
}

void checkDistance(){

// Hold the trigger pin high for at least 10 us


digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Wait for pulse on echo pin
while ( digitalRead(ECHO_PIN) == 0 );

// Measure how long the echo pin was held high (pulse width)
// Note: the micros() counter will overflow after ~70 min
t1 = micros();
while ( digitalRead(ECHO_PIN) == 1);
t2 = micros();
pulse_width = t2 – t1;

// Calculate distance in centimeters and inches. The constants


// are found in the datasheet, and calculated from the assumed speed
//of sound in air at sea level (~340 m/s).
cm = pulse_width / 58.0;
inches = pulse_width / 148.0;

// Print out results


if ( pulse_width > MAX_DIST ) {
//Serial.println("Out of range");
} else {
//Serial.print(cm);
//Serial.print(" cm \t");
//Serial.print(inches);
//Serial.println(" in");
}

// Wait at least 60ms before next measurement


delay(60);

if(cm<= 20){
ObsticalAhead = true;
Serial.println("Problem Ahead");

}
else{ ObsticalAhead = false;}

}
void checkDirection(){
Serial.println("checking direction");
if(ObsticalAhead ==true){
nextStep = Brake;
drive();
myservo.write(180); // tell servo to go to position in variable ‘pos’
delay(400); // waits 15ms for the servo to reach the position
checkDistance();
if(ObsticalAhead ==false){//if left side is open
nextStep = TurnLeft;
Serial.println("Next step is TurnLeft");
myservo.write(90);//reset servo position
delay(400);
}
else{// left is blocked, now need to look at right
myservo.write(0); // tell servo to go to position in variable ‘pos’
delay(800); // waits 15ms for the servo to reach the position
checkDistance();
if(ObsticalAhead ==false){//if right side is open
nextStep = TurnRight;
Serial.println("Next step is TurnRight");
myservo.write(90);//reset servo position
delay(400);
}
else{//right is blocked as well, need to turn around
nextStep = TurnAround;
myservo.write(90);//reset servo position
delay(300);
Serial.println("Next step is TurnAround");
}
}

}
else{nextStep = Forward;}//No obstical ahead
}

void drive(){
switch (nextStep){
case Forward:
leftMotor.Drive(255);
rightMotor.Drive(255);
Serial.println("Forward");

break;
case TurnLeft:
leftMotor.Drive(-255);
rightMotor.Drive(255);
Serial.println(" TurnLeft");
delay(400);

break;
case TurnRight:
leftMotor.Drive(255);
rightMotor.Drive(-255);
Serial.println(" TurnRight");
delay(400);
break;
case TurnAround:
leftMotor.Drive(255);
rightMotor.Drive(-255);
Serial.println(" TurnAround");
delay(600);
break;

case Brake:
leftMotor.Drive(0);
rightMotor.Drive(0);
Serial.println(" stopped");
}

You might also like