There are many ways to build a robot, from scratch a kit, a prebuilt system or combination of any of these methods. The path we will take here will be mostly from a kit and other items such as an Arduino controller, motor driver and sensors from eBay or other vendors.
The chassis kit I use for this project is the Peewee which comes from Actobotics, from their Runt rover line but any two wheeled small robot kit will work fine as well for this project. I chose the Peewee because it's small, inexpensive, durable, has lots of mounting options and is easy to put together. To assemble it you need no tools and can follow the video supplied by the manufacture. It can be assembled in under 10 minutes or less by most persons.
Things you will need to download:
Parts you will need are as follows:
- Runt Rover Peewee chassis or a suitable replacement
- Arduino Uno or similar board with USB cable
- Arduino Motor shield R3 or clone
- SG90 mini servo
- HC-SR04 or similar ultra sonic sensor
- Female to Female jumper wires
- Double sided sticky tape
- Small plastic soda bottle top
- A hot glue gun or rubber cement
- A 'AA' 4 slot battery holder (for alkaline) or a 5 slot (for rechargeable's) or one lithium ion 2 cell pack (7.4v) and charger (I highly recommend a li-ion pack to power most small bots) See more information on batteries below.
After you have purchased, collected and downloaded everything thing you're ready to start with the build!!!
First assemble chassis following the instructions included with the chassis or video. After finishing you should have something like the image.
Next attach the Arduino controller board and motor shield together then place them into the clip holder or onto your screw mounts (if you are using another type chassis). After you're done with that it should look something like this.
Now you can start hooking up wire connections. First connect the motor wires to the motor output terminals on the motor shield. For this bot the left side motor (with the rear of the bot facing you) will be connected to the ‘A’ channel. The black wire is in the first terminal and the red the second terminal. This leaves the right motor going to channel ‘B’, with with black again on the first terminal and red in the second. See pic for more details.
Next connect the HC-SR04 up by connecting VCC to one of the left pins of the tinker connector on the motor shield. The 5v (VCC) pins are the pins closest to the black female pin rail for the Arduino pins 0-SCL. After this is done, connect the GND pin of the sensor to the right pin of the tinker connector. After that, connect the Echo line to the Arduino’s pin 2. You can either connect it to the middle pin (the pin between VCC and GND) on the tinker connector for pin 2 or on the black rail for pin 2. Now connect the Trigger line to the Arduino’s pin 5. Again you can choose to either connect it to the middle pin (the pin between VCC and GND) on the tinker connector for pin 5 or on the black rail for pin 5.
Now you can hook up the servo. Connect the GND wire (usually black or brown, but opposite side of the white or orange wire. Place it on one of the tinker connector gnd pins. Then connect the servos center wire to a tinker connectors VCC. Finally signal wire (white or orange) to the center pin for the tinker connector for pin 6.
To place the servo on the bot, cut a small piece of double sided sticky tape and stick on the bottom of the SG90 servo. Take the servo and place it in the center of the two holes at the front of the chassis. NOTE: If you have two screws that fit the servo and chassis holes that are long enough, you can use those :-) Take the plastic soda bottle top and carefully cut a slit across it (see picture below), wide enough for the sensor board to slide into. Use a little hot glue or rubber cement on both sides to hold it in place. Now take the servo cross attachment horn “+” and glue it to the top side of the bottle cap. You can also drill a small hole with a small drill bit or even a little screw driver into the center of the top to help secure the mount even better on the servo with a screw.
Once you have the sensor ready to mount on the servo, place it on the horn and turn the servo slowly and VERY gently all the way in one direction, then the other to figure out the middle point. Once you think you have it, press the sensor on without the screw until you are sure it's in the correct position.
Now... Recheck all the wiring!
- Left Motor Black wire --> Motor sheild 'A' first teminal
- Left Motor Red wire --> Motor sheild 'A' second teminal
- Right Motor Black wire --> Motor sheild 'B' first teminal
- Right Motor Red wire --> Motor sheild 'B' second teminal
- HC-SR04 VCC --> Motor sheild tinker connector pin for VCC (pin closest to the Arduino pin rail)
- HC-SR04 GND --> Motor sheild tinker connector pin for GND (pin furtherest away from the Arduino pin rail)
- HC-SR04 ECHO --> Arduino’s pin 2 (either on middel pin of the tinker connector for pin 2 or the Arduino’s pin 2 on the rail)
- HC-SR04 TRIG --> Arduino’s pin 5 (either on middel pin of the tinker connector for pin 5 or the Arduino’s pin 5 on the rail)
- Servo GND (Black or Brown) --> Motor sheild tinker connector GND pin
- Servo VCC (Red) (servo center wire) --> Motor sheild tinker connector VCC pin
- Servo signal wire (white or orange) --> Motor sheild center pin for the tinker connector for pin 6.
With the wiring checked and rechecked, It's time to load the code.Follow the instructions on the Arduino site on how to install the Arduino IDE. After the IDE is installed, you can next install the Motor Driver library. Do this by down loading the zip file and extracting it to your Arduino libraries folder or by following these instructions on how to add a library. Once the library has been loaded, copy the below program and past it into the Ardriono IDE. Connect your PC and Arduino up with the USB cable. Now choose the board from the Tools->Board menu in the IDE, Uno for this project (choose the board you have if different from Uno) Now from Tools->Port menu, pick your com port. After this is done, click the upload button. If all went well, the code was loaded, if not see here for help on the IDE and related issues.
After the code has been loaded on to the controller, you can hook the battery pack up. If you are using a battery holder (with no batteries at this point), hook the black wire to the motor shield motor power in GND and the red to VIN. If you have a li-po or li-ion, you can use jumper wires as pictured to connect the battery, again black to GND and red to VIN.
As you make the last connection, you may want to hold the bot in one hand whilst doing it or it may get away from you! I do have a 30 second delay at startup to give you some time for adjustments. Once the bot powers on, the sensor servo is set to the neutral position (angle 90) and then the 30 second delay begins. At this point if you need to reposition the sensor mount, you can do so. After the delay has completed, the bot will move forward if all the connections were right and made well. If not, recheck them again and make any corrections needed. If they are right and the sensor looks centered enough, you can screw the bottle top to the servo using one of the servo screws that came with the servo. If the robot is moving backwards or turning instead of going forward at first move, switch the motor wires on the sheild terminals until they are correct (you may have to play around with it some)
One of the most common mistakes and problems for beginning robot builders is battery choice. Most pick batteries they are familiar with like 1.5V ‘AA’ or 9V alkaline or “Super duty” batteries. These are cheap and easy to get. However are not the correct choice though for powering your bot!!! A robot has a computer, motors, motor drivers and sensors that all need power. ‘AA’, 9v alkaline or the like will NOT supply enough power for them all.
In this day and age you have a lot of different battery types to choose from; NiCAD NiMH, Li-ion and Li-po just to name a few. They come in many shapes and voltage/mah sizes. For this robot or most any beginner bot I highly recommend using Li-ion 7.4v packs. They are relatively inexpensive for the power they give and easy to work with. For a good 7.4v pack you will expect to pay at least 10$USD. You will also need a charger, and one can be had for near the same price as the batteries.
Now you could go with NiCAD or NiMH 1.2v ‘AA’ size rechargeable, and you will need at least 5 of them to get the same voltage as 4 normal ‘AA’s. This is not a big issue since you can get 5 slot ‘AA’ holders. Rechargeable’s are easily found at most department, sporting or electronic stores. Buying 5 batteries and a charger may be around the same cost as the Li-ion option.
You can find both batteries and chargers on eBay, Adafruit, ServoCity, Sparkfun or hobby sites like HobbyKing and many other places. Do shop around!
Final battery note... Picking a battery for your bot may seem trivial, but it will weigh a lot more in it's performance than any thing else at first!!
The video above shows the bot in action. The code running on the video bot has close object reaction distances (2cm) and driving faster to show the maneuverability of the bot. It just wants to run free like other little robots!