Maker Pro
Arduino

How to Make a Beginner's Robot Using Arduino

September 02, 2015 by Ashish Alex
Share
banner

Learn how to interface DC motors, IR sensors, and motor drivers with an Arduino to make an obstacle-avoiding robot.

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 also showing you how to make a robot. This project will give you a clear idea on how to interface DC motors, IR sensors, and motor drivers with an Arduino. 

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:

How Does the Arduino Robot Work?

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.

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.

Connecting the Parts for Your Arduino Robot

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.

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'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(){
Serial.begin(9600);
}

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 = ");
Serial.println(value);
delay(100);
}
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.

Uploading the Code to the Arduino Robot

Make the connections shown in the circuit diagram above. 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! 

Related Content

Comments


You May Also Like