Arduino Obstacle Avoiding Robot





Introduction: 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

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

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

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

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

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

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!

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!

2 People Made This Project!


  • Woodworking Contest

    Woodworking Contest
  • Clocks Contest

    Clocks Contest
  • Planter Challenge

    Planter Challenge

We have a be nice policy.
Please be positive and constructive.




How can we control the car ? Suppose if we want to move the left or somewhere else, how this could have been done since there is no remote or any other blue-tooth, wi-fi or antenna connected to the circuit ....


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

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

this was really helpful
thanks a lot

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

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

1 reply

its embedded c(im a beginner)

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?

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

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


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

2 replies

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

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

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...

1 reply

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?

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.

I have a problem in uploading code

so what can i do?

I am use ardiuno Uno Atmega368

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

1 reply

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