Introduction: Obstacle Avoiding Robot With Arduino

Picture of Obstacle Avoiding Robot With Arduino

OBSTACLE- AVOIDING ROBOT

An OBSTACLE AVOIDING ROBOT is one which can avoid an obstacle by using ultrasound sensor and navigate in its own path. With a breadboard attached to the robot you can play fun within a short period of time. One such is what we are going to discuss here. This project can teach you how a sensor can be used to process some data.

BASIC REQUIREMENTS:

ü ARDUINO UNO

ü Ultrasonic sensor (SR 04)

ü 2 low current motors

ü 12v battery

What is an ARDUINO?

Arduino Uno is a single board microcontroller intended to make the application of interactive objects or environmentsmore accessible. The hardware consists of an open source hardware board designed around an 8-bit atmel AVR microcontroller or a 32 bit atmel ARM. The Arduino board used for this purpose is Arduino UNO. You can find more about this board in Arduino UNO.

What is an Ultra sonic sensor?

An Ultrasonic sensor generate high frequency sound waves and evaluate the echo which is received back by the sensor, measuring the time interval between sending the signal and receiving the echo to determine the distance to an object.A Sr-04 ultrasonic module has been used here for the demo purpose . It has a power, ground and two data pins(Trigger, Echo).The usage of this module is explained in Usage of US 04

Where to start with?

This is a simple weekend project that could be completed in less than a day following the steps given below:

STEP 1:

Take an ARDUINO UNO and connect it with your PC using a data cable. ARDUINO IDE is the platform that is used to write the codes and burn it in the microcontroller of ARDUINO. Hence, it is necessary to have this software installed in the PC before connecting the ARDUINO UNO. You can ping through the options available in this software before it is used. You can get started in an Arduino IDE environment very easily by seeing, Getting started with Arduino IDE

STEP 2:

An ARDUINO code which is written in ARDUINO IDE (Software) is shown below. Here ultrasonic sensor reading is used to calculate the distance from the sensor to any obstacle before it and these readings are used to control the motor.

If you are a novice you could try this simple ARDUINO IDE code which is given below.

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

//ARDUINO IDE code for Obstacle detecting Robot

const int trig = 12;

const int echo = 11;

const int motorPin1 = 2;//left motor of the robot

const int motorPin1 = 3;//right motor of the robot

long duration, inches, cm;

void setup()

{

Serial.begin(9600);

pinMode(trig,OUTPUT);

pinMode(echo,INPUT);

pinMode(motorPin1, OUTPUT);

pinMode(motorPin2, OUTPUT);

}

void loop()

{

digitalWrite(trig, LOW);

delayMicroseconds(2);

digitalWrite(trig, HIGH);

delayMicroseconds(5);

digitalWrite(trig, LOW);

duration = pulseIn(echo, HIGH);

//this returns the time duration taken

//for the ultrasonics to hit an obstacle and return

inches = duration / 74 / 2;//converts the time duration into inches

cm = duration / 29 / 2;//converts the time duration to cm

if(cm>4)//checks for the distance is greater than 4cm

//the bot forward if the condition is true

digitalWrite(motorPin1,HIGH);//Both the motors are in ON state

digitalWrite(motorPin2,HIGH);

Serial.print("No obstacle detected");

else

//the robot turns right when an obstacle is detected

digitalWrite(motorPin1,HIGH);//the left motor is in ON state

digitalWrite(motorPin2,LOW);//the right motor is in OFF state

Serial.print("Obstacle detected");

delay(100);//this delays the process by 100millisec

Serial.print(inches);

Serial.print(“in, “);

Serial.print(cm);

Serial.print(“cm”);

Serial.println();

delay(100);//this delays the code by 0.1 second and repeats the loop again

}

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

You have to burn this code into the ARDUINO UNO board using the UPLOAD option.

In this code we first initialize the ultrasonic and the 2 motors with the pins in which they are connected. Then we get an input from the ultrasonic sensor and convert the duration(time period) into cm and inches in order to measure distance. The distance recorded is compared with 4cm (in this case) and the condition is checked. If the condition is TRUE the two MOTORS are in high state and they roll forward. But when the condition fails, the right motor stops rotating and the left motor continues to rotate for a specified time period in the delay. This makes the robot to turn towards the right direction. The loop is executed once again and the process continues and the process goes on…

STEP 3:

Make the circuit connections as shown in the picture below.

This circuit is exclusively for low current motors used in toy cars. In case you use a high power DC motor, you may need to add a Motor driver circuit. You can find more about it in blog.iqubean.in

STEP 4:

Make a trial test before you build up a chassis for the robot.

STEP 5:

Now it is ready. All you need is to build a chassis and fit these modules in the chase and experiment yourself….

This project can be extended where the user can have three ultrasonic sensors and develop a chase where the robot can track its own path and navigate.

There you Go!.. Please don't forget to drop your valuable comments!....

For further updates stay tuned with http://myelectrokart.blogspot.in/...

detailed explanation

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

Step 1:

Comments

PIYUSHT7 (author)2017-02-19

The code do have some corrections!!

yaswanthtb94 (author)PIYUSHT72017-07-06

Can you give me the edited code?

kravi3 (author)PIYUSHT72017-06-28

Please post the updated code.

anerdkb16 (author)2016-01-12

thanks! which motors did you use exactly?

kravi3 (author)anerdkb162017-06-28

I have used 200 RPM DC motor.

IanT49 (author)2016-04-14

Where did the tutorial I'm half built and all the instructions are gone

MadhuneedamG (author)IanT492017-06-25

it's in the PDF at the bottom of the tuto

AyushU1 (author)2016-07-27

it says ur code is wrong ...the serial print part ...

serial print ("cm")

adscorp (author)2015-12-27

muito obrigado nós iniciantes precisamos disso

kravi3 (author)adscorp2015-12-29

você pode encontrar muitas atualizações em alguns dias..

About This Instructable

26,117views

19favorites

License:

Bio: I like thinking hypothetically and bringing it to reality.
More by kravi3:Ultimate Guide for TravellersUseful Van Fabric HacksPlant Monitoring Using Alexa
Add instructable to: