You can build the Mini-Mob in several configurations. We'll show one here, but if you think it would work better set up differently, try it and see. You can always take it apart and try another configuration later.
Start by attaching the axle holders to your chassis. In the kit, the chassis is the piece of wood with notches cut out of the side. The axle holders slide into the notches in the chassis and are attached with two zip ties each.
Next, attach the servos to the chassis. Make sure that the servo output shafts are both towards the back of the chassis. Attach each with a zip tie going through one hole above and one below the servo. A second zip tie can be attached around the outer edge of the chassis as shown below. It is not necessary, but it can help stabilize the servos.
Using the bolts and stand-offs to attach the upper platform. Below, two bolts were put into opposite corners, but it will work fine if they are both at one end. As mentioned above, there are many different configurations that will work. Try several to see which you like best.
Now, it's time to prep the wheels. On the drive wheels (below left), glue the servo horns into the gap. If you want to use the rubber bands as drive tread, cut two small pieces of dowel and that will later be inserted into the outside of the drive wheels (below right).
Connect the wheels to the robot. Start with the drive wheel and slide the servo horn onto the servo output shaft. Next, put one of the small screws into the hole on the outside of the drive wheel and screw it into the servo. (If you are using tread, put the wooden dowel in behind the screw and slide the brace onto the dowel.) Then use a nut and bolt to attach the free wheel to the axle holder (making sure to bolt on the brace if you're using it).
Repeat the last steps to connect the other wheels. Then flip the robot over to prepare to attach the motherboard.
Use a zip tie to attach the motherboard to the top of the chassis. You may need to daisy-chain two zip ties together to make one long enough to fit all the way around the motherboard. Make sure the zip tie fits low enough across the motherboard not to interfere with the Arduino chip which will be installed next.
Insert the Arduino chip into the socket so that the USB connection is at the opposite end of the board from the switch. Next, plug the servo wires into the two sets of pins at the end near the USB connection (pins 10 and 11) with the yellow wires closest to the chip. Then, slide the battery pack between to two levels. Finally, plug in the battery wires with the insulation pulled off the end and tighten the set screws. (Note, in this version, the tread isn't being used).
Congratulations, your robot is complete and ready to be programmed.
Download the correct version of the Arduino IDE for your computer
Install Arduino IDE
Download ArduBlock (ardublock-all.jar)
Install ArduBlock
Open Arduino IDE, Click File >> Preferences
Find the "Sketchbook location:"
Move ardublock-all.jar to "Sketchbook location"/tools/ArduBlockTool/tool/ardublock-all.jar
Close Arduino IDE
Once everything is installed, it's time to start programming your robot. Arduino based robots are typically programmed using the Processing language (which gets compiled into Java). Here we will examine both Processing and ArduBlock which is a Graphical User Interface (GUI) allowing people to program the Arduino by dragging and dropping blocks around the screen. To get started using either of these, first launch the Arduino IDE. Then make sure you tell it which type of Arduino you are using. For the Mini-Mob, we're using the Arduino Nano so click Tools >> Board >> Arduino Nano.
Anytime you write a program or sketch for the Arduino, you need two sections. The first section is called setup, which runs once at the start of the program. The second section is loop, which, not surprisingly, continues to loop endlessly. The code for these sections looks like this:
void setup()
{
}
void loop()
{
}
Between the curly brackets { } is where you write the code for each of the two main sections. Every Arduino program needs to have these two parts. Later, you can create new sections like these, but you can't replace or omit these.
If you're using ArduBlock, you don't have to type any code. Once you've told it what type of Arduino you have, click Tools >> ArduBlock. This will launch another window. Notice the colored categories along the left side of the new window. Clicking on any of those will bring up a list of available blocks to use. Now, just because you aren't typing the setup and loop doesn't mean you don't need them. The first thing you need to start with in ArduBlock is a loop so click Control and drag out the top block. It should look like this:
This will act as the loop section of your code and the setup section will be created behind the scenes depending on what your code requires. Let's start with a simple example.
When building your robot, you wired in the servos which will eventually drive the wheels, but before we get to that, let's look at the LED that's built into the Arduino itself and connected to pin 13. Start with the loop we had before. Now get the "LED Module" block which you can find it near the bottom of the DFRobot list. Drag it out so the dimple on the top left corner of the LED Module block aligns with the bump on the top right of the loop block. Notice that the loop expands to hold it. There are two small blocks stuck on the right side of the LED Module block: pin# and status. We want to control the LED connected to pin# 13 but it defaults to pin# 1. By clicking the 1, you can change it. We want it to turn the LED on, so don't change the status block. Next get the "delay" block from the Utilities list (making sure not to get the delayMicrosecond) and drag that to the bottom of the LED Module block. It defaults to a delay of 1000 milliseconds (1 second) but let's make it blink faster. Change the 1000 to 500 so the LED will stay on for only a half second. Then we need to turn it off so get another LED Module block and change it to pin# 13 also. This time we want the LED to turn off, so change the status to OFF. Finally add another delay of 500 milliseconds and you program should look like this:
Make sure that you robot is plugged into the USB cable and click the Upload button at the top of the ArduBlock window. This translates your code into Processing language in the Arduino IDE and send it to your robot. Did the LED on your robot start blinking?
At this point, we can look at the code that was created or if you don't use ArduBlock, you can type this to get the same result:
void setup()
{
pinMode( 13 , OUTPUT);
}
void loop()
{
digitalWrite( 13 , HIGH );
delay( 500 );
digitalWrite( 13 , LOW );
delay( 500 );
}
Remember, we still need the setup and loop sections. In the setup section, we tell the robot that we will be using pin 13 as an output pin rather than an input pin. Then, in the loop section we set pin 13 to high with the digitalWrite command. This mean there is high voltage (5V) going to that pin. Then we delay for 500 milliseconds before setting pin 13 to low or 0V. If you make any changes to the code, they won't be translated back to ArduBlock, but you can still upload them to the robot by clicking File >> Upload in the Arduino IDE.
Independent Challenge: Long Blink
Now that you have the LED blinking for a half second on and a half second off, go back and change the code in either Arduino IDE or ArduBlock to make the LED blink on for two seconds and off for a quarter second.
It's time to get this robot moving. For that, we need to turn on the servos. With electric motors, you can connect them to a power supply and they will turn one direction. If you want them to turn the other way, you must disconnect the power and switch the wires. For a robot, this would be very difficult, but servos have three wires: positive, ground and control. The positive and ground are the same connections you would use for electric motors. The control wire is what sets servos apart. You can send a signal on the control wire to tell the servo how to move. Most servos are designed to rotate in 180° which is useful if you are using it to control the flaps on an RC plane, but not helpful if you're trying to drive a robot. The servos that came with the Mini-Mob have been hacked to allow them to rotate continuously. If you tell one of these servos to go to position 45°, it will rotate forward and if your signal tells it to go to 135°, it will rotate backward. They are all set to have 90° be almost stopped (because of minor differences in the servos, they won't all stop at exactly 90°).
To get your robot to drive forward, we need to send one servo the signal for 45° and the other to 135°. This is because the servos are pointed in opposite directions. One must turn clockwise to drive the robot forward while the other must turn counter-clockwise. In ArduBlock, start with an empty loop (you can grab the top block in the loop and drag it out of the programming window below the category blocks to delete them). Grab the DFRobot Servo block from the DFRobot category and drop it into the loop. Change the pin to 10 and the angle to 45. Then, grab a second one and set the pin to 11 and the angle to 135. Upload that and your robot will start moving.
If you look at the code that was generated by ArduBlock, it's done something different. At the top, it says #include <Servo.h>. This tells the Arduino IDE to include the library called Servo.h which allows us to control the servos without having to think about what the signal to them should be. We tell the IDE that we want the servo to go to 45° and the library takes care of translating that for the robot. We also tell the robot that there are servos on pins 10 and 11, then in the loop we tell the robot to drive the servos to their desired locations.
#include <Servo.h>
Servo servo_pin_10;
Servo servo_pin_11;
void setup()
{
servo_pin_10.attach(10);
servo_pin_11.attach(11);
}
void loop()
{
servo_pin_10.write( 45 );
servo_pin_11.write( 135 );
}
This code will make it drive forever. If we want it to drive and stop, we need a little more code.
There are several different ways to make your robot drive for a certain distance, then stop. We'll examine one below. Can you think of others?
We start with our drive code from before and add a delay of 1000 milliseconds to the bottom of the code. Next we'll need two more DFRobot Servo blocks to tell the servos to stop and a delay block to prevent it from looping back to the top too soon. We could grab three more blocks or we can right click on the top DFRobot servo block, which brings up a menu, and select clone. This will create a copy of every block from that point down. Look for the cloned blocks in the upper left corner of the programming area. Grab the top block and drag it down to connect with the delay block already in the loop. When you drag the top block, all the blocks below it will come along. Now set the angle to 90° for the two new servo blocks and increase the delay to a large number like 999999999. This long delay will effectively end the sketch. If you wait long enough, the robot will start driving again, but it take ~11.5 days, so you're not in a rush.
Below you can see that I didn't use 90° in my code. As we discussed above, each servo is slightly different. Mine stop around 93°. If you use 90° and the servos are still turning, you can adjust the number to make them stop. It's unlikely that they will be the same, so notice which servo is turning and only adjust that one.
Using ArduBlock makes it easy to program your robot, but it doesn't give you complete control. There are certain things you can do with code that can't be done with blocks. Here is one example. Using ArduBlock, you can not stop a servo. You can send it a command that won't make it turn, but you are still sending it a command. Usually this causes the servo to continue to make noise and attempt to get to the position you assigned it. Using code however, you can completely shut it off. In the Drive sketch above, we attach the servos specific pins in the setup. Then we write a position for them to go to in the loop. We can also detach the servos, if we're done with them. So, for the code, we can use the same long delay to prevent it from looping and detach the servos to completely stop them from moving.
#include <Servo.h>
Servo servo_pin_10;
Servo servo_pin_11;
void setup()
{
servo_pin_10.attach(10);
servo_pin_11.attach(11);
}
void loop()
{
servo_pin_10.write( 45 );
servo_pin_11.write( 135 );
delay( 1000 );
servo_pin_10.detach();
servo_pin_11.detach();
delay( 999999999 );
}
This should start to look familiar. Notice that we still have the setup and loop sections and the #include <Servo.h> at the top. Play around with the code to see what happens if you adjust the different variables. What happens if you change the angle the servos are supposed to go to? What happens if you change the length of the first delay?
Independent Challenge: 1 Meter
Your robot drives and stops. Nice work. To show that you are in control of what your robot does, make it drive exactly 1 meter and stop.
So far the Mini-Mob has only gone forward (and possibly backward), but how do you get it to turn? There isn't a wheel you can angle like on a bike or car. Instead, it uses differential steering like a tank. If only one wheel rotates, that side of the robot will move while the other side stays in place. This causes the robot to turn, but it will turn even faster if one wheel rotates forward while the other one rotates backward.
Remember when we first started using the servos, for the robot to drive forward, one wheel had to rotate clockwise while the other rotated counter-clockwise because the servos are pointed in opposite directions. So if the robot is going to turn, both must rotate clockwise (or counter-clockwise) so that one side of the robot will drive forward and the other in reverse. All we need to do is change the 135° to 45° and the Mini-Mob will start to turn.
Having the robot just turn isn't very interesting, so let's have it drive forward, then turn. Start with the Drive code and add a pause. Then clone those three blocks like the Drive and Stop code. This time, don't set the second set of servo command to stop, instead set them both to 45° to make it turn. That will make it drive and turn, but let's add one more piece that will be useful for the Independent Challenge. Go to Control and grab a repeat block. Drag this to the top of main loop and then put all the other code inside the repeat. It defaults to repeating 5 times. Of course once it finishes the repeat, it hits the bottom of the loop and starts over, so it won't do much good yet. Here's the AdruBlock sketch.
When we look at the code, there are a few new things.
#include <Servo.h>
Servo servo_pin_11;
int _ABVAR_1_;
Servo servo_pin_10;
void setup()
{
servo_pin_11.attach(11);
servo_pin_10.attach(10);
}
void loop()
{
for (_ABVAR_1_=0; _ABVAR_1_< ( 5 ); ++_ABVAR_1_ )
{
servo_pin_10.write( 45 );
servo_pin_11.write( 135 );
delay( 1000 );
servo_pin_10.write( 45 );
servo_pin_11.write( 45 );
delay( 1000 );
}
}
The setup looks the same, but notice there is an extra line above the setup. Where we normally declare the names of the servos, there is also int _ABVAR_1_;. This tells the robot to set aside an area of memory for a variable called _ABVAR_1_ and that this variable will be an integer (int). That means the value it stores will always be a whole number and, because of the size of the area set aside, it will be between -32,768 and 32,767.
The next change in is the loop. A new command is used: for (_ABVAR_1_=0; _ABVAR_1_< ( 5 ); ++_ABVAR_1_ ). This is how it translated the repeat command. What it is telling the robot is to do the code below in the { } for a certain number of times and that number is define by what comes immediately after the for. First, it take the variable we created before (_ABVAR_1_) and sets it equal to 0. Then it says to keep doing the for loop as long as _ABVAR_1_ is less than 5. This is the "test condition". Finally it requires that the variable be increased by 1 (++) each time before it checks the test condition. The use of ++ to mean increase by one might not seem obvious but it turns out it happens a lot in programming and rather than write "_ABVAR_1_ =
_ABVAR_1_ + 1" each time, the programmers created a shortcut. You can also use -- to decrease by one. One last thing to note, the indentation of the code in the for loop was not auto-generated and was done to make it easier to read.
Independent Challenge: Square
Now that your robot can drive forward and turn, make it drive in a perfect square with 1 meter sides. You'll need to change the delay for the drive forward section and the delay for the turn section. How many times should it repeat those? When it finishes repeating it the correct number of time, it needs to stop near where it started, pointing in the same direction.