How to make a simple Obstacle avoiding robot without a servo motor
Hello and welcome back. In this project, we will learn how to make a simple Obstacle-avoiding robot without a servo motor. For that, I mainly used the Arduino UNO board, Ultrasonic sensor, and L293D motor driver shield. This means you can make it easily and at a low cost. I’ve used 5mm foam board to make the robot body, but feel free to use whatever material you prefer. I think this project is perfect for school assignments.
If you are a beginner in Arduino, Please visit our basic tutorial and projects. The ultrasonic sensor is the main actor in this project. It helps us measure distances to obstacles in front of the robot. Then, based on this distance, the robot stops and turns left and right. You can change the robot stop distance as you like. Afterward, the ultrasonic sensor again checks distances on either side and decides which way to turn. Once it’s clear, the robot moves forward. This cycle repeats continuously. You can adjust the distance at which the robot stops and other timing delays based on your needs.
If you want to visit more obstacle avoidance robot projects, please use the following links.
- How to make an obstacle avoidance robot using Raspberry Pi Pico board
- How to make an obstacle avoiding robot with three ultrasonic sensors
- How to make an Obstacle avoidance and Bluetooth control robot using a robot tank kit
- How to make an Obstacle avoiding robot using a 4-way line tracking sensor module
- How to make an obstacle avoiding robot using Arduino & Ultrasonic sensor
- How to make an Obstacle avoidance robot (L298N motor driver)
- Obstacle avoidance Robot car
- How to make a cute WALL-E smart robot with Arduino step by step
OK let’s do this project step by step. The required components are given below.
- Arduino UNO board x 1 — Our Store / Amazon
- Ultrasonic sensor x 1 — Our Store / Amazon
- L293D motor driver x 1 — Our Store / Amazon
- Gear motor x 2 — Our Store / Amazon
- Robot wheel x 2 — Our Store / Amazon
- Swivel Caster Wheel — Our Store / Amazon
- Li-ion battery x 2 — Amazon
- Battery holder x 1 — Our Store / Amazon
- Jumper wires — Our Store / Amazon
- Foam board — Amazon
Step 1
Firstly, identify these components.
Step 2
Secondly, cut the foam board pieces to the following sizes.
Step 3
Thirdly, prepare the side foam board piece to mount the ultrasonic sensor. For that find the center point and prepare the area using the sensor.
Step 4
Next, prepare the part of the robot base to mount the Swivel Caster Wheel. For that, draw a circle with a radius of 14mm using the back center point of the foam board. Then, cut out this circle and install the caster wheel.
Step 5
Now, install the robot front part on the base part. Then, cut out 10mm of the left and right foam board pieces.
Step 6
Next, prepare the robot wheel mounting holds. For that, use the gear motors and mark the holes on the left and right foam board pieces. Then cut out these holes.
Step 7
Afterward, install the left and right foam board pieces on the base part. Then, glue the gear motors.
Step 8
Now, connect the L293D motor driver shield to the Arduino UNO board. Then, cut an Arduino UNO board shape foam board piece and glue it to the Arduino UNO board.
Step 9
Next, make two holes for the USB programming port and 12v power port on the robot’s backside foam board piece. Then, install the Arduino board and back side foam board piece on the robot base part.
Step 10
Now, connect the robot wheels to the gear motors.
Step 11
Afterward, connect the gear motors to the motor driver shield. Also, connect the ultrasonic sensor to the motor driver shield. For that, use the circuit diagram below.
Step 12
Now, install the ultrasonic sensor on the front of this robot. Then, connect this robot to the computer for programming.
- Next, copy and paste the following program to the Arduino IDE.
- Then, install the AFmotor library file.
- AFmotor library — Download
- Code and circuit diagram — Download
/*Obstacle avoidance robot
Home Page
*/
//Include the motor driver library
#include <AFMotor.h>
//Define the sensor pins
#define Trig A0
#define Echo A1
//Set the speed of the motors
#define Speed 160
//Create objects for the motors
AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
void setup() {
Serial.begin(9600);
//Set the Trig pins as output pins
pinMode(Trig, OUTPUT);
//Set the Echo pins as input pins
pinMode(Echo, INPUT);
//Set the speed of the motors
motor1.setSpeed(Speed);
motor2.setSpeed(Speed);
}
void loop() {
int value = distance();
// Check the distance using the IF condition
if (15 >= value) {
Stop();
Serial.println("Stop");
delay(1000);
leftSide();
int leftDis = distance();
delay(1000);
rightSide();
delay(1000);
int rightDis = distance();
delay(1000);
if (leftDis < rightDis) {
right();
delay(300);
} else {
left();
delay(300);
}
} else {
Serial.println("Forward");
forward();
}
}
//Get the sensor values
int distance() {
//pulse output
digitalWrite(Trig, LOW);
delayMicroseconds(4);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
long t = pulseIn(Echo, HIGH);//Get the pulse
int cm = t / 29 / 2; //Convert time to the distance
return cm; // Return the values from the sensor
}
//Turns left
void leftSide() {
left();
delay(300);
Stop();
}
//Turns right
void rightSide() {
right();
delay(600);
Stop();
delay(300);
left();
delay(300);
Stop();
}
/*******************Motor functions**********************/
void forward() {
motor1.run(FORWARD);
motor2.run(FORWARD);
}
void left() {
motor1.run(BACKWARD);
motor2.run(FORWARD);
}
void right() {
motor1.run(FORWARD);
motor2.run(BACKWARD);
}
void Stop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
}
- Now, select the board and port. Then, click the upload button.
- Then, check the motor rotate direction. If the motors do not rotate in the correct direction, please change the motor connections.
Step 13
Next, install the top cover of this robot. Then, mount the battery holder on the robot’s top.
Step 14
Finally, put the batteries into the battery holder. Then, connect the power adapter to the Arduino UNO board. Now you can test this robot. The full video guide is below. So, we hope to see you in the next project. Have a good day.
troubleshooting
- Check the Jumper wires.
- Check the Power source.
- Check the L293D motor driver shield power jumper.
- Check the Gear motor directions.
- Install the motor driver shield library file.
How to make a simple Obstacle avoiding robot without a servo motor