Introduction: Obstacle Avoiding Robot

About: 31 years old tinker and diy hobbyist. From Oulu, Finland. IG @mkarvonen_instructables

What could be more awesome than building your own robot.

This is how to do it your self.

Banana for scale in the last picture.

For mobile users. Watch the video from here!

Find the building kit from here!

Step 1: Components.

I used my previous project's shield and ultrasound sensor in this project.

Learn how to make the Radar from HERE! The build is explained there.

The base for the whole build is an old HDD lid. It is light weight and it hold's its shape well.

The wheels are just from an old toy car.

Two servos for the wheels is needed and one servo for the radar.

And of course some kind of Arduino based board is needed. I used Intel Edison+ Arduino breakout board.

Step 2: Making a Forever Rotating Servo.

Forever rotating servo means that it will turn more than the basic 0-180 degrees.

The forever rotating servo is great for this type usage. You can change the speed by entering differed value to the servo and also you can change the direction of rotation.

First find a simple test code from the internet to set up your servo.

I used a basic potentiometer on a shield and set the servo to 90 degrees. This way it is in the middle of its original rotation and it is easiest to program. Also the rotation speed of the servo is the same in both 0 and 180 degree.

Then remove the cap from the servo and pull out the gears.

In one gear there should be a small pin that stops the servo if it is turning too much. Cut that off.

Then make absolutely sure that the potentiometer is at 90 degree position and drop a small drop of superglue on the potentiometer to jam it on its place.

Then just put all the gears back and test the workings of the servo.

Step 3:

Attach your servos to the wheels and attach the servos to the base of your robot.

I used hot glue for basically connecting everything since it is very durable and hold's tightly on its place.

Don't worry about the front wheels at this point. I will get to them later.

Step 4: Add Connectors to the Radar Shield.

If you have not checked out my RADAR project yet, i suggest to look at it now since mostly of this pit of the project is done in my previously project.

Add two simple connectors for the two servos.

A slight modification to the radar shield had to be done however. This is just for convenience of the build.

The trigger and echo pins were moved to 7 and 8 pin.

And the two servos are connected to pin 3 and 5.

The radar servo is in pin 9.

Step 5: Coding and Testing

Lift the project on to something so the wheels will be up, this just eases the coding process.

If you have any questions about the code, just ask and i will try to answer them.

Start the code by making all the needed definitions and global variables.

To change the distance when the robot stops, change the dangerThresh to something else. like 10.

The threshold is in centimeters.

#define ECHOPIN 8 #define TRIGPIN 7

const int RForward = 0; const int RBackward = 180; const int LForward = RBackward; const int LBackward = RForward; const int RNeutral = 90; const int LNeutral = 90;

const int dangerThresh = 20; int leftDistance, rightDistance; Servo panMotor; Servo leftMotor; Servo rightMotor; long duration;

Then it's time for setup.

void setup()
{ Serial.begin(115200); rightMotor.attach(5); leftMotor.attach(3); panMotor.attach(9); panMotor.write(75); pinMode(ECHOPIN, INPUT); pinMode(TRIGPIN, OUTPUT); }

And then for the main program, loop.

void loop()
{ int distanceFwd = Distance(); if (distanceFwd>dangerThresh) { leftMotor.write(LForward); rightMotor.write(RForward); } else { leftMotor.write(LNeutral); rightMotor.write(RNeutral); panMotor.write(0); delay(500); rightDistance = Distance(); delay(500); panMotor.write(150); delay(700); leftDistance = Distance(); delay(500); panMotor.write(75); delay(100); compareDistance(); } }

Then there is two subroutines.

One to compare the measured distances. This one tells the robot to go left or right, witch has more space to move.

void compareDistance()
{ if (leftDistance>rightDistance) { leftMotor.write(LBackward); rightMotor.write(RForward); delay(700); } else if (rightDistance>leftDistance) { leftMotor.write(LForward); rightMotor.write(RBackward); delay(700); } else { leftMotor.write(LForward); rightMotor.write(RBackward); delay(1000); } }

And subroutine for the distance calculation.

long Distance()
{ digitalWrite(TRIGPIN, LOW); delayMicroseconds(2); digitalWrite(TRIGPIN, HIGH); delayMicroseconds(10); digitalWrite(TRIGPIN, LOW);

float distance = pulseIn(ECHOPIN, HIGH); distance= distance/58.2; return(distance); }

Step 6: Adding Battery Pack.

The robots usage is pretty limited if it need's a cord to run, so at this point is good to make a battery pack for it.

The pack hold's six AA (LR6) battery's witch is plenty for the project. I haven't tried how long it can run.

Once again i used hot glue to hold the pack in its place.

The Edison is not hold with anything on the board. It just fits snugly on the base board so it wont need any. This means that changing the battery's is easy.

Step 7: Time for the Front Wheels.

These wheels are the same kind of wheels that are on the servos.

I used a BBQ stick to make the axle and a two pits of plastic to hold it in it's place.

Once again, Hot glue everything like there is no tomorrow.

Step 8: Done.

Now it is finally done.

I could say this is pretty easy project to do. It just takes some time to collect all the needed pits and parts.

Anyway, I hope you liked the build!

If you did, Make sure to follow me to get more projects!

Thank you for reading.

PS. Remember to watch the video ;)

On a Budget Contest

Participated in the
On a Budget Contest