The best tutorial to build your first Arduino Robot

From our STAR Interns: Mohammed Ibrahim, Ashish Alex, Emil George, Vishnu Prakash, Akshay James

arduino robot tutorial

Arduino obstacle avoiding robot tutorial

One of simplest projects that you can make for the first time using an Arduino is this obstacle avoiding robot. If you are a beginner to Arduino and wish to learn more about it, look no further. This arduino robot tutorial will help you build your first robot really easily and quickly. This project will give you a clear idea on how to interface DC motors, IR sensors and motor drivers with an Arduino. You can take advantage of the knowledge you gain from building this robot to build other kick-ass robots. And if you are a true beginner, you can go through our free beginners eBook before you get started.

An arduino obstacle avoiding robot detects any obstructions in its path and avoids it by taking deviation from its current path.The same action can be more accurately obtained using ultrasonic sensor modules. And even using PID (proportional-integral-derivative) based algorithms. This concept has even been used in automatic vacuum cleaners:

What are the stuff required to do this?

  1. Arduino or an arduino clone board (freeduino), or make your own custom arduino board with this tutorial.
  2. IR  modules.
  3. L293D motor driver.
  4. Two DC geared motors.
  5. Robot chassis and wheels.
  6. Caster wheel.
  7. Breadboard and double side tape.
  8. Male to male/Female to male jumpers.
  9. 9V battery.

How it works?arduino robot tutorial

The Arduino robot reads the input from the IR modules through the analog pins. Depending on the values received from the IR module, the Arduino controls the two motors separately. Thus, making the robot turn left or right, to avoid the obstacle.

L293 MOTOR DRIVER: The driver has 2 inputs for power. Also 4 points for motor control inputs and 4 points for motor control outputs. That is, set of 2 input and 2 output for each motor. To control the motors, connect the four control points to the Arduino and the 4 output points to the motors. The 9V battery can be connected to the driver using the power input pins. The input and output, power points are indicated on the board .

IR module: IR stands for Infra Red, which is a wavelength of light not visible to the human eye (but can be seen through our smartphone cameras!). These modules consist of a pair of receiver and transmitter IR leds. When an object gets in front of the IR sensor, the surface of the object reflects a part of the IR light back to the receiver. Thus, the receiver then outputs a LOW signal notifying that an object is in front of the sensor.Raspberry Pi obstacle avoiding robot DIY Hacking

Here, this arduino robot uses two IR sensor modules which can detect objects within a range of 5-6cm. This sensor outputs a digital LOW (0V) signal when there is an object within its range. And outputs a digital HIGH (5V) signal otherwise.

Step 1: Connecting the parts for the Arduino robot tutorialarduino robot tutorial

The L293D motor driver IC is used for controlling the two motors. A motor driver is used because an Arduino can’t supply enough current required for driving a motor. Pins 2, 3, 4, 5 from Arduino go into the input of the L293D IC. Pins 2, 3 are the control signals for the right motor and 4, 5 are the control signals for the left motor. A 9V battery is connected to the L293D IC for driving the motor.

+5V and GND are given to both of the IR sensors from the Arduino. The left and right IR sensor outputs are given to the analog pins 3 and 4 of the Arduino respectively. The readings from the IR sensor will be analog values. As an obstacle obstructs the sensor, the output analog value will be digital LOW. The output from the motor driver (L293D) is given to the 2 motors as seen in the diagram.

Step 2: Checking the IR modules and DC motors

Check whether the connected IR sensors are working with the arduino. To do this, connect the IR module to the Arduino analog pins and check the values received in the serial monitor. Then find the corresponding values when an object is in front of the IR sensor. You can use this code for checking:

int value;

void setup(){

void loop(){
value = analogRead(3);
Serial.print(" Sensor Left = ");   // printing the values of both sensors into
Serial.print(value);               // serial monitor for inspection
value = analogRead(4);
Serial.print(" Sensor Right = ");

The two terminals of the motors are connected to the 4 output terminals of the board. The motors then, based on the command from the arduino are powered by the 9V battery. The logic for controlling the motors from the arduino is as given below:

Raspberry Pi robot DIY Hacking

Here, HIGH means 5V signal or digital 1 and LOW is 0V signal or digital 0. Eg: digitalWrite(5, HIGH), this command sends a HIGH signal (digital 1) to pin no 5 on the arduino. Thus each motor’s direction can be controlled by writing HIGH/LOW signals through two digital pins from the arduino.



Step 3: Uploading the code to the arduino robot

Make the connections as explained in the circuit diagram. And you can try to code on your own or use the code we made: Arduino Robot tutorial. Given here is a code that handles obstacles directly in front of the arduino robot and also the corners to some extent. It can be simplified or expanded to accommodate more possible events. In simple words, whenever one of the sensors senses a obstacle the arduino immediately commands the DC motors to stop and move in another direction. Check out this video to see our robot in action:

Upload the code and make necessary changes to it to ensure smooth operation. And that’s it, you have made your own Arduino robot. Give yourself a pat in the back and figure out what more you can do with this.

– Tutorial submitted by our STAR Interns at DIY Hacking

arduino robot tutorial

STAR Interns at DIY Hacking: Mohammed Ibrahim, Ashish Alex, Emil George, Vishnu Prakash, Akshay James

Recommended Posts
Showing 3 comments
  • susil kanti

    i cant get it right

  • priyanka

    Can you please explain programming??

  • Priyanka

    Good tutorial.
    Please specify that the supply to the Arduino board is taken from the PC through the USB cable.

Leave a Comment

8 + 2 =

Start typing and press Enter to search