Introduction: Simple 3D Printed Arduino Robot
Who doesn't want to build a robot? As a kid, I dreamed of building robots. Now, anyone of any age with just a little bit of knowledge can build a simple robot! I will show you how to do just that.
The Robot
This robot has a 3D printed chassis. It has an arduino uno for the brains, continous rotation servos for motion, a AA battery pack to power the servos, a Lithium Ion battery and charging/boost circuit (in the form of a shield) to power the arduino, a PWM shield to drive the servos, and finally, sensors!
What Can it Do?
Right now, this robot can do one of two things. It can either drive around a table without falling off. Or it can follow a line drawn on a piece of paper. However, I encourage you to get creative with it! Add other sensors, give it some more functions, the possibilities are endless!
Step 1: Bill of Materials
To build this simple robot, you'll need various parts.
-Arduino/Genuino Uno or Sparkfun Redboard (or anything with that form factor)
-Adafruit I2C PWM/Servo Shield
-For simpler programming, you can also use a motor driver shield like this one. However, if you plan to use additional servos and IO pins, it is more efficient to use the PWM shield as it only uses 2 pins (SDA and SCL)
-Wheels for continous rotation servos(2)
-Adafruit Powerboost 500 Shield
-I also soldered in some JST connectors (male and female) to make it easy to unplug the battery. However, they are not absolutely necessary
-3.7V 2000mAh Lithium Ion Battery
-TCRT5000L Infrared Optical Reflective sensors
-Resistors(100 ohm and 10k ohm; available from various sellers)
-Either Perfboard or get this PCB manufactured (more on this later)
-Various lengths and types of wire. (I recommend using ribbon cable from an old computer or ribbon cable that you can purchase)
-Heat Shrink(This or Hardware Store)
-4-40 X 3/8 flat phillips screws (Hardware Store)
-6-32 X 1/2 pan head screws (Hardware Store)
Required Tools
-3D Printer
-Soldering Iron/Equipment
-Screwdriver and bits
-Computer
Please note that this robot is completely open for modification and customization. Therefore, you do not have to use the exact parts I have listed.
Also note that most of these parts are available from different sellers. I have included links to where I bought them from but feel free to shop around.
Step 2: 3D Printing
Click here to be directed to my Thingiverse where you can download all the stl files necessary to build this robot.
I printed these parts on a Printrbot Simple Metal. I recommend to print at around 15-20% infill. However, every printer is different and you should know the right settings for your specific printer.
Customization
All of these parts are designed to work with my specific components, However, if you use different components or would like to customize it for any other reason, I will provide a link to the Onshape Document where you can modify the files to fit your needs.
Step 3: Preparing the Shields
I recommend starting with the powerboost shield. You will need to solder in the headers, solder in the switch, and plug in the battery. I wont go into too much detail because adafruit already has an entire tutorial on how to do this!
Next, you will need to prepare the PWM shield. Adafruit also has an excellent tutorial on how to do just that!
On this same PWM shield, you'll need to go ahead and tin a few pins (make sure you are tinning the pins that are on the opposite side of the header!). Tin pins A1, A2, GND, and 5V by putting some solder on them. You'll need these later.
Step 4: Prepare Servos
You can now screw the Servo brackets (which you should have printed earlier) to the main plate of the robot using 10 #4-40 screws (5 screws for each bracket). Make sure the cutout is facing out, and that the brackets are placed on the bottom and not the top.Then, pass the wires from the servos through the cutouts and slide the servo in making sure that the wires are facing the front of the robot. Then, screw the servos in using the long silver screws that should have been included with your servos.
Go ahead and attach the rubber tires to the wheels. Then, use the small black Phillips screws that should have came with the servos to affix the wheels to the servos.
Lastly, slide the servo wires through the hole in the main plate so that they can reach the electronics at the front. It may be helpful to put a piece of tape on each cable denoting whether it goes to the left or right servo.
Step 5: Arduino/Battery Pack
Place the Arduino Uno (or whatever equivalent board you chose) on the front of the robot to where it matches up with the standoffs on on the top side of the main plate. Screw the pan head screws into the standoffs. Just get them started. DO NOT screw the screws all the way in at first.
IMPORTANT NOTE: You may need to cut off the SCL pin on the left side of the Arduino so that the screw can fit in the standoff. The PWM shield does use the SCL and SDA pins for I2C communication. However, we don't need that specific pin because the SCL and SDA pins are also connected to pins A5 and A4 respectively.
Next, you will need to (one at a time) place the battery pack brackets under the main plate on their respective holes. Screw them in using the same pan-head screws from the Arduino. Make sure you keep them in the correct position.
TIP: If you get confused about which bracket goes where, place the battery inside them and look at the bottom side. If everything looks symmetrical AND the holes line up with the holes on the bottom side of the robot, then you're good! If not, rearrange them until it does. You could also keep track of what STL files you printed as they are named based on their positions (this is what I would recommend to do).
Once you get the brackets screwed in, go ahead and slide the battery pack through until the slide switch hits the edge of the bracket. I designed these brackets with tight tolerances so you may need to play around with them a little to make the battery pack fit properly. Next, slide the wires through the hole in the main plate and strip the ends of the wires. Since these wires are going into a terminal block, there's no need to tin them with solder.
OPTIONAL: You can also solder in a JST connector to the wires to make it possible to unplug the battery pack.
Step 6: Attach the Shields
If you soldered everything on the shields using the Adafruit tutorials, the PowerBoost 500 shield should have shield stacking headers on it. This makes it possible to "stack" shields on top of this shield. Which is exactly what we need to do! So go ahead and plug the PowerBoost shield into the Arduino. Then, you can plug the PWM shield into the PowerBoost shield.
Next, use a small Phillips bit to screw the wires from the battery pack into the terminal on the PWM shield.
Next, you'll need to plug in the servos. The LEFT servo goes to 1. While the RIGHT servo goes to 0. Make sure you don't plug the servos in backwards!
Step 7: Caster
You will need to attach the ball caster to the caster bracket. You can do this by taking the nuts off the screws, sliding the screws through the holes, and reattaching the nuts. You can then tighten by removing the ball from the caster and, while holding the nut with a pair of needle nose pliers, use a Phillips bit to tighten the screws.
Next, attach the entire bracket to the main plate by simply placing the bracket on top and using #4-40 screws to attach the two pieces.
NOTE: I have included a cutout and screw holes for a micro servo. I have not yet taken advantage of this. However, it will be easy to implement if you wish to do so.
Step 8: Software
Now to get some code on the thing! I used Codebender to write the code. I have also embedded the code so that all you need to do is plug the Arduino into your computer with the USB cable. Select the appropriate board, port, and click Run on Arduino. Make sure you switch the AA battery pack ON to power the servos while it is plugged into the computer. You also may want to place the robot so that the wheels will not be touching the table. Once it compiles and uploads, you should see... Well, nothing. At least that's what your'e supposed to see. The purpose for this sketch is to test the STOP positions for the servos. Both of the servos SHOULD NOT be moving. However, chances are they are moving slowly. The best way to change this is to adjust the potentiometer located on the front side of the servo until the wheel stops moving. You could also edit the RIGHTSTOP and LEFTSTOP variables in the sketch.
NOTE: You may edit this sketch to fit your needs by clicking on the Clone & Edit button near the top of the embedded code. You can also download an INO file by clicking on Download.
Step 9: Further Testing
Want to see it actually move? Upload this code to see it do a simple "Dance" function. Again, you'll need to plug in the Arduino to the computer (Go ahead and make sure the AA battery pack is switched OFF, as well as the switch on the PowerBoost Shield). Upload the code and then unplug the Arduino from the computer. Next, switch the AA battery pack to the ON position, as well as the switch on the PowerBoost Shield.
What you Should See
The robot should turn left for 1.5 seconds, turn right for 2 seconds, go in reverse for .5 seconds, go forward for .5 seconds, go in reverse for .5 seconds, go forward for .5 seconds, and then start over.
Step 10: You've (basically) Made a Robot
So, now you have a robot that can move around on its own. I encourage you to tinker with the code. If the code looks too confusing then just relax. It's actually really simple and I did my best to make it super easy to use! I am making a video where I will show you just how you can tinker with the code. I will post a link when the video is done!
So, you have moving robot that you can control with commands. Congratulations! You could stop there and have a completed robot. However, at this point the robot is pretty dumb. It just does the same thing over and over again without following a path. If you were to sit the robot on a table, it would eventually fall off. We can change that!
Step 11: SENSORS!
Okay, so for right now let's make the robot do two different things. Let's make it capable of following a line and also make it capable of driving around a table without falling off. To do this, we need sensors. Specifically, we need 2 TCRT5000L Infrared Optical Reflective Sensors. We can use two of them to accomplish both of those tasks. You will need to first wire the sensors up to a board. You have two options for this.
1. Perfboard
Simply wire the sensors and resistors to a piece of perfboard that around 70mm X 15mm. Use this schematic as a reference to wire the sensors up. Make sure the sensors are at the ends. You'll also need to solder 4 wires. One for 5V, one for GND, one for the left sensor and one for the right sensor.
2. PCB
I designed a PCB for the sensors which I have embedded below. The link to have it manufactured by OSHPark is on the bill of materials on Step 1. However, you may also download the gerber files to have the board manufactured wherever you wish. Also note that, at the time of this writing, I have not yet received the PCB in the mail. Therefore, changes may apply.
HINT: To download the gerber files or to duplicate and edit the project, click View on 123D Circuits.
If you're curious about how I made this PCB. Check out this video on my YouTube Channel. And while you're at it, SUBSCRIBE!
Step 12: Wiring to PCB
If you decided to go with the PCB method, you'll need to solder in the components. Here's the resistor values for each resitor.
R1 & R4 --- 100 ohm (220 also worked fine for me)
R2 & R3 --- 10kohm
Also, the TCRT5000L sensors ARE polarized, so don't solder them in backwards. The inward angle of the component should match the inward angle of the silkscreen on the board.
You will also need to solder wires to the pads for the header. You could also solder a header to these pads but I find it easier to just solder wires.
Step 13: Attaching the Sensor Board
If you used perfboard, the best thing to do is probable just hot glue the board to the lip on the caster bracket. If you got the PCB manufactured, then you can affix the PCB to the caster bracket with #4-40 screws.
Step 14: Wire Sensor Board to Arduino
Assuming you have been following the guide, you should have pre-tinned some pads on the PWM shield with solder. You'll need to solder the wires from the sensor board to the corresponding pads. Use this for reference:
PCB PIN --- ARDUINO PAD
5V --- 5V
GND --- GND
Left sensor/U1 --- A2
Right sensor/U2 --- A1
Step 15: More Software
So now you have soldered in the sensors, we still need to have the code that makes it work. As previously stated, it can do two functions as of right now. Edge detection and Line Following. Simply upload the code to the Arduino below.
1. Edge Detection (allows the robot to be placed on a table, move forward until it senses the edge, and turn left to avoid falling off)
2. Line Following (allows the robot to follow a black line drawn on white paper)
Step 16: Going Further
Congratulations! If you've made it this far, you now have a completed robot that can "see" the outside world. But where to go from here?? Well, the next thing I am going to do is add some sharp infrared digital proximity sensors so that I can allow it to sense objects around it. This way, it can not only avoid the edge of a table but also detect and avoid running into an object. I may also add a LCD and rotary switch in order to choose between functions. You could also attach a micro servo to the cutout in the caster bracket and affix something to that servo. That's just what I would do though. Let me know what you would like to add or would have done different! I will update this project as I add more features to it. To stay up to date, subscribe to my YouTube channel! I will also update this guide as I make improvements.
Congratulations on building this 3D Printed Arduino Robot!
Step 17: Going Further: Object Detection
So if you built the robot, all it can do is either follow a line or sense the edge of a table without falling off. However, if there is an object (such as a cup or box) on the table, the robot will run right into it. To solve this problem, I added a HC-SR04 Ultrasonic distance sensor! Basically, this sensor transmits and receives ultrasonic signals in order to determine the distance between the sensor and an object. In the code, I told the arduino to not only turn left when the IR sensor is triggered, but also when the distance measured on the ultrasonic sensor is less then ~4cm.
Attaching and Wiring the HC-SR04
The TRIG and ECHO pins of the HC-SR04 are wired to pins 13 and 12 of the Arduino, respectively. The Vcc and GND connections on the HC-SR04 go to power and ground. If you had the PCB (Rev B) made, then these Vcc and GND are already connected but you will still need to wire up the TRIG and ECHO pins.
To attach the HC-SR04 to your robot, you can do one of two things.
1. If you had the PCB (Rev B) made, then you can simply solder in some female headers to the HC-SR04 pins on the PCB, and then plug the HC-SR04 into those headers. (you could also solder the sensor in directly.)
2. If you did not have the pcb made, you could attach the ultrasonic sensor to the same perfboard you wired the IR sensors on. If there is not room, solder the sensor into another small piece of perfboard and hot glue that to the other board.