Obstacle Avoiding Robot





Introduction: Obstacle Avoiding Robot

This instructable is the written version of my "Arduino: How To Build An Obstacle Avoiding Robot" Youtube video that I've uploaded recently. I strongly recommend you to check it out.

So, without further ado, Let's get started !

Step 1: A Chassis !

the first step and the base of any robot is a chassis. i got mine from ebay, and i'll leave links for that. if you prefer, you can also make your own using cardboard and DC/Servo motors. Either way, the chassis has to include a body, two motors and sometimes even a battery holder and a switch.

Step 2: Brain

Now we need something that will orchestrate our motors, a micro-controller.

from the title of this instructable you probably have already understood that we are going to use Arduino.


well, the answer is simple. Arduino (or, specifically, Arduino Uno) is a compact, comfortable and relatively cheap micro-controller. In addition, it is very common and you can get it literally everywhere online.

Step 3: Attaching the Arduino to the Chassis

Now simply use some screws to attach the Arduino to the chassis. If you've made your own chassis/ can't find any screws, you can use a small amount of double-sided tape. If you do choose to use double-sided tape then search for an area under the arduino that doesn't have many pins/solder above it.

Step 4: A Sensor

In Order to make a robot that can maneuver by its own we need some sort of an input, so it can "know" or "judge" what to do. a very comfortable sensor that fits our goal (avoiding obstacles) is the Hc-sr04 ultrasonic sensor.

Scientific Explanation Of the sensor's action:

What the sensor does it is calculating the distance from an object by sending bursts of ultrasound towards it and measuring the time it takes to the sound waves to get back (Distance = Velocity * Time). we can use this information in order to determine whether there's a close "obstacle" near the robot and then- avoid it !

So now you know how an ultrasonic sensor work, Scientifically. Now, Let's use it !

Step 5: Attaching the Sensor to the Chassis

all we have to do next is to actually attach the sensor to the body. To make life easier, i recommend sticking a mini bread-board as well for easier wiring, although you don't have to.

Step 6: A Milestone

If it seems like the robot is staring at you, then you are on the correct way.

Step 7: Connecting the Sensor to the Brain

Now gather some wires, and connect the sensor to the arduino according to this diagram i made.

Pay attention that your ping sensor may have a different pin layout (e.g. 5 pins), but it should have a voltage pin, ground pin, trig pin and an echo pin.

Step 8: Connecting and Controlling the Motors With the Arduino

arduino boards can't control dc motors by their own, because the currents they are generating are too low. Moreover, the currents they are generating cannot be reversed, so you can't change the direction of the motor. To solve that we will use a motor driver, which helps the arduino control dc motors. The most comfortable way of using motor drivers is through shields. Motor shields are very cheap and i will leave links for where you can buy one online.

Step 9: Attaching the Motor Shield to the Ardunio

Take your motor shield and simply plug it into the arduino with the sensor's wires crunching inside.

Step 10: Connecting the Motors to the Shield

Every Motor Shield has (at least) two channels, one for the motors, and one for a power source. Locate the channels and plug your chassis' motors to the motors' channel, and whatever power source you are using ( e.g. AA batteries, Lithium Battery) to the power source's channel.

Step 11: Programming the Robot

After You've made your motor shield connections, From a hardware side, believe it or not, Your robot is Done. All you have to do next is to plug your arduino to your computer.

Now open this link and download the sketch i wrote: http://www.mediafire.com/download/dql27gnuljjpurr/...

Then, open it. Choose whatever board you're using and the com port of your arduino (my happens to be three). Finally, upload the sketch, and after a few seconds you should see a message stating that the upload is complete.

Note: If the code doesn't work, you may need to download the motor shield library from: https://learn.adafruit.com/adafruit-motor-shield/l...

you might need to download other libraries, depends on what motor shield you are using.

Step 12: Playing With the Robot and Code

After you've uploaded the code, unplug the arduino, connect your batteries and watch as the robot speeds forward and avoid obstacles. then, go over the code, examine it, play with it, improve it and modify it to fit your needs !

Step 13: About Me + What's Next ?

First of all, I would like to thank you for reading this guide ! I hope it helped you build your own robot and improved your knowledge about robotics and arduino.

I think now it's a good time to introduce myself. My name is Roy and I'm a 14.5 years old teenager who likes Math, Science, Computers, Robotics and programming. {Actually in case of Math, I don't really like It, But I'm pretty good at it ;)} . I've just started a youtube channel, hoping to help people, share some of my knowledge and learn myself.


My next Youtube (and Instructables) tutorials will deal with different methods of controlling electronics (Smartphone-Bluetooth control, TV remote control and much more) and specifically robots. There will also be videos about home automation (controlling every day appliances with your smartphone or computer using arduino/raspberry pi). so make sure you are a subscriber so you won't miss them, and I will see you next time.

Bye !

Step 14: Materials Links

17 People Made This Project!


  • Oil Contest

    Oil Contest
  • Creative Misuse Contest

    Creative Misuse Contest
  • Clocks Contest

    Clocks Contest

181 Discussions

But, what do i do if the wires won't fit?

how i get the code of programming ..and how to operate i arudino plzz help me

sir how i get code to oberate it into ardiuno...and where is the ON and OFF button in the this robot


9 months ago

Can i use L298 motor drive controller
If yes, then i have a buck converter for it also.
Please tell me the pins (to which i have to connect motors to L298)
And, also give me the code.
Thanks in advance.

1 reply

I used an L298 Motor Driver. Connect the motors if you have not done so to IN1, IN2 for left and IN3 and 4 for the right.

I want to make the same robot using Arduino nano can you help me

can more than one wire go into the slot(don't know the term for it)? like what you mean by crunching inside?

Hey mate, I want to know how many batteries had you used for this "Robot Avoiding Obstacles"?
I had used 2 Batteries (9V) for the motors and 4 cell (batteries, as a power source of H-bridge).
Need to know should I put one more Battery for Arduino of 12V?
Waiting for your reply ?


5 months ago

were can i get the code please thanks. <3

Thank you for al this info. I followed all the instructions, but had a problem:
I made an object FOLLOWING car instead of an AVOIDING car. After start it turns cirkels to the left. until the sensor notices something. It follows this object, like my hand:

I know this is cool to, but can anyone help me out, i want to make it properly?

1 reply

you connected one motor wrong..you have to check which one of the motors going backwards(instead of forwards) when there is no obstacle to avoid.Then change the wires between them and the problem is solved:)

why does my sensor only says 0 distance turning, even though the distance from an object is very far. it doesn`t say anything else only 0... HELP>>

Can i use L298 motor drive controller
If yes, then i have a buck converter for it also.
Please tell me the pins (to which i have to connect motors to L298)
And, also give me the code.
Thanks in advance.

in the picture there is only half code seen so send me full code.


9 months ago

Can u please tell me using only one dc motor which is common to 2 wheels of car . Using these connection is it possible to control and move car using Arduino?

one of my wheel is moving in the opposite direction ..

So , my robot is rotating in circle ,,please help me...

1 reply