Introduction: Arduino Obstacle Avoiding Robot

Picture of Arduino Obstacle Avoiding Robot

In this instructable I will show you how to make your own obstacle avoiding robot!

We will use the Arduino uno board and an ultrasonic sensor. If the robot detects an object in front of it, with the help of a small servo motor, it scans the area left and right in order to find the best way to turn.

It has also a notification LED, an buzzer to play a tone when an object is detected and an button for changing the function of the robot (stopped / moving forward).

Official page:

It's very easy to make it!

So, let's get started!

Step 1: What You Will Need

Picture of What You Will Need

For this project you will need:

You will also need one big (metal) paperclip and an bead to make the back supporting wheel.

For the robot base I used a piece of plexiglass (12 x 9.5 cm). You can also use a piece of wood or metal (or two cd/dvd disks ).

The cost of the entire project is about 20$ :)


  • Drill machine
  • Super glue
  • Screw driver
  • Hot gun glue (optional)


We will use an 9V battery to power on our robot because it's small and cheap, but it's not very powerful and will be empty after about one hour. Consider if you want to use a rechargeable battery pack (min 6V, max 7V) that will be more powerful but it will be also more expensive and bigger than the 9V battery.

Step 2: Prepare the Robot Base

Picture of Prepare the Robot Base

Place all the hardware parts on plexiglass piece and mark it with a pen in order to open the holes with a drill. (1st image).

Begin with the bottom side, use a super glue to mount motors in the plexiglass piece. Make sure that they are perfectly aligned - use a triangle ruler (2nd image). Now attach the 9V battery holder.

Tip: You can also open holes for the motors and battery cables .

Step 3: Put the Hardware Parts on It

Picture of Put the Hardware Parts on It

Use the spacers, screws and nuts to attach the Arduino uno board and the L298 module on plexiglass piece. The mini breadboard can be easily attached on it with the adhesive tape that already have at the bottom of it (1st image).

Now it's time to make the rear supporting wheel, use the paper clip and bead (2nd image). Finally, use a super glue (or hot gun glue) to attach it on the bottom side of the plexiglass.

Step 4: The "eyes" of Our Robot

Picture of The "eyes" of Our Robot

Use a super glue to attach the tiny servo motor in the front side of our robot. Watch the first image above to understand how to put the ultrasonic sensor in the servo motor by using a small gear piece.

The second above image shows the completed part that will be the "eyes" of our robot.

Step 5: The Circuit

Picture of The Circuit

Now it's the time to make our circuit! The connections are pretty easy, watch the above image with the breadboard circuit schematic.

Tip: Use the breadboard only for the LED, button and buzzer, this will keep it simple and you can use the remain area to add more stuff on the future.

Step 6: The Code

Picture of The Code

Here is the code, embedded using Codebender!

Codebender is an online Arduino IDE - It's the easiest way to program your Arduino board directly from your browser! Just click on the "Run on Arduino" button and that's it! Try it! It's really amazing!

Plug an battery on it and press the function button once, your robot will start moving forward. To stop it, just press the button for one more time.

You can also press the 'Edit' button and start making your modification in the sketch.

For example, try to change the '10' cm value that is the distance that will make the robot to stop and 'look' for a clear path.

Note: if your robot doesn't move forward, try to change the pins of the motors (motorA1 and motorA2 or motorB1 and motorB2).

Step 7: Well Done!

Picture of Well Done!

Now you have your own Arduino Obstacle Avoiding Robot!!!

Check my page for more cool Arduino projects:

I hope you liked this, let me know in the comments below, I would like to see photos of your cool robots!


MelvinV9 (author)2017-11-25

By any chance, does this robot detect holes? For example, if it is driven on a table, will it identify the edge and stop?

ppr153 (author)2017-09-24

Hey can I use only one motor?

JezzD (author)ppr1532017-11-02

Yes, but you will only have forward and backward movement, no steering.

AmeyaW2 (author)2017-10-01

this was really helpful
thanks a lot

JayB182 (author)2017-09-08

Hey there, where did you get that L298n into fritzing ? how did you add it ? thank you

angelinelouw (author)2017-06-06

Can anybody please tell me what coding language is being used here?

its embedded c(im a beginner)

Datrell (author)2017-04-24

i want to add this robot to my smart walking stick cane. How do I do that as far as putting both arduino codes together?

Rjshalom (author)2017-02-20

what is the code to do it with only the L298N and the distance sensor?

RavikumarM3 (author)2017-01-27

wow its super..i made this robot only single is successful completed

Exop (author)2016-04-29

Love the project! If I build a waterproof case around the sensor, can I use it underwater?

Ardumotive_com (author)Exop2016-11-30

No it's not possible... But you can try something like this

budrow01 (author)Exop2016-11-30

If you build a case, the sound for the sensor can't get out.

YUSUF6731 (author)2016-08-01

I make the connections as given in diagram also but I don't know where is something wrong in the connections,sometimes both motors rotating sometimes only one....and how many times I have to press the button??
And the ultrasonic sensor detects obstacle only once and then all stops...

Please help me...

adgjj4679 (author)YUSUF67312016-10-03


IsraelD3 (author)2016-08-14

la línea:

stop(); //Object detected! Stop the robot and check left and right for the better way out!

error: sketch\Ultrasonic.cpp: In function 'void loop()':

Ultrasonic.cpp:69: error: 'stop' was not declared in this scope

stop(); //robot remain stoped


Ultrasonic.cpp:79: error: 'forward' was not declared in this scope

forward(); //All clear, move forward!


Ultrasonic.cpp:84: error: 'stop' was not declared in this scope

stop(); //Object detected! Stop the robot and check left and right for the better way out!


Ultrasonic.cpp:106: error: 'left' was not declared in this scope



Ultrasonic.cpp:110: error: 'right' was not declared in this scope



Ultrasonic.cpp:114: error: 'backward' was not declared in this scope

backward(); //The road is closed... go back and then left ;)


Ultrasonic.cpp:115: error: 'left' was not declared in this scope



exit status 1

'stop' was not declared in this scope

¿que hago?

sblai made it! (author)2016-02-15

Works pretty good. Makes poor decisions occasionally..

YUSUF6731 (author)sblai2016-08-01

sblai can you please tell me where you connected the batteries to arduino?? between 12v and Vin ???

LMaddio made it! (author)2016-04-11

Was nice to make it, the code is something I think it could get cleaner and with more performance. Keeps being cool!

YUSUF6731 (author)LMaddio2016-08-01

Hello Leonardo, am happy that you make this robot.
I make my connections many times as same given in the circuit,but the motors are running once and then stopped..nothing is happening,the robot stops.The hc sr04 also detects object and stops...

Is you make any changes in the code to run it bcoz I didn't found any error during compile.

And I wanna know the wire going from Vin to 12v on l298,in figure it is given Vin or power can I attach 9v battery in this ???

help me please...

QueztionM (author)2016-06-07

I'm new when it comes to electronics so I have to ask this. How did you connect the H-Bridge to the servo motors? It seems like it is dividing a pin with the sensors on the arduino when I look at the circuit image.

AkhilK21 (author)2016-05-03

I have a problem in uploading code

so what can i do?

I am use ardiuno Uno Atmega368

electric guy (author)2016-01-08

if u want to can u make a code and stations and program it so it can't go past those stations?

you mean like a "memory" feature? I don't know.. maybe you can do it but the programming part will be not easy...

especially for me I don't no how to write a arduino code

RajeshK112 (author)2016-03-21

program is showing errors. how to rectify and make it work. pls reply

RajeshK112 (author)2016-03-14

where to connect battery

SunnyE1 (author)2016-02-06

I am using an l298 and have enable a and b where do I connect this

MehulK1 (author)2016-02-06

where to put the battery connections???

abdullah05 (author)2016-02-03

please can you tell me the use of servo motor in it

alireza0000 (author)abdullah052016-02-05

yep , rotating the sensor to the right and left to chose the best way to go

alireza0000 (author)2016-02-04

where to connect battery wires ??

electric guy (author)2015-12-14

this is exactly what I need thx

thank you for your comment! I would like to see a photo of your new robot!

Unfortunately I'm not done with it (I'm not really even close) it will basicly look like the one above just a few modifications thanks and check out my instuctables anntenna guy

keep going ;)

sadiq96 (author)Ardumotive_com2015-12-30

I like this thing. but doesn't accept MasterCard?

Ardumotive_com (author)sadiq962016-01-02

I don 't know.. ask gearbest

GekoF (author)2015-12-22

How do you get 2 wires to go into the same pin? In the schematic you have 2 wires going into 5v pin how you do that?

Ardumotive_com (author)GekoF2015-12-31

use your breadboard......

usmank13 (author)Ardumotive_com2016-01-01

hello , Nice robot can u send me pdf file.... i have no pro account .

n1cod3mus (author)2015-12-31

no video?

Ardumotive_com (author)n1cod3mus2015-12-31

not yet :P

About This Instructable




More by Ardumotive_com:MIKE - Arduino Line Following Robot for Beginners "GRECO" - Arduino Object Avoiding Robotfor BeginnersArduino 3D Printed Digital Thermometer With DHT-22 Sensor
Add instructable to: