Objective: To create from scratch a working robot that is able to avoid walls and obstacles. Ever wanted to make a robot that could actually do something, but never had the time or knowledge to do it? Fear no more, this instructable is just for you! I will show you step by step how to make all the necessary parts, and programs to get your very own robot up and running. I was first inspired to build a robot when I was ten, and saw Lost in Space, with that famous B-9 robot, I wanted one! Well six years later I finally built a working robot, its name- Walbot of course!
Now is a good time to order and collect some of the things you will need for this project. The "brain" of Walbot is a Microcontroller by Atmel called the Atmega168, it is very fast, easy to use and cheap, so that is what I will be using in this project. If you prefer to use PIC, or other Microcontrollers thats fine, however I can't help you out with the code then! Since I did not feel like wasting my time building a prototyping board for the Atmega168, I bought the USB Arduino; it is very easy to use, supports USB, has the boot-loader already burned in, quite cheap, and has free programming software that is similar to C++. Well enough of that talk, let's get on with what you will need! note: these are only the prices I found from a quick search, if you look harder you probably will find better prices somewhere else, also the DIgiKey links might be broken or timed out, just search for the part description and whatever price matches the one listed here.
Tools these are the suggested tools to have for this project, you could either buy borrow or use something else you have for the same purpose. Bandsaw for cutting the Lexan base and various parts. Drill Press for drilling straight holes in Lexan base. Tap and Die set for tapping holes in the Lexan base. Good soldering iron for soldering various parts on the robot. Digital Multimeter for debugging electrical components. Wire strippers Needle-nose pliers for gripping and crimping
Alright, now that you have gathered all the necessary parts required to build Walbot it's time to get started. First of all, I must warn you that the use of various power tools will be necessary, I will not go into the proper use of operating them safely as I assume you already know how to do this; I take no responsibility for any stupid mistakes, like cutting off your finger on the bandsaw, that you make. You have been warned! To start off, I have done most of the work for you! YAY. That would include a couple months of resaerch and design for this project, which should be done for any robot you plan to build your self after this. I made a scale 3D model of Walbot in a free program called SketchUp by Google (thank you Google), you can download my model of walbot from Google 3D warehouse here (note: there might be some differences in the motor type and some of the components are missing like the circuit shield on top of the Arduino, wires... I will update the model when I have time).
Step 1: Download the Word document of the cutting and drilling guide here, and print it out. Once it is printed make sure that it is 6" wide by 5.5" long. Now cut off the extra bottom half of unprinted on paper so that you have a template thats about 8 1/2" by 6", and using some kind of adhesive or semipermanent glue or double stick tape, mount both the templates on the Lexan sheet.
Step 2: Cut out the Lexan base with the bandsaw, following the template line as closely as possible. To make it easier, cut little relief slit along the perimeter to free up the area you are working on without having to worry about the blade binding up. When your finished, you can use some sand paper to smooth out the edges if your cuts did'nt come out perfect.
Step 3: Over at the drill press, use a #29 drill to make the holes for the 8-32 standoffs, and a #43 drill to make the holes for the 4-40 screw size motor bearing blocks and standoffs for the Arduino. When drilling be sure to use a little WD-40 or water as a lubricant to keep the polycarbonate (Lexan) cool.
Optional: it is not on the template, but to make things neater, if you have a large 1" forstner bit or other big drill bit, it is useful to drill a hole right where the two lines cross on the TOP layer. This allows an area to channel wires from the top layer to the bottom layer. I did it on mine and that is what you will see in the picture, but it is not necessary.
Step 4: Using the 4-40 tap you bought in the set, carefully tap the holes that you drilled with the #43 drill. Then using the 8-32 tap do the same for the 3 holes you drilled for the standoffs with the #29 drill. If you do not know how to thread materials with a tap, learn how to here. I use a cordless drill, but it is not recommended if you are just a beginner.
Step 5: Using goo gone or other adhesive remover, remove the drilling and cutting templates and wash the lexan free of all fingerprints and grease.
560x419 : FTA7T4PF36FEUNS (2)
DON'T drill this it is not a hole, just where the half ping pong ball caster will go
Now it is time to put together the robot, using the stuff we bought earlier and the bases you made last step.
Step 1: Screw the 8-32 one inch standoffs onto the 3 holes that you drilled and threaded. In the picture I temporarily put caps on the ends of the standoffs because they are too long, but I recommend that you cut them off with like a Dremel tool.
Step 2: Place the top Lexan base on the standoffs, and using the 8-32 screws you got, attach the top to the standoffs. Note: trying to thread metal screws into plastic can be hard, to make it easier, rub a little paraffin (candle) wax on the threads and they should go in smoothly.
Step 3: Now would be a good time to solder leads and capacitors to the motors, go here to find out how to solder capacitors to the motors.
Step 4: Attach the bearing blocks to the motors using the 2-56 screws you got. Make sure to use the 2 horizontal holes so that the wheels will be aligned parallel to each other (if you put the screws vertically the gearhead can wiggle back and forth just a little bit, but enough that it could make it not go straight).
Step 5: There should be enough room to stand the bearing blocks up vertically and slide/wiggle them into place between the top and bottom layers. Now mount them in place by inserting and screwing in all the 4-40 cap screws into their respective holes.
Step 6: Now take the LV-MAX Sonar module and solder 4 wires onto it, through the AN, RX, +5, and GND holes. Now find or make a 90 degree mounting bracket for it. I used a leftover piece of Lexan, cut a strip 1" by 2", heated it in a little oven until it was pliable and bent a 90 degree angle in the middle. Then you can either drill some more holes in the bracket, corresponding to the mounting holes in the Sonar module, to mount it; or you can just use some double sided sticky foam; or use Velcro to mount it to the bracket, and the bracket to the robot base.
Step 7: For my Walbot I used old Cpasella wheels and had custom hubs made for them on a lathe. So that means if you get the wheels and hubs from the parts list, your robot will look a little different. If you can find/make lighter wheels with a 3mm bore, I encourage you to do so. Anyway, take the wheel and mount the hub to it with the screws they provide, and then attach that to the 3mm motor shaft using superglue or epoxy.
Step 8: Mount the Arduino board to the top base using the 4-40 screws. If you can get some short 4-40 standoffs that would be best to use, if not just use some washers or a small straw section to raise it off the top base a few millimeters.
Step 9: Attach the 9Volt battery and 2 AA battery holders to their respective places using Velcro. I use Velcro because it is strong yet still allows you to remove them when they need to charge up. The 9Volt should be mounted on the top level in front of the Arduino. The 2 AA battery holders should go behind the motors ( just look at the 3D model in SketchUp to see where everything goes). A quick note on the batteries, make sure that you use 1.2volt AA rechargeable cells (most rechargeable NiMH are 1.2V), if you use standard 1.5volt alkalies that could dammage the motors because they are not rated for 9 volts (6batteries * 1.5 volts =9 where as 6*1.2= 7.2 volts)
Step 10: Time to add the "third wheel" AKA caster AKA half of a ping pong ball or other slick-surfaced sphere thats about the same size as a ping pong ball. Take either of the two things mentioned above and split it in two, you can use your favorite splitting tool be it hacksaw or guillotine... Now all thats left is to fill it with something like hot glue (thats what I used) and stick it to the bottom layer base. You can make out in the picture where I put mine, it doesn't matter really just as long as it provides support for the other two wheels.
Step 11: Pat your self on the back, you're doing a good job, and you're more than half way through. On to the electronics!
OK, so you're done with the mechanical part of this project, time to give franken-robot its brains! You'll see in step one I referred you to this step for the circuit shield. The Arduino by itself can do nothing for this robot besides process and output data in a high (1) or low (0) 0-5volt signal. Furthermore, microcontrollers can't supply things like motors and relays the high current they require. If you try to power a motor with the Atmega168, most likely all you will get is smoke and a free fireworks show. So then how will we control out gear-head motors you might ask? Surveyyyyy says- H-Bridge! I am not going to spend the time here to explain exactly what an H-Bridge is, if you would like to learn more about them go here. For now all you need to know is that an H-Bridge will take a high or low signal from a mircocontroller, and power our motors from the AA batteries supply voltage source we give it. The circuit shield as the Arduino community calls them, will be a PCB (printed circuit board) that will rest on top of the Arduino and plug into it with header pins. To this shield we will add components like the L298 H-Bridge, some LED's, and Ultrasonic sensor wires. Once again I have done most of the work for you, by spending hours making a PCB of our circuit shield in a PCB CAD program called Eagle. To get your very own professionally made circuit shield go to BatchPCB. BatchPCB is a shoot off of Spark Fun Electronics, and they specialize in taking small orders from people like you and me at a very reasonable price. Next make yourself an account there so you can order my shield, then get the Zip file which contains the golden 7 files they need: GTL, GTO, GTS, GBL, GBO, GBS, and TXT drilling guide. It costs like $30 and takes about 1-2 weeks depending upon when you send it to them and what shipping you get. Now if you are good with electronics already, and think you can make your own on a prototyping board ( I did this temporarily), or if you like to etch your own PCB's, then go ahead but I'm not discussing how to do that here as it will waste time and space. If you choose to make your own then you can get just the schematic here, its a little crowded and messy so be ware. Oh, and an extra note on the PCB it does have some of my silkscreen graffiti on there, so don't think that the guys at the PCB factory were writing Chuck Norris facts on your circuit board! So lets fast forward about a week and assume your holding the circuit board right now...
Step 1: Make sure the holes for the Arduino headers line up with the holes for the header pins on the shield. Now as a result of my error, you will have to bend some of the pins on the L298 H-Bridge back so they will fin in the holes on the shield. Sorry about that. Warm up your soldering iron and get ready for some major soldering! If you don't know or are rusty on how to solder check out this page by Spark Fun.
Step 2: Solder the male header pins to the board. To make sure they fit well, I suggest that you stick the male headers into the Arduino first, then fit the shield over them; and solder them on.
Step 3: Now solder the L298 H-Bridge to the shield and the rest of the components (LED's, polarized connector pins, resistors, and diodes). The PCB should be pretty self explanatory as to where everything goes, because of the silkscreen layer on top. All the diodes are 1N5818, and be sure to match up the stripe on the diode to the stripe on the silkscreen. R1 and R2 are the 2.2K resistors, R3 and R4 are the 47K resistors, and R5 is the 10K resistor. LED's 1 and 3 are green to indicate the motors are going forwards, and LED's 2 and 4 are red to indicate the motors are going in reverse. LED 5 is the obstacle indicator and shows when the sonar picks up an obstacle in its programmed limit. The extra jumper places are there to leave us the option to update Walbot with different sensors in the future. Step 4: If you are soldering the wires directly to the board then skip step 5. If you are using the polarized connector pins then skip THIS step. Soldering the wires directly to the shield is not as neat but much faster and cheaper. You should now have 4 wires for both the motors, 4 wires coming from your AA battery packs, and 4 wires coming out of the sonar. Lets do the Battery packs first. See the second picture for a diagram of where to solder the wires. Now that thats done, solder the LEFT motor wires to the MOT_LEFT labeled holes on the PCB, and the RIGHT motor wires to the MOT_RIGHT holes (order does not matter, we can fix that with software later). For the sonar, there should be small labels in front of the SONAR holes on the PCB. Match up your GND wire to the GND hole, the 5V wire to the VCC hole, the RX wire to the Enab hole and the AN wire to the Ana1 hole. You should then be done with the wires!
Step 5: If you are using the polarized connector pins for the wires on the board and don't know how to use them, then read up on them here. Now solder in all of male polarized connectors to their corresponding number of holes. Look at the diagram below to see where to stick the crimp pins in the housing slots, so that they line up as shown. Next do the polarized connector housing for the left and right motor wires, it does not matter which order the wires go in just as long as left goes to MOT_LEFT, and right to MOT_RIGHT (we can fix which way the robot goes in the software). Finally do the Sonar wires making sure to line up / orient the wires so that your GND wire does to the GND hole, the 5V wire to the VCC hole, the RX wire to the Enab hole and the AN wire to the Ana1 hole. Once you crimp, wire, and connect those together, you should be done with the wires!
Step 6: Now you need to be able to power the Arduino using your 9Volt (its really 7.2 volts) battery. Using the 9Volt clip connector, open the power jack and solder the POSITIVE RED WIRE TO THE CENTER TAB and solder the black gorund wire to the tab which goes to the outer metal part. This is critical to make sure that the center / inner hole is positive, if you reverse this the Microcontroller will most likely do nothing except heat up, smoke or explode. If by accident you fry your Atmega168 you can get a new one here but you will have to burn the boot loader back on. To find out how to do this check the Arduino forum.
All the electronics should be finished with for now! Only easy stuff left now!
560x419 : FE5ACFNF3AQ37KG (1)
Make sure that all the file types shown here are the same as what you see when you order it.
When you wire these up, it is critical that positive goes to positive and negative goes to negative as shown. Check it with a volt meter just to be sure, and if when you first try out Walbot if nothing happens in about 10 seconds check the H-Bridge to see if it is getting hot. If it is turn everything off, and recheck to make sure these wires are in the right place.
So you've done all the exterior mechanical and electrical work, now its time to teach Walbot to avoid walls. Download the free Arduino program, and install it along with the USB drivers in the Drivers folder. Download the program I wrote for Walbot here and open that in the Arduino program. Next you want to compile the code by clicking the play (sideways triangle) button that says verify to the left when you hover over it. When it has finished compiling, use a USB cable to plug in the Arduino. The Arduino itself can be powered by the USB cables regulated 5Volts. Right next to the silver USB plug on the Arduino, there should be a jumper pin ( a little black piece of plastic and metal that connects two of the three pins sticking up), make sure when powering the board through USB that that pin is set nearest the USB plug ( there should be two labels under the jumper pin the right is USB the left should say EXT, you want it on the USB one for now). So now when you plug the USB cable into the Arduino board the green power LED underneath the PCB shield we made should be on, and the yellow indicator LED on top should light up once or twice. Note: If the green power LED on the Arduino board does not come on, take the USB cable out and check the jumper pin again, and that the USB cable is plugged into your computer! You should have already compiled the code in the Arduino program, so now click the upload button and it should start uploading onto the Arduino board (you can see the orange TX and RX LED's flashing on the Arduino board if this is happening). If you get an error that it is not responding first push the reset button ton the Arduino board ( the little DIP switch, after you push this you have about 6 seconds to upload the code before it reboots), if it still doesn't work, make sure you installed the USB drivers correctly (they are in the drivers folder in the Arduino folder you downloaded). If you still can't get it to work, consult the Arduino Forum and ask for help, they can guide you through what you need to do. If everything went well your program should have booted up in about 10 seconds, and if the AA batteries are charged and installed, the motors should turn on and if the Sonar detects something within 16 inches the yellow indicator light will turn on and the Right wheel will reverse direction for half a second. You can now unplug the USB cable, switch the jumper to EXT, plug in the Power Jack and put it on the ground. If you have done everything right so far, you will now have your very own obstacle avoiding robot!
If you have any questions or comments (or if I left something critical out which I probably did) just leave me a message in the comment area.
Also if you have any robot related questions I suggest that you join the Society of Robots Forum which I am a member of, and one of the people there will be more than happy to answer your questions! Happy Roboting!
So now you have a working robot...but it can only turn right, and it still has a good chance of running into things. How do we fix this? By using two side sensors. Since getting two more ultrasonic sensors would be very expensive, and not to mention overkill, we will use two Sharp GP2Y0A21YK Distance Measuring Sensors. These are wide angle so it will give us a larger field of view. When we were using just the Ultrasonic sensor, the threshold was 16 inches, this is a lot of room, but it was necessary. As you can see in the picture below, the sonar will detect an area the width of Walbot when it is about 16 inches away. But if Walbot was in a corner (with the wall being on the right) it would detect the wall ahead but then turn into the wall on its right, and get stuck. However, if we have two infrared distance sensors on either sides of the sonar, we can virtually eliminate the sonars blind spots. So now when Walbot goes into a corner it can decide: 1. if there is an obstacle ahead and on the right, turn left. 2. if there is an obstacle ahead and on the left, turn right 3. if there is an obstacle ahead, on the right and on left turn around. There is also something we haven't mentioned yet, and that is each sensors weaknesses. Sonar uses sound to calculate whats ahead of it, but what if its pointed at something that does not reflect sound well, such as a pillow? Infrared uses light (we can't see it) to see if anything is in front of it, but what if its pointed at something painted flat black? (The shade black is the absence of light, it theoretically does not reflect light.) Together these two sensors can address each others weaknesses, so the only way Walbot would miss something in front of it, would be if it was a black sound absorbing material. You can see how these two little additions can help Walbot tremendously. Now lets add these sensors to Walbot.
Step 1: Get the sensors! I put the link to get them above this. I also suggest you get the 3-pin JST Cable for Sharp Sensors because they're pretty hard to find elsewhere. Now skip a week ahead when the UPS guy delivers them, and lets get to work. First you need a way to mount them. You will need to make a mounting bracket for them, I made mine out of a strip of aluminum, but it doesn't really matter. You can try to copy the shape of my bracket, anything works as long as it fits and holds it in place.
Step 2: Attach the sensor to the bracket. Unscrew the top front two 8-32 cap screws just enough so theres space in between the standoff and the base. Fit the sensor into place and screw it back together.
Step 3: pull the wires through to the top. On your PCB shield there are two sets of 3 holes on the front side of the board labeled INFRA1 and INFRA2. Solder the red wire to the hole labeled VCC ( hole closest to the IN in INFRA), solder the black wire to the middle hole, and solder the white wire to the last hole labeled Ana2 or Ana3 (hole closest to the RA in INFRA). You can also to choose to use polarized connector pins instead of soldering the wires directly to the board.
Step 4: Download this code which includes extra features using the Sharp infrared sensors. Compile and upload this to your Walbot, and it should be smarter than ever!
Note: I haven't had much time to test the new code, so if someone finds anything wrong with it or sees a way to make it better just leave a comment.