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: http://www.ardumotive.com/obstacle-avoiding-robot.html

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: www.ardumotive.com

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

<p>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?</p>
<p>what is the code to do it with only the L298N and the distance sensor?</p>
<p>wow its super..i made this robot only single time.it is successful completed</p>
<p>Love the project! If I build a waterproof case around the sensor, can I use it underwater? </p>
<p>No it's not possible... But you can try something like this</p><p>http://www.ebay.com/itm/Ultrasonic-Module-Distance-Measuring-Transducer-Sensor-Waterproof-Perfect-/272041782549?hash=item3f56f42d15:g:mMYAAOSw5ZBWQbkT </p>
<p>If you build a case, the sound for the sensor can't get out.</p>
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?? <br>And the ultrasonic sensor detects obstacle only once and then all stops...<br><br>Please help me...
<p>la l&iacute;nea:</p><p>stop(); //Object detected! Stop the robot and check left and right for the better way out!</p><p>error: sketch\Ultrasonic.cpp: In function 'void loop()':</p><p>Ultrasonic.cpp:69: error: 'stop' was not declared in this scope</p><p> stop(); //robot remain stoped</p><p> ^</p><p>Ultrasonic.cpp:79: error: 'forward' was not declared in this scope</p><p> forward(); //All clear, move forward!</p><p> ^</p><p>Ultrasonic.cpp:84: error: 'stop' was not declared in this scope</p><p> stop(); //Object detected! Stop the robot and check left and right for the better way out!</p><p> ^</p><p>Ultrasonic.cpp:106: error: 'left' was not declared in this scope</p><p> left();</p><p> ^</p><p>Ultrasonic.cpp:110: error: 'right' was not declared in this scope</p><p> right();</p><p> ^</p><p>Ultrasonic.cpp:114: error: 'backward' was not declared in this scope</p><p> backward(); //The road is closed... go back and then left ;)</p><p> ^</p><p>Ultrasonic.cpp:115: error: 'left' was not declared in this scope</p><p> left();</p><p> ^</p><p>exit status 1</p><p>'stop' was not declared in this scope</p><p>&iquest;que hago?</p>
<p>Works pretty good. Makes poor decisions occasionally..</p>
sblai can you please tell me where you connected the batteries to arduino?? between 12v and Vin ???
Was nice to make it, the code is something I think it could get cleaner and with more performance. Keeps being cool!
Hello Leonardo, am happy that you make this robot.<br>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...<br><br>Is you make any changes in the code to run it bcoz I didn't found any error during compile.<br><br>And I wanna know the wire going from Vin to 12v on l298,in figure it is given Vin or power jack...so can I attach 9v battery in this ???<br><br>help me please...
<p>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. </p>
<p>I have a problem in uploading code</p><p>so what can i do?</p><p>I am use ardiuno Uno Atmega368</p>
if u want to can u make a code and stations and program it so it can't go past those stations?
<p>you mean like a &quot;memory&quot; feature? I don't know.. maybe you can do it but the programming part will be not easy... </p>
especially for me I don't no how to write a arduino code
<p>program is showing errors. how to rectify and make it work. pls reply</p>
<p>where to connect battery </p>
I am using an l298 and have enable a and b where do I connect this
<p>where to put the battery connections???</p>
<p>please can you tell me the use of servo motor in it</p>
<p>yep , rotating the sensor to the right and left to chose the best way to go </p>
<p>where to connect battery wires ??</p>
this is exactly what I need thx
<p>thank you for your comment! I would like to see a photo of your new robot! </p>
<p>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</p>
<p>keep going ;)</p>
I like this thing. but doesn't gearbest.com accept MasterCard?
<p>I don 't know.. ask gearbest</p>
<p>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?</p>
<p>use your breadboard......</p>
<p>hello , Nice robot can u send me pdf file.... i have no pro account .</p>
<p>no video?</p>
not yet :P

About This Instructable




More by Ardumotive_com:Arduino 3D Printed Compass Arduino Bluetooth Car With Custom PCB DIY Arduino LED Matrix Display - 80x8 Px 
Add instructable to: