Introduction: Obstacle Avoiding Robot

Picture of Obstacle Avoiding Robot

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.

Picture of 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.

Picture of 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:

Picture of

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.

Picture of 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

Picture of 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.

Picture of 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.

Picture of 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.

Picture of 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 ;)


Shubhamt948 (author)2015-09-05

Where I will write these code or with which software

mkarvonen (author)Shubhamt9482015-09-06


This should get you started,

jhumankhan (author)2015-07-08

i will try

thom.bouttier (author)2015-05-17

Hey ! This is a very nice job ! I want make the same one but your building kit link is dead. Can you fix it please ? Thank you very much :)

Fleon12 (author)2015-04-22

Thanks for giving the idea I was able to complete the robot and once again thanks for the idea of making this awesome robot.

mahnoor gul (author)2015-02-17

Is there any link other than the youtube for this vedio?

mahnoor gul (author)2015-02-17

I can't find any vedio at the given link

miragempro (author)2015-02-17

Hello, seeing this tutorial, I wonder if it would be possible, do the ultrasound rotate rotate and detect all around you? a radius of a circle, for example of a meter, he would turn and detect all approach this circle.

sb4 (author)2015-02-14

Great work. For the video, I'd prefer to hear commentary instead of shredding guitar. Why do people feel embarrassed about technical prowess, and have to make a statement "See, I'm not a nerd -- this cool music proves it"? But excellent project.

mkarvonen (author)sb42015-02-14

Hi. Thanks for commenting. The reason i don't like to talk on my videos is that i'm not comfortable with it since i'm not a native speaker. Text is much more convenient way to "communicate" in videos. And also the music is free to use. :)

FYI. I have a degree in music (bass, drums and guitar) and also i'm Electronics technician, soon to be Engineer in the same field.

We Finns just like to listen metal, bang our heads to the wall and communicate as less as possible.

sb4 (author)mkarvonen2015-02-16

I get it -- thanks for setting me straight. I apologize for sounding critical. I guess I was cranky. :) Thanks for your project! -Cheers

sontung1404 (author)2015-02-11

How do you power the board, do the Intel Edison use 5V power supply? Btw, that batteries seem to be from Finland :)

mkarvonen (author)sontung14042015-02-12

Intel Edison has a build in regulator of 5 volts. So if you use like in this project 6*1.5 Volt battery's you will get 9 Volts that is regulated to 5 Volts for the board. It can handle Volts from 0 to about 15 Volts.

Jep Jep. Patterit on halvinta lähikaupan Smarket laatua ;D

sontung1404 (author)mkarvonen2015-02-12

I have a Galileo, wonder if the Galileo also has a built-in regulator?

MagicKreator (author)sontung14042015-02-15

Soo... this works on a Galileo?

sontung1404 (author)MagicKreator2015-02-15

No, I am not sure about everthing, but about the power supply, you need an extra voltage regulator.

mkarvonen (author)sontung14042015-02-12

I cant find any information about that.

This is what the datasheet says:

Galileo is powered via an AC-to-DC adapter, connected by plugging a 2.1mm center-positive plug into the
board's power jack. The recommended output rating of the power adapter is 5V at up to 3A.

So i think that means there is no regulator on that? Here is a link to the datasheet

steinie44 (author)2015-02-15

Had to mute the video. No sound would be better.

mkarvonen (author)steinie442015-02-15

Great! The mute button is made just for you. Rest of that don't mind the music can keep audio on.

Everybody wins!

Have a nice day.

sontung1404 (author)2015-02-15

How do you connect your sensor? Do you connect it directly to your analog pin?

mkarvonen (author)sontung14042015-02-15

Hi, I use digital pins for the sensor. Pins 7 and 8.

allartssk (author)2015-02-13

you have to be careful when removing pins from a servo because some potentiometers can't go 360 degrees instead you could use a motor with a gearbox and an encoder that way you don't need to worry about modifying the servo and you ensure that it can go 360 degrees

mkarvonen (author)allartssk2015-02-14

Servos typical turning ratio is 180 degrees. No pin is removed in the servo modifying process. To use a motor with gearbox you will need a driver for that. For example this

algelman (author)2015-02-12

Would stepper motors work for the wheels?

mkarvonen (author)algelman2015-02-12

Well. That depends how you are going to use them. Wheels are the best for moving in this kind of build.

algelman (author)mkarvonen2015-02-13

What I meant was can stepper motors be used instead of the servos to power the wheels.

mkarvonen (author)algelman2015-02-14

Stepper motors can be used. But you will need more power to the board. I suggest using a stepper motor shield for this since the arduinos/edisons power supply is not enough.

bill2009 (author)2015-02-12

Very nice! I would have worried about spikes on the power. How are the servos powered?

mkarvonen (author)bill20092015-02-12

Servos are powered just with the 5V output. The servos are micro servos and don't draw too much current when in use. But the 3 servos is the max that i suggest using. Otherwise make or order a servo/motor shield.

Battery's are pretty solid and spike proof power supply.

mrveillette (author)2015-02-12

Hi! Nice build. Is the robot can avoid stairs?

mkarvonen (author)mrveillette2015-02-12

It can be programmed to avoid them. By default it can't since the ultrasound sensor looks straight ahead and not down. But it can be surely done.

dricker1 (author)2015-02-08

Off subject, but seems like you spelt "robot" wrong on your main picture.

mkarvonen (author)dricker12015-02-08

it seems like it but in reality the font just has got that kind of B letter. :D Try look at it in artistic view point.

mkarvonen (author)mkarvonen2015-02-08

don't know why. it's a downloaded font .

dricker1 (author)mkarvonen2015-02-08

I didn't know since the "B" in the word obstacle looks right.

ir jammer device (author)2015-02-08

Hello friends broke this ir jammer device this send information to the bill acceptor cant your this for me build send me one email writing me of this email

hi. Could you please write that message again. I can't really understand what you are trying to say.

egrasso (author)2015-02-07

I meant to say quick enough on that pin

mkarvonen (author)egrasso2015-02-08

Hi, The HC-SR04 has 4 pins to deal with. Vcc, Trigger, Echo and GND. The Arduino shield has worked like any other Arduino and i have had not any problems with anything so far. (check my distance bug project to see how to calibrate the sensor)

The Edison chip should be much faster than any Arduino atmel chip.

I think you might have a false information about that.

Here is an example.

If you calculate it with speed of sound, lets say the distance is about 2.5 meters. The sound takes about 15 ms to reach to the measured distance and the same time to get back. The whole process takes about 30 ms and if Arduino isn't fast enough for that, it is useless for anything.

The same goes with a three pin sensor. Just try it and you will be surprised.

Thank you for commenting!

egrasso (author)2015-02-07

Nice build I thought I read about the edison not having the ability with the arduino shield to change between input and output on one pin to use a three wire ping sensor so I haven't messed with mine

About This Instructable




Bio: I am 27 years old engineering student from Oulu in Finland. I make these projects as a hobby, and it would be fun to also ... More »
More by mkarvonen:PipBoy 3000 (working)DIY Piranha PlantPhoto(s) to 3D model
Add instructable to: