Dear friends welcome to another video! In this video we are going to build an Arduino Robot that can avoid obstacles. It is a fun project and a great learning experience, so without any further delay, let’s get started!

As you can see the Arduino Robot that we are going to build today is moving around and it can detect obstacles and avoid them. It uses an Ultrasonic distance sensor in order to measure the distance from its front side. When it detects and obstacle it stops, goes backward for a few cms, looks around and then it turns to the direction with the more space available. As you are going to find out, building this impressive little robot is extremely easy and fun. It will not take you more than a couple of hours from start to finish. Then you can use my code, modify it and implement your own robot behavior easily. It is a great learning experience and great introduction to robotics for kids and adults. Let’s build it!

How to build an Arduino Robot

The parts needed in order to build this Arduino Robot are these:


Robot Chassis Kit:

Arduino Uno:

Motor Shield:

SG90 Servo:

Ultrasonic Sensor:


100nf Capacitors:

300μF Capacitors:


Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

The cost of the this Arduino Robot is around 25$.

First we have to build the Arduino Robot chassis. The kit, contains the chassis, two motors with the wheels attached, a front wheel, a battery holder, some screws and wires.

We solder the thick black and red wires at the motors. Next we have to solder the small ceramic capacitors to the motors. We do so in order to reduce the electrical noise that the motor produces. Since we are using ceramic capacitors which do not have polarity, just solder one leg to each motor connection. Repeat the procedure with the second motor and we are ready to continue.

We then attach the front wheel. My little nephew helps me with that as you can see. This project is great for kids! Next we attach the rear wheels according to the instructions leaflet that comes with kit. The next step is to attach the switch to the battery holder. I cut the battery holder wires and I solder the red wire from the battery holder to the first pin of the switch. The black wire from the battery holder goes to the third pin. Now I solder a small red wire to the middle pin of the switch. Another small black wire is then soldered to the third pin of the switch. Our switch is ready. I then attach it to the battery holder using hot glue.

We move on to the motor shield. This shield provides power to the motors and the servo motor and makes our life much easier. The motors need a lot of current, and this shield can provide up to 600mA of current to each motor, that’s why we need it. We have to solder 4 wires to the motor shield. These wires will be then connected with the supersonic sensor. We solder one to 5V, one to GND, one to Analog Pin 5, and the last one to analog pin 4.

Next we attach the motor shield to the Arduino Uno board. With a double sided tape I attach the Arduino Uno and the Battery holder to the chassis. With a double sided tape I also attach the supersonic sensor to the Servo motor and both of them to the robot chassis. I could 3D print a part in order to achieve that but since most of the viewers don’t have access to a 3D printer yet, I chose this simple solution to achieve that.

We are almost ready! All we have to do is to attach the wires! First we connect the Supersonic sensor. Vcc goes to 5V via the wire we attached earlier. GND goes to the GND wire. ECHO pin goes to Analog Pin 5, and TRIG pin goes to Analog Pin 4. Next have to connect the power. We connect the black wire from the switch to the motor shield. It goes to the GND pin of this external power connector. The red wire from the switch goes to the M+ connector. If we open the switch we can see that the green LED lights up, the Arduino is receiving power from the batteries.

The next step is to connect the motors. We connect the left motor to the M1 connector of the shield like this. We connect the right motor to the M3 connector of the shield this way. Lastly we have to connect the servo motor. We connect it to the SERVO_2 connector of the shield. The Brown wire is GND, the RED is Vcc and the orange is Signal. That’s it! Our robot is now ready! All we have to do is to load the code to it.

The code uses three libraries. Two of them must be downloaded in order the program to compile. The first one is the motor shield driver from Adafruit. The second library is the NewPing library for the supersonic distance sensor. You can find the links for both libraries in the description of the video.


Motor Shield Library:

New Ping Library:!download-install

Let’s now take a quick look at the code in order to see how it works. At first we declare some variables. In this one we set the speed of the motors. You can set any value up to 255. Next, we initialize the servo motor and we set it to “look” straight. In my case this was at 115 degrees angle. Next we read the distance a few times in order to get a valid distance measurement.

Now we go to the loop function which executes every 40 ms. If the distance we measured is less than or equal to 15 cm, we stop the motors, we go backwards for 300ms and then we stop again. We look right and left and we measure the distance at each direction. If the distance at one direction is greater than the other we turn the robot the largest distance. If the distance from the front of the robot is greater than 15 cm, we move the robot forward.

That’s the simple algorithm I developed for this robot so far. As always you can find the code of the project in a link in the description of the video.  You can easily modify the code I provide in order to modify the robot behavior. It is very easy.









Never miss a video: Subscribe to