Introduction: Arduino Obstacle Avoidance Robot (NEW SCHEMATIC)

Picture of Arduino Obstacle Avoidance Robot (NEW SCHEMATIC)

Hey guys,

In this project, we will be making an obstacle avoidance robot using the Arduino Uno. This robot is designed to move around and avoid any obstacle it encounters using an ultrasonic sensor. For those who needed a schematic diagram, I have added it for visual learners.

Material:

Tools:

  • Scissors
  • Tape
  • Computer
  • Arduino Program
  • Your Hands

Optional:

  • Velcro
  • Hot-Glue Gun
  • Pliers
  • 9 Volt Battery

Step 1: Step 1: Servos

Picture of Step 1: Servos

The first step is to make sure your servos are working. For the Parallax continuous servos, use the jumper wires to connect the black wire to GND, red wire to 5V, and the white wire to digital pin 9 on the Arduino. For the Hi-Tec servo, the only difference is that the signal wire for the servo is yellow, compared the the white wire on the Parallax servo. After, just upload the sweep code that I have uploaded for you at the bottom of the page.

Are your servos working? If it does, good. If not, then go get a refund from your supplier. Now that your servos are working, it is time to center them. This will ensure that your servos are well balanced and even. I have provided you with the code file below.

After you have uploaded check to see if your servo moves. If it doesn't, don't freak out because that's good news. You're all set. If your servo does move, use a Phillips screwdriver, and slowly turn either way in the tiny slot to adjust until your servo stops moving. After you are done, you are ready for the next step. Yay!

Step 2: Step 2: Ping Sensor

Picture of Step 2: Ping Sensor

Now, you are ready to test your Ping))) sensor. First, connect the GND pin on the Ping sensor to the GND on the Arduino. Then connect 5V pin on the Ping sensor to the 5V slot on the Arduino. Lastly, connect the SIG pin on the Ping sensor to digital pin 7 on the Arduino. After that, upload the code onto the Arduino and go up to tools, and open up serial monitor. A window will open, and it will show you the sensor's distance from an object in front of it. Congrats! You are done testing the Ping))) sensor!

Step 3: Step 3: Attaching the Servos

Picture of Step 3: Attaching the Servos

This is the fun part! You will now be completing the hardware section of your project. First, you will have to assemble the Tamiya track kit. If you want, you can assemble the whole thing, but the thing you really need to assemble are the 2 tracks and the rest of the wheels. You will notice that the wheels with teeth do not have a free moving axle, but a gearbox instead. You do not need to assemble or even use the gearbox! Save the parts for other projects because we only need the 2 wheels with teeth. First, you will have to cut the plus signs that comes with your continuous servos. Just cut half way down, about 2 holes from the center, enough to fit it into the Tamiya wheels. After you are done doing it to both servos (ONLY THE CONTINUOUS ONES), hot glue the wheels the the servos. Now, place the servos with the bottoms touching each other, sides facing down, and the long part pointing out, or else your robot will run backwards. Then attach the sensor servo (180 degree servo) straight up with the long side pointing back. You can use hot glue, velcro, or tape to attach the servos down to the base (I used velcro, but anything will work). Now using the breadboard, connect the servos to the 5V port and both to a common ground (GND). Also connect the servos to the right digital pins. Then attach the battery box between the continuous and 180 servos and stick the breadboard on top of the battery box.

Step 4: Step 4: Connecting the Sensors and the Rest

Picture of Step 4: Connecting the Sensors and the Rest

Now the servos are done, Its time to connect the Ping))) sensor. First, you must attach the Ping)) sensor onto the servo. I glued 6 Styrofoam meat trays cut into squares on top of each other to make a block. You can do the same, use cardboard, or just purchase a block of foam. I do not recommend gluing the sensor directly to the block, but instead use pins, or nails to pin the sensor to the block. Then, I used tape to secure the Ping sensor onto the block. After that, I stuck the breadboard on top of the battery pack (the breadboard was really small) and the Arduino onto both of the continuous rotational servos.

Step 5: Step 5: Finishing Touches and Coding

Picture of Step 5: Finishing Touches and Coding

Yay! This is the final step! Now, connect the arduino to your computer and paste in this code into your Arduino program and install it into your Arduino (make sure you verify the code, just in case). I give credit for this code to Brandon Campbell. Check out his YouTube videos because he got some really awesome videos and tutorials (this Instructable was based on this code, and since he didn't give a tutorial I decided to give one myself).

Code: https://docs.google.com/document/d/1EULUhXL978xHmI...

After that, plug in the power pack into the smaller plug onto the Arduino, turn it on, and watch your robot go! If it does not go, feel free to ask me in the comment below, or through my email. I will try my best to reply as soon as possible and thanks for reading this Instructable! If you like this, please follow me for more fun projects like these and I will see you again!

Comments

IlhamN3 (author)2017-03-10

if i use different component (for example, different servo motor and different ultrasonic sensor) does it require different code?

ArduWeno (author)IlhamN32017-03-11

Hey,

No, it will not require a different code unless the component has different connections from the components I've been using (i.e. instead of 3 ports there are 4)

walkercreations (author)2016-07-06

Great tutorial and well written. Unfortunately on my Robot, I'm using an HC-SRO4 Sensor and am having a hard time relating that to your PingTest sketch. :(

9937058570 (author)2016-05-10

can u please tell me how can i start my roboat

nd which switch i have on

zhatan (author)2015-06-18

Hello,




I am
building an obstacle avoidance robot using the Arduino UNO board. The robot
consists of a pair of dc motors being driven using the L293D H-Bridge which has
been functioning just fine for a line tracer robot project. I have added a
HiTEC HS-422 servo motor (in parallel with a 100 micro farad decoupling
capacitor) for the distance measurement part to be able to rotate the ping
sensor to the left (~10 degrees) and right (~170 degrees).



Both DC
motors and the servo have their own dedicated power source not to overload the
Arduino power output and their grounds are connected to the common ground with
the Arduino board (reported as a common mistake).



DC motors
and the servo work just fine on their own as the robot goes forward and
backward and turns right and left and servo passes the sweep test and moves
nicely to any predefined angle. As I try to run the DC motors and the servo
together, the servo turns to almost 0 degree and kind of twitches around 0
degree regardless of the predefined angle such as 90 or 170 degrees. I have
tried the following scenarios and the following code for wiring the H-Bridge to
overcome the problem but had no success:

First
scenario
:

Controlling the speed of the DC motors with a potentiometer
and analogWrite(right_mot_Enable_Pin,Motor_Speed):

L293D-pin-1 connected to Arduino-pin- ~6

L293D-pin-2 connected to Arduino-pin- 8

L293D-pin-3 connected to left motor

L293D-pin-4 connected to common ground

L293D-pin-5 connected to common ground

L293D-pin-6 connected to left motor

L293D-pin-7 connected to Arduino-pin- ~10

L293D-pin-8 connected to + 9 V Battery

L293D-pin-9 connected to Arduino-pin- ~3

L293D-pin-10 connected to Arduino-pin- ~5

L293D-pin-11 connected to right motor

L293D-pin-12 connected to common ground

L293D-pin-13 connected to common ground

L293D-pin-14 connected to right motor

L293D-pin-15 connected to Arduino-pin- ~9

L293D-pin-16 connected to +5 V from Arduino

Servo-signal-pin connected to Arduino-pin- ~11

Second
scenario
:

No speed control on the DC motors:

L293D-pin-1 connected to +5 V from Arduino

L293D-pin-2 connected to Arduino-pin- ~5

L293D-pin-3 connected to left motor

L293D-pin-4 connected to common ground

L293D-pin-5 connected to common ground

L293D-pin-6 connected to left motor

L293D-pin-7 connected to Arduino-pin- ~6

L293D-pin-8 connected to + 9 V Battery

L293D-pin-9 connected to +5 V from Arduino

L293D-pin-10 connected to Arduino-pin- 8

L293D-pin-11 connected to right motor

L293D-pin-12 connected to common ground

L293D-pin-13 connected to common ground

L293D-pin-14 connected to right motor

L293D-pin-15 connected to Arduino-pin- ~9

L293D-pin-16 connected to +5 V from Arduino

Servo-signal-pin connected to Arduino-pin- 4

#include <Servo.h>

Servo myservo;

int Motor_Speed = 0;

const int left_mot_forward_Pin = 8; // Left Motor connected to digital pin 8

const int left_mot_backward_Pin = 10; // left Motor connected to digital pin 10

const int right_mot_forward_Pin = 9; // right Motor connected to digital pin 9

const int right_mot_backward_Pin = 5; // right Motor connected to digital pin 5

const int left_mot_Enable_Pin = 6; // Left Motor Enable Pin

const int right_mot_Enable_Pin = 3; // Right Motor Enable Pin

const int Pot_Pin = A3;
// Pot Pin

void setup()

{

Serial.begin(9600);

Motor_Speed = map(analogRead(Pot_Pin), 0, 1023, 0, 255);

myservo.attach(11); //
attaches the servo on pin 11 to the servo object

pinMode(left_mot_forward_Pin, OUTPUT); // Left Motor

pinMode(left_mot_backward_Pin, OUTPUT); // Left Motor

pinMode(right_mot_forward_Pin, OUTPUT); // Right Motor

pinMode(right_mot_backward_Pin, OUTPUT); // Right Motor

}

void loop()

{

myservo.write(90);
//Rotate the servo to face the front

moveForward();

}

void moveForward() //This function tells the robot to go
forward

{


digitalWrite(right_mot_forward_Pin, HIGH); //Right Motor Forward


digitalWrite(right_mot_backward_Pin, LOW); //Right Motor Backward


analogWrite(right_mot_Enable_Pin,Motor_Speed);


digitalWrite(left_mot_forward_Pin, HIGH); //Left Motor Forward


digitalWrite(left_mot_backward_Pin, LOW); //Left Motor Backward

analogWrite(left_mot_Enable_Pin,Motor_Speed);

}

NasirN1 (author)zhatan2016-01-02

hello,

I am building the same robot as yours but unfortunately I dont have much knowledge about how to use servo so can you please send me the code with little guidance about using servos thanks in advance

13bemennasir@smme.edu.pk

ArduWeno (author)NasirN12016-01-03

Hi,

Here is the link to the code of the entire robot if it is what you're asking for:

https://docs.google.com/document/d/1EULUhXL978xHmIlP4cErjugKC0JFe9WlI5DHhfoc7zo/edit?pli=1

So a servo is a little like a regular dc motor except that servos are easier to program with a microcontroller. That is one of the biggest differences of it. They usually come in micro, standard and giant size.

Servos usually have a 180 degree freedom of rotation but there are also fully rotating 360 degree freedom of rotation servos out on the market, like the Parallax Continuous servo motor, which I used 2 on my Obstacle Avoidance Robot.

The servo that I used on the robot all came with three connecting wires, but other types may come with 4 connecting wires. The three main connecting wires are GND (ground), 5V (power), and SIG (signal from microcontroller). GND wires are usually colored black. 5V wires are usually colored red, and SIG wires can come in white or yellow depending on the brand.

5V usually connects with the 5V pins on microcontrollers. GND usually connects to GND on microcontrollers, and SIG usually connect with the numbered output pins, usually digital.

Hoped that helped!

NasirN1 (author)ArduWeno2016-01-03

Thanks a lot it was very helpfull I just wanted to know that it is necessary to use a potentiometer with servo motor ?

NasirN1 (author)NasirN12016-01-03

plus the code you gave me uses two servos, intstead if I use on servo will it be feasible ?

shafayatjamil.alamin (author)2015-02-27

I use arduino uno and servo motor with 180 degree rotation and ultrasonic sensor.Can I please get the arduino code for my obstacle avoider robot. my email- shafayatalamin@gmail.com

hi bro I am using the same servo as yours in obstacle avoider so can you please send me the code, thanks alot in advance

13bemennasir@smme.edu.pk

Hi,

The code is located on step five, but I realized that there is a problem with some of the code links, so I will fix that. Thanks for telling me, and I will send the code to you. Your robot looks very nice, but the 180 degree standard servo is for the rotating Ping))) sensor, not the wheels.

eset01 (author)ArduWeno2015-03-08

hi sir.. we have a project for this can you send me the code.. vienielvie@gmail.com

toaster_me (author)ArduWeno2015-02-27

hi can u send me the code please :-) pakcikteds@gmail.com

tqvm!!

LucasP29 (author)2015-11-08

We had some... problems

1. Your code didn't work very well. It kept saying it had trouble defining the servos when we tried to verify. Still trying.

w

rene9900. (author)2015-10-01

Any chance of some tips on how to make this with the stuff i have already? got 2 dc gear motors and pan tilt with servos, id like to know how to change the code to use dc motors and 2 servos for the scanning.

im using motorshield on a uno r3
http://www.ebay.com/itm/221605183415?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

thanks in advance.

Michael AngeloM1 (author)2015-08-03

If it is okay to you, may I see your schematic diagram. Thanks :) email me gelomikmik@gmail.com

Gcappelli (author)2015-07-19

Can I get a diagram of where the servos connect to the breadboard and arduino or u could send it to gabec.cappelli@gmail.com

ZakD (author)2015-06-11

Would a 4-pin distance sensor work with the provided code?

ArduWeno (author)ZakD2015-06-12

Hi ZakD,

I am not sure about it, however I think it may work but don't take my word for it.

srijan.sharma.1447 (author)2015-04-02

hello ,... can u please upload a schematic diagram (circuit diagram) ,... or send me to my email id - srijansachittanand@gmail.com .. thanks .,,. please tell me more about the servos , arduino, (which kind or version of arduino uno, servos i should purchase ??? ) thank you ...

eset01 (author)2015-03-08

hi sir.. we have a project for this can you send me the code.. vienielvie@gmail.com

master.s.blader (author)2015-01-31

can u provide the schematic diagram

Benjamin1212 (author)2015-01-27

that would be nice to have a diagram

allen.andres.92 (author)2014-12-08

Can you provide the schematic diagram of this project ? Thanks.

ArduWeno (author)allen.andres.922014-12-08

Hey Allan,

The schematic diagram isn't necessary because the 3 servo pin numbers you can find in the code, and they just connect to GND and 5V, same with Ping sensor. However, if you really need the diagram, I can provide one for you.

MsSweetSatisfaction (author)2014-11-18

Woah this is really cool! I just wish there were some in progress pics to go with the awesome project.

Thanks for enjoying this project! I have just uploaded some pictures to go with the process, so it should make the process easier and enjoyable.

About This Instructable

70,077views

42favorites

More by ArduWeno:Arduino ConnectionsArduino Obstacle Avoidance Robot (NEW SCHEMATIC)
Add instructable to: