Introduction: Arduino-based Robot With IR Radar

The robot prototype in this Instructable is my second Arduino-based "slumbot" which is an autonomous robot. It's attached together with household items and scraps. The robot "sees" with an IR scanning sensor rotated by a servo. It looks left, forward, and right for obstacles and distances then decides where to go.

The code name for the robot is Faz3a-X. Faz'ah is slang for a sudden collective fit of rage and lunacy :)

After reflecting on my design themes for this and my other robot, words such as junkyard and Mad Max come to mind.

So let's get started.

MAIN PARTS
- Arduino UNO: $28
- Turnigy TG9e servos (2 modified for continuous rotation): $2 each = $6
- Sharp IR sensor GP2Y0A2 for about $14
- Arduino prototyping shield is optional. You can use a mini breadboard: $15
- 9V battery and pack $3
- 6V Alkaline or 4.8V NiMh 4 X AA batteries and pack $4
- 10uF cap for IR sensor: $0.2
- 0.01uF ceramic caps for for servos X 3 = $0.30

TOTAL: about $70 (in Jordan, expect to pay almost double after shipping, handling, tariffs, taxes, clearance fees)

PLATFORM
- External 3.5" USB hard drive enclosure
- Table leg slider pin (caster)
- Toy car wheels X 2
- Construction set parts for wheels axle and servo mount

TOOLS
- Velcro (what a great invention for prototyping)
- Paper binders/clips
- Rubber bands to give plastic wheels traction
- Stapler to staple rubber bands
- Glue
- Tape, single and double sided
- Wires

WHAT'S NEXT
Next phase of this prototype will involve refining the attached Sketch for better radar/movement coordination and finer obstacle detection instead of the simplistic Right, Front, Left scanning algorithm used here.

Also, the robot platform needs to go on a diet to shed a few ounces but to do it with household items or office supplies. As in my previous robot project, in which I used Arduino to control a cheap toy car, I try to make sure as much of the robot as possible is made up of readily available items in Jordan considering commercial robot parts are nonexistent in local markets and the tariffs and taxes (corruption money) and shipping costs would discourage most Jordanian Makers from pursuing their robot projects.


Step 1: The Robot IR Radar Module

I made use of the plastic cover of a MiniDV tape as a mount for the Sharp IR radar. I used a drill pit to make the screw holes, and sand paper to taper the edges of the plastic cover. It's a rough job but it works.

The servo spins the IR sensor left, forward, and right and reads distance in each direction. In this project, the robot will turn in the direction where there's more space.

I used construction set parts to create a mount for the sensor and servo.

In the video below, I test the IR radar scanner connected to the Arduino and rotated by a TG9e micro servo. It's sending back distances for each direction.

With a piece of Velcro attached to the bottom of the mount, using glue, I can affix the whole radar mechanism on the robot platform and change its position with little hassle.



Step 2: The Robot Platform

The aluminum external USB drive enclosure had the added benefit of the cavity which allowed me to tuck wires in. While making this robot prototype, I was not ready to trim any wires until I was done affixing all parts to the platform.

For the robot caster, I used a furniture leg glider/slider pin. I glued a piece of IC shipping foam/sponge to the bottom of the USB enclosure and just stuck the glider pin into it. Works great on smooth surfaces like my marble floor. I considered round drawer handles and even deodorant roll on sticks as casters.

To hold the various robot components on top of the platform, I covered it with pieces of Velcro using double sided tape. For this sort of prototyping, Velcro and double sided tape are useful.

Then, I wrapped the two battery packs(9V and 4xAA) with Velcro. I taped a small Velcro piece on the bottom of the Arduino Uno and the IR servo mount.

Now, everything can be affixed to the platform surface. Best of all, I can rearrange the parts with little effort.

Step 3: The Robot Wheels

I had to modify two TG9e servos for 360 rotation. For that, I followed the instructions of Nicolas “ndupont” Dupont. I discovered his page after I destroyed two TG9e servos while trying to do the impossible: squeezing two resistors inside a very compact servo case. For those who attempted to do this, you know what I mean. The TG9e case is too tight to accommodate standard resistors, unless you are highly skilled or use smd resistors.

These servos are good for disposable use since they are cheap but they emitted so much noise to the point my IR sensor was giving erratic readings even with decoupling capacitor. So I ended up powering the servos separately then I added decoupling capacitors to each servo between VCC and GND, same for the IR sensor.

As for the wheels, I pulled them off a toy car, then I retooled their axle hole with my dependable drill pits and screwd them onto the servos. With the help of rubber bands, they got traction. Without the rubber bands, sometimes the robot would skid during turns on smooth surfaces such as marble.

To hook up the servos to the platform, I used construction set parts with the help of electric tape. I did not wish to make any permanent attachments to this platform yet. So the tape did a good job of holding the axle to the wheels. And with the help of two paper binder, I attached the axle to the USB enclosure.

Step 4: Integrating the Robot Brain With the Platform

This is the fun part (after hours of frustrating trials). I assembled the parts, without the robot platform, and tested the connections. After a few wiring adjustments and Sketch debug routines, it worked.

Then came the hard part: coding the Arduino to control the 3 servos and the IR sensor.

NOTE: I started the tests with one 9V (6 X AA) power source but decided to separate power to Arduino/IR from a 9V while powering the 3 servos from a 6V (4 X AA) or 4.8V if using 4 AA NiMh. The noise generated from the servos was throwing off the IR sensor readings and based on the experiences of others, it's better to separate the power sources.

In this video, I am testing the fully assembled robot in the lab to ensure wheels are reacting correctly to information from the IR radar. Of course this only tests the accuracy of the wheel spin directions. Without wheel traction, it's not possible to know how long the wheels need to spin to make a good turn. This data can be measured only when you test the robot on the target surface. In my case, marble floor.


Step 5: The Sketch Code to Run the Robot

After so much trial and error and research...

THE ARDUINO SKETCH CODE

This beta code drives the Arduino-based servo-driven sweeping IR radar to perform obstacle avoidance and servo control.

Latest Version: Beta 0.8 Oct 22, 2011

This code was written to be as self-documenting as possible. I used verbose and expanded syntax instead of compact code to make it easier to understand and to port to other programming languages. With the exception of the IR reading code, this Sketch was not copied from any project but I benefited from the collective experience of many others. Anyone can use and modify this code with attribution.

This robot moves using differential steering. To make it turn, one wheel must move faster than the other in same or opposite direction for a period of time. I used trial and error to find this time value. it will be different for your own robot.

These time values depend on many factors such as wheel size, robot weight, surface qualities, traction, etc. It's best to test your robot on the target surface (eg sumo disc, marble floor) to arrive at working values so you don't have to change them later.

NOTE: To stop the servos, I simply "detach" them in the program then "attache" them when I need them to move again. This was better than the headache of trying to figure out the stop point of each servo I modified for continuous rotation.

The pseudo logic works as follows:

SETUP
Setup environmental and physical constants such as timing of wheel spins, safe distance to obstacle, etc;
Start robot;
Scan Left, Forward, Right;
Move in direction of greater space;

LOOP
Keep moving Forward while scanning ahead;
IF Obstacle reached THEN Stop and scan in All directions (Left, Forward, Right)
Move in direction of greater space;
IF Obstacles found on All directions THEN Backturn 360 degrees then scan in All directions agin (Left, Forward, Right)
IF Obstacle found in all directions THEN STOP;
REPEAT LOOP

That's it.

On the logical level, I have 3 main section of the Sketch code:

1) Setting up constants, physical and environmental variables.
2) Logic to turn IR servo and read distances and obstacle warning.
3) Logic to turn wheel servos forward, left, right, 360, and simply reverse.

Again, this is beta code but it works.

Here's another video recording, but poorer quality (taken with Nokia 5800 camera)

Comments

author
ysami made it! (author)2015-04-02

Hello I would like to have the source code if possible thank you

author
infanati made it! (author)2014-05-02

total noob here. I've been trying to figure out the code you posted, but it's all just one big paragraph. Could you please repost the code in an arduino file.

thanks

author
ahassan18 made it! (author)2012-07-29

where is the code?? i need the code !!!

author
ricojones made it! (author)2012-07-01

is it posible for me to have code for this prototype?

author
filip10 made it! (author)2012-02-01

can I use a sharp GP2Y0D810Z0F 10cm sensor for this robot ?

author
techbitar made it! (author)techbitar2012-02-14

I see no reason why not. there might be some design considerations. best thing to do is to compare specs of datasheets if the only difference is the distance that this could be a plug and play process so to speak.

author
Higgs Boson made it! (author)2011-12-16

did you need to make a H bridge to get one of the motors to run backwards when it turned, or did one just remain stationary while the other ran when it turned?

author
techbitar made it! (author)techbitar2011-12-17

I did not use motors. I used servos which I modified for continuous rotation. I can then rotate the servos clockwise or counter clockwise. So no h-bridge was used. An Arduino can power and drive a servo directly.

http://www.arduino.cc/en/Reference/Servo

author
Higgs Boson made it! (author)Higgs Boson2011-12-17

Okay. Thank you.

author
techbitar made it! (author)techbitar2011-12-17

Opps! I forgot the other part of your question. To make a turn, I use differential steering techniques. Basically, differential steering means spinning each of the two wheels at different speed/direction/duration to achieve a desired turn angle. There are many factors that determine speed/direction/duration values for each wheel such as wheel material, floor material, wheel size, etc I had to wrap rubber bands around the cheap plastic wheels to give my robot better traction which also meant I had to adjust my values for spin speed/direction/duration. If I moved the robot to a shallow carpet, I would have had to adjust those values again. That's because my code is very basic and does not calibrate the wheels automatically for any change in traction. It would have been overkill for this project.

author
aefields made it! (author)2011-11-08

Proper terminology is important. I'm searching for RADAR. Infrared is not radar. It is LiDAR. Please fix your title so others aren't misdirected.

author
techbitar made it! (author)techbitar2011-11-09

Thanks for the note. Both uses of the word are correct.

Radar is a mechanism of object detection using electromagnetic waves. IR is just a band along the spectrum of electromagnetic waves, along with visible light. So radar is all encompassing.

http://en.wikipedia.org/wiki/Radar
http://dspace.mit.edu/bitstream/handle/1721.1/4145/RLE-TR-610-36353301.pdf

LiDAR is commonly used with laser detection but also includes ultraviolet, visible, or near infrared, all of which are electromagnetic waves.

http://en.wikipedia.org/wiki/LIDAR

About This Instructable

42,544views

53favorites

License:

Bio: Did I unplug the solder iron?
More by techbitar:IR Remote Control Station for Android - TURN THE TV DOWNSensoDuino: Turn Your Android Phone into a Wireless Sensors Hub for ArduinoModify The HC-05 Bluetooth Module Defaults Using AT Commands
Add instructable to: