The design of this robot focused around using the book "Getting Started with Arduino" by Massimo Banzi and published with [makezine.com Make]. I also employed code for running the servos from a project titled: How to Make an Arduino Controlled Servo Robot (SERB).
The Arduino Mothbot is in total a pretty quick robot to build. Assuming you start with all of the parts and don't have to improvise, the project in total should take maybe an hour to build. That is if you follow the instructions and copy the code. However, if you build only one feature at a time and test along the way then this project could take significantly longer. The advantage of the longer track is that you'll probably learn a lot more and have some fun along the way.
Step 1: Gather Your Parts and Tools
Arduino Mothbot Parts List
Now you may want to get some tools. Since this project employs a solderless breadboard you can do without a lot of fancy electronics equipment. Hopefully you can find the rest of the things you need in a garage:
1. Needle nose pliers
2. Wire Cutters
3. Flat head screw driver
4. Small Phillips (4-sided) screw driver
5. Adjustable wrench or 11/32" hex wrench
7. 1/16", 5/32" and 7/32" drill bits
8. Saw (optional)
9. Safety Goggles
Please use safe practices when using any power tools.
Step 2: The Planning Stage
In my planning phase I did not only looked at hardware and coding but did my electronics homework as well. I wanted to draw up a simple electronics schematic for this project so I could follow what was going on as I built it. You can see in the picture the different components, power lines, and the Arduino pins. Hopefully it's a clear diagram and also illustrates how simple the electronics for this project is.
Step 3: Connecting the Servos to the Arduino
1. The first thing to do when setting up the solderless breadboard is to set up the ground (GND) and power (+6V) for the servos. I chose to use the two long strips on the board that would be closest to the Arduino.
2. Once the ground and power lines are identified connect the ground of the Arduino board to the ground strip on the solderless breadboard. Do not connect the power to the solderless breadboard yet.
3. Each servo has three wires that come out of them. Mine have a black, red, and white wire for each. The black is for ground, the red is for power, and the white is the control wire. Cut three jumper wires for each servo of the same size (so 6 in total).
4. Attach the jumper wires to the end of the servo wires and then each servo to the solderless breadboard.
5. Now use jumpers to connect the ground and power from each servo to the ground and power of the solderless breadboard.
6. Now connect the control wires from each servo to the Arduino. Connect the left servo to digital output (PWM) 3 and the right servo to digital output (PWM) 11.
7. Finally, connect the ground and power from the 4AA batteries to the solderless breadboard ground and power. Don't be alarmed if the servos start moving when your Arduino has no power or is not yet programed.
8. Using the code you should now be able to run the motors in the forward, backward, left or right directions using the included functions.
Step 4: Testing Out the Motors
Before I post any code below I want to make it known that the following is based on another great project called How to Make an Arduino Controlled Servo Robot (SERB). I learned a lot from following the work on that instructable and want to give credit where it is due.
Step 5: Integrating the On/Off Button
As a note, you'll notice I removed the servos from the solderless breadboard for most of my pictures. This just helps make the image more clear when I'm showing different steps.
1. To begin, disconnect power from the servo motors before doing any more work. Remember to do this every time you add something to this project.
2. Now you may want to be able to turn your robot on and off as opposed to having the robot immediately start moving when you connect the power.
3. Identify a strip on the opposite side of the solderless breadboard to be power for on/off button (and later the sensors).
4. Using a long jumper wire connect the power (+5V) from the Arduino to the strip you just identified.
5. Connect two jumper wires to the momentary switch and plug one end into the (+5V) power
6. Plug the other end of the momentary switch into a smaller strip in the middle of the solderless breadboard.
7. From that same strip connect a 10K ohm resistor to the strip and the other end into ground
8. Finally, connect a wire from the strip with the switch and the resistor on one end and place the other end in digital input 7 on the Arduino.
9. Now, with the code you should be able to use the button to turn on and off the robot. If you use the code with the LED (digital output 13) you will see the on-board LED turn on and off with the robot. This is a great way to test the Arduino code if you have the power to the motors disconnected.
Step 6: Testing the On/Off Button
Step 7: Integrating the Light Sensors
1. Again, disconnect the power from the servo motors before doing this step
2. The setup for the light sensors will be done twice. It is almost the exact same setup as the momentary switch. Actually, it is the same setup, but this time you will use the light sensor (photo-resistor) instead of a momentary switch.
3. Because this robot will use the two light sensors to pick a direction to drive it is recommended that you set up each light sensor on opposite sides of the solderless breadboard or as far apart as possible.
4. Connect one end of a light sensor to the (+5V) power line and the other end into a small strip in the center of the board.
5. Connect a 10k ohm resistor to that same strip and the other end to ground
6. Now connect a jumper wire from the small strip (where the photo resistor and regular resistor are connected) and plug the other end into an analog input.
7. Connect the left sensor to analog input 0 on the Arduino and the right sensor to analog input 1.
8. You should now be able to use the light sensors to move the servos.
Step 8: The Final Code
Step 9: Build the Mothbot Body
1. The body of the robot is made out of a small sheet of poplar wood I bought at the hardware store precut to 6" x 24". I cut mine down to 6" x 8" using the saw provided in the hardware store.
2. Next I drilled holes towards the front of the board to attach the servo brackets for each servo. For this I used an 5/32" size drill bit.
3. I also drilled in a hole at the rear of the board for the caster wheel that balances the robot. For this I used an 7/32" size drill bit. I chose to use a slightly smaller drill bit so I could get a tight friction fit with my caster wheel since I wasn't using a nut and bolt combination to attach it.
4. Then I attached the brackets to the board with the nuts and bolts. This was done using the flat head screw driver and the adjustable wrench.
5. After attaching the brackets I attached each servo to the brackets with the nuts and bolts.
6. Finally, I pushed the caster wheel into the whole.
Step 10: Making the Wheels
Each wheel is made from the lid from a Ziploc Twist 'n Loc container. Other good lids are those on peanut butter jars or other food goods. I don't advocate wasting food but save up your lids and you might find one is the right size for your robot project. I used the leftover containers to hold parts I've collected.
1. The first thing I did was pick the servo horn I wanted for the wheels. I picked the ones that had four horns and that were included with my servos when I bought them.
2. Before you do anything, drill a hole in the center of the wheel. I recommend doing this with your 5/32" drill bit. You'll need this so you can get to the screw that connects the horn to the servo.
4. Now screw the lid to the horn. I used four included screws with each servo to connect the lids to the horns. It might be easier if you pre-drill tiny holes through the lid like I did. I used a 1/16" drill bit for this. But be careful, drilling through this plastic with a heavy drill and a tiny bit can be difficult.
5. Now connect the horns to the servos using the small Phillips (4-sided) screw driver.
6. Finally, wrap rubber bands around each wheel to give you more traction. I got my rubber bands from produce I bought at the grocery store. Hopefully you have a few lying around.
7. At this point the entire body and wheels should be assembled.
Step 11: Completing the Arduino Mothbot
1. Tape the Arduino and solderless breadboard to the top of the robot body that you've built.
2. Using tape again it's a good idea to connect the 4AA battery holder and the 9V battery to the body. Make sure the wires reach.
3. Connect the servo wires to the solderless breadboard if you had removed them previously.
4. Connect the Arduino power
5. Connect the servo motor power
6. Now place your robot on the ground and press the on/off switch! It should now come to life and chase the light around the room:)
As a future add-on project I would include a simple bumper or wall sensor. This would be a switch, much like the On/Off button used in this project. However, when the button was pushed it would tell the robot to reverse direction, turn left or right, and continue with the program. Once that is completed this robot would be a great little testing platform for other sensors and devices.