Introduction: Obstacle Avoiding Robot

A robot is a machine capable of carrying out a complex series of actions automatically, especially one programmable by a computer. We usually think that a typical robot has sensors,servos, complex codes just like in the fiction movies of I,Robot. But that is not true. A robot can be a simple code to hack websites and send data to the hacker.

I was inspired by driver-less cars that are taking the streets. Not only do they avoid obstacles, but also reach their destination while follow traffic rules. Such robots require complex programming and fast and accurate connection with the physical world.

This instructable will teach you how to build an autonomous robot that moves on 2 wheels and avoids any obstacle in its path by changing its direction of motion. It keeps turning as long as the obstruction is there and keeps on moving without any aim or specific destination point.

The robot uses Arduino UNO (ATmega328 micro controller) as its brain to analyze data from the ultrasonic sensor, which act like its eyes, to sense its surroundings and control the movement accordingly. The 8000 RPM motors act like its legs that help in movement.

You will need mere wood working skills, cardboard cutting skills and basic arduino experience and soldering skills for this project.

MATERIALS REQUIRED:

You can search HobbyKing to buy the parts.

I bought all the parts from VegaKitand Simple Labsand from a local hobby store.

Hardware:

  • 4mm thick wood (11.5cm x 14cm) x1
  • U-Shaped clamp x1
  • L-Shaped clamps x4
  • Gears (1 cm diameter) with 0.5 diameter teeth ring at center (Refer to the pictures for exact shape) x8
  • Pinion x2
  • Motor holder for your motors x2
  • Axles ( 4 cm) x4
  • Castor Ball x1
  • Plastic Stoppers x8
  • Nuts and bolts (size depends upon the size holes in your clamps and hex-rods)

Electronic parts:

  • 8000 RPM, 9V DC Motor x2
  • Arduino UNO x1
  • Jumpers (male and female, 6 cm)
  • Screw Terminal Wing Boards x2

Tools:

  • Wire Cutter
  • Pair of scissors
  • Hot glue gun
  • Drilling Machine
  • Screw Driver
  • Spanner
  • Solder wire and Soldering Iron.

Others:

  • Computer
  • USB cable to connect Arduino to computer

Step 1: Build the Base

You will need wood piece, cardboard and a drilling machine, a pair of scissors to proceed with this step.

  • Cut a rectangular section in the wood piece. Length and Width of the rectangle is 4 cm x 0.6 cm. The location of the holes is given in the pictures.
  • Drill holes. Their location is also given in the pictures.
  • Now you can reshape the front and back portions of the robot as you want. It is not necessary. But it length should not decrease by more than 1.5 cm.
  • Then, cut 2 pieces of cardboard of dimensions 5 cm x 4 cm. Ignore the holes as given in the pictures.
  • Stick them together and then, fit them inside the rectangular section you cut earlier in the wood. Use hot glue.

You can even use plastic sheets or aluminium sheets instead of cardboard. Cardboard, in this case, is used as it is easily available and is significantly light in weight.

Step 2: Make the Sensor Holder

You will need cardboard, ultrasonic sensor, pins and a pair of scissors, pins ant tape for this step.

  • Cut a cardboard piece of dimensions 4 cm x 3 cm.
  • Insert each pin through each hole present at the 4 corners of your ultrasonic sensor.
  • Insert the remaining part of each pin into each corner of the cardboard piece.
  • Bend the protruding pins at 90 degrees in order to stop them from coming out.
  • Cover everything with tape to make the grip stronger and to avoid injuries.
  • Cut a part of cardboard adjacent to the pins of the ultrasonic sensor.

Ultrasonic sensor sends an impulse of sound wave which gets reflected back after hitting a surface. The receiver, lying adjacent to the impulse sender receives those waves and sends data back according to the time difference between send time and receiving time.

So, Make sure that the sensor and the ground are parallel. If this is not so, the sensor may not receive the ultrasound pulse it sends and so, will not be able to detect any obstruction.

Step 3: Complete the Body

You will need all the remaining parts to complete this step.

Please ignore the 4 x 1.5 V DC cells and the battery holder shown in the pictures. Use the 9V DC supply. I supplied 6 V earlier and found that it is insufficient. The motors were running too slow on that power supply.

Make the Gearbox:

  • Screw the 4 L-Shaped Clamps in position as shown in the pictures.
  • Pass the axles halfway and do not pass them through the other hole.
  • Insert stopper and the wheel in the hind axle.
  • Insert the final driver gear first.
  • Next, Insert the intermediate transmission gears. Refer to the pictures for exact gear arrangement (The green and red gear).
  • Now, pass the axle to which, the wheel is connected through the other wheel after placing the second stopper in the right position.
  • Insert the driver gear, the stopper in the front axle and pass the axle through the other hole.
  • Place the stopper in the right position.

Complete the remaining body:

  • Screw the U-shaped clamp, the motor holder and the hex-rods.
  • Place the motor in their holders.
  • Attach the pinions to the motor shafts.
  • Insert the switch in its place.
  • The hex-rods are the Arduino Board's supporters. Screw the Arduino board on the rods.
  • Insert the Castor ball in the front hole.

Step 4: Upload the Code

This is the code you need to upload to the Arduino UNO Board.

const int trig=10, echo=11, pos=12, m1p=1, m1n=2, m2p=3, m2n=4;
int x=0;
void setup()
{
  pinMode(trig, OUTPUT); 
  pinMode(echo, INPUT);
  pinMode(pos, OUTPUT);
  digitalWrite(pos, HIGH);
  pinMode(m1p, OUTPUT);
  pinMode(m1n, OUTPUT);
  pinMode(m2p, OUTPUT);
  pinMode(m2n, OUTPUT);
}
void loop()
{
  long cm;
  cm=sense();
  if(cm<=10)
  {
    while(cm<=10)           //this loop will keep turning the robot while there is an obstruction
    {
      
  digitalWrite(m1p, HIGH); // to
  digitalWrite(m1n, LOW);  //   turn
  digitalWrite(m2p, LOW);  //       the
  digitalWrite(m2n, HIGH); //          robot
  cm=sense();
    }
  }  
  else
  {
    fd();
  }
}
void fd()
{
  digitalWrite(m2p, HIGH);
  digitalWrite(m2n, LOW);
  digitalWrite(m1p, HIGH);
  digitalWrite(m1n, LOW);
}
long sense()
{
  long duration, cm;
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);        // send the ultrasonic pulse
  delayMicroseconds(5);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);  // store the reading
  cm=duration/29/2;                // converting the reading into centimeters
  return cm;
}<br>

Now, you must be wanting to know what does the code really do?

  • First, the robot senses and manipulates sensor data to get the distance between the obstruction and the robot.
  • If the distance is greater than 10 cm, it moves forward.
  • If not, the robot turns. While it is turning, it still senses and when the favorable distance between the obstruction and the robot, i.e., greater than 10 cm, is found, the robot again starts to move forward.

You can refer to the Arduino website: Arduino - Home to solve any troubleshooting problems.

A common error is : avrdude stk500_getsync(): not in sync resp=0x30

This is due to mismatching COM port or driver is not installed/updated.

Sometimes, removing all loads/connections to the Arduino Board pins and then uploading the code as well as re-connecting the Arduino to the computer solves the problem.

Step 5: Do the Wiring

The connections are as follows:

Ultrasonic sensor:

  • Vcc - pin 12
  • Trig - pin 10
  • Echo - pin 11
  • Gnd - GND pin

Left Motor: pin 1 and pin 2.

Right Motor: pin 3 and pin 4.

9V DC connector Positive to the switch and switch to the power supply pin of Arduino Board.

Negative to the respective GND pin of the Arduino Board.

If your wire are longer than required, you can wind them around the U-shaped Clamp to avoid cutting.

Do soldering wherever required.

Step 6: Almost Done!

Now, you just have to turn the switch on and watch it go!

Comments

author
EdwardL8 (author)2015-11-25

Question I have is: Are you powering the motors straight from the Arduino board? Are you not required to run the motors through a motor shield or L293D driver chip?

author
SVR8 (author)EdwardL82015-11-26

Oh yes. You are right.
I didn't do enough research.

author
EdwardL8 (author)SVR82015-12-01

Although you haven't used a driver chip or motor shield, does it work? because adding the shield or driver chip is not that difficult,,,

author
SVR8 (author)EdwardL82015-12-01

Yes it works. This is why I did not notice any fault.

author
SVR8 (author)EdwardL82015-12-01

Yes it works. This is why I did not notice any fault.

author
seamster (author)2014-12-30

Great robot! Very nicely done!

author
SVR8 (author)seamster2014-12-30

Thanks!

About This Instructable

3,016views

60favorites

License:

Bio: I'm a school student who aspires to pursue robotics. I love working on DIY projects and am learning programming and algorithms.
More by SVR8:Virtual 3D ImagingObstacle Avoiding RobotRC TANK with HIGH TORQUE
Add instructable to: