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

An Arduino-based Obstacle Avoiding Robot!

One of the simplest projects you can make for your first time using an Arduino is an obstacle avoiding robot. If you are a beginner to Arduino and want to learn more about it, this Arduino robot tutorial will teach you the basics while you build a cool robot. 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! If you are a true beginner to electronics, you can go through our free beginner’s 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 PID (proportional-integral-derivative) based algorithms. This concept has even been used in automatic vacuum cleaners like the Roomba:


Required Materials

  1. Arduino or an Arduino clone board, like 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 sided tape.
  8. Male to male/Female to male jumpers.
  9. 9V battery.

How Does it Work?
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, 4 points for motor control inputs, and 4 points for motor control outputs. That is a set of 2 inputs and 2 outputs 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 Infrared, which is a wavelength of light not visible to the human eye (but can be seen with 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, the receiver then outputs a LOW signal notifying that an object is in front of the sensor.Raspberry Pi obstacle avoiding robot DIY Hacking

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: Connect the Parts for Your Arduino Robotarduino robot tutorial

The L293D motor driver IC is used to control the two motors. A motor driver is used because an Arduino can’t supply enough current to drive the motor. Pins 2, 3, 4, and 5 on the Arduino go into the input of the L293D IC. Pins 2 and 3 are the control signals for the right motor and 4 and 5 are the control signals for the left motor. A 9V battery is connected to the L293D IC to drive 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 on 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 two motors as seen in the diagram.

Step 2: Check 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’s 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 to check the IR modules and DC motors:

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 on the motors are connected to the four output terminals on 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:

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 5 on the Arduino. Thus, each motor’s direction can be controlled by writing HIGH/LOW signals through two digital pins on the Arduino.



Step 3: Upload the Code to the Arduino Robot

Make the connections shown in the circuit diagram above. You can try making your own code or just 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 an 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’ve made your own Arduino robot! Give yourself a pat on the back and start thinking of ways you can improve your robot!

– 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 6 comments
  • Priyanshu Kumar

    Robot is not working despite following all the steps. Can you tell me why?

    • Ishat

      Connect 5V/6V battery to the bitboard to power the components. Also supply 5V/6V power to power the motor driver. Worked for me!

  • Ankit Gorai

    I use hc-sr04 sensor instead of IR modules. Can you please send me the code for that.

  • 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

21 − 15 =

Start typing and press Enter to search