Turn your robot starter kit into a jousting bot!

This project builds upon the line-following robot from the RadioShack Make: it Robotics Starter Kit to create a jousting robot. Build one to learn how to modify a kit with just a bit of additional hardware and software, then build a second robot with a friend and organize a tournament!

With two robots, they will charge at each other down a defined track, adding a deadly edge to their line-following capabilities. A momentary button switch will act as the jousting lance’s tip, while a lever switch will act as the target (the knight’s “shield”). Depending on which robot wins and which robot loses, audible victory & defeat tunes will be played.

Along the way there’s a lot to learn about building and programming a robot.

Watch the video below to see the Joust-A-Bot in action and then let’s get started building your own jousting robot!


 

Circuit

Schematic

When you get to the step for building the circuit, you can refer to the diagrams below.

Here's the circuit schematic for the Joust-a-Bot.
Here’s the circuit schematic for the Joust-A-Bot.
Breadboard layout for the Joust-a-Bot
This is the breadboard layout for the Joust-A-Bot.

Breadboard

To help you check your progress along the way, the project steps refer back to these pictures of the breadboard build.

Breadboard with resistors and wiring for the speaker, lance button and bump switch.
Breadboard with resistors and wiring for the speaker, lance button and bump switch.
Breadboard with wiring from the robot's controller board.
Breadboard with wiring from the robot’s controller board.

Programming

Understanding the Line-Following Sketch

Line-following robots like this one generally use infrared (IR) sensors to guide them. If the optical sensor is over a white reflective surface, the IR light from the sensor is reflected and received. If the sensor is over a black surface, the IR light is absorbed and the sensor does not detect it. By guiding the robot based on readings from the sensors, a line-following robot straddles a black line on a white background. The two optical sensors keep the robot over the line.

The line-following sketch that comes with the starter kit works well, and the code is reasonably commented. However, many beginner programmers or even experienced Arduino programmers may find the code a little obscure.

For one thing the robot’s controller board has its own microprocessor, and the Arduino Uno compatible board you connect communicates with the controller’s processor using digital pins you would normally have access to under Arduino. Avoid using digital pins 0-3.

The code calls custom functions from the MakeItRobotics library, which may seem confusing. Also the bit-wise math calculations may not be familiar to many beginner and even intermediate programmers. But fear not, for all of the steps below are documented and as long as you are patient with your build, you’ll have a jousting robot in no time!

Ack! Hexidecimal numbers and bit-wise math! Ack!
Ack! Hexidecimal numbers and bit-wise math! Ack!

The good news is you don’t really have to mess with any of that for this project. I mention it here because if you want to go on to do bigger and better things with this robot kit (which you should totally want to do) you’ll want to get a better understanding of the code and how it works with the controller hardware.

Understanding the Jousting Sketch

I adapted the line-following sketch to build the Joust-A-Bot robot. I made one little change to the original code for the purpose of jousting, and incorporated some popular example code to manage input from the lance button and output to the speaker.

Incorporated Debounce and toneMelody examples, and borrowed some fun tunes.
Incorporated Debounce and toneMelody examples, and borrowed some fun tunes.

You have to set up some constants and variables for use with the Joust-A-Bot. I also turned a hard-coded value for the robot’s speed into a variable (the playspeed variable). This allowed me to implement different speeds depending on whether the robot is jousting, celebrating victory, or agonizing in defeat.

Set up constants and variables for the Joust-A-Bot.
Set up constants and variables for the Joust-A-Bot.

In the set-up section of the sketch, I added code to define the lance and shield pins as input.

Define the lance and shield pins as inputs.
Define the lance and shield pins as inputs.

There’s a problem with using buttons as input into an Arduino or other microprocessor. When the button transitions its state it has a mechanical “bounce” period, during which a microcontroller may see input from the button fluctuate rapidly between high and low.

Luckily, there’s a handy example sketch in the Arduino IDE to debounce the input. We use the debounce code here to remove bounce errors from the lance button and lever switch.

If a hit is detected by the lance button, the code calls the win() function to declare victory!

Debounce the lance button.
Debounce the lance button.

I originally wanted to make a little knight’s shield for the robot. Instead the cardboard tube knight actuates the switch. So in the code below, the bump switch is referred to as the “shield”.

If a hit is detected by the shield bump switch, you have lost and the code calls the lose() function.

Debouce the bump switch.
Debouce the bump switch.

For Joust-A-Bot, we want to create a white track between two black lines for the robot to travel down. We have to change the behavior of the robot, turning right where the line-following robot would typically turn left, and vice-versa.

Reverse the normal direction of turns so the robot will drive within the jousting lane.
Reverse the normal direction of turns so the robot will drive within the jousting lane.

As discussed above, if the lance button detects a hit, you call it a win. The robot will play a victory tune and dance a merry jig.

Note the last line in the code snippet below stops the robot from moving. To joust again you press the reset button on the robot’s controller board.

You win!
You win!

Here’s the code for the victory music:

Play the victory tune from Final Fantasy.
Play the victory tune from Final Fantasy.

If the shield bump switch is triggered, you have lost. Rest in peace. Better luck next time.

Ouch! You lost.
Ouch! You lost.

Here’s the code for the defeat tune:

"What matter wounds? For each time he falls, he shall rise again, and woe to the wicked. "Don Quixote
“What matter wounds? For each time he falls, he shall rise again, and woe to the wicked.”Don Quixote

Jousting

Set up the Jousting Lane

The field is prepared for combat!
The field is prepared for combat!

All you need for a jousting lane is two black lines on a white background. I used black electrical tape on white foam board from a craft store to make my jousting field. I cut the foam board in half length-wise and taped the ends together to give me one long lane. I’m able to fold the jousting field in half to be more portable.

A double length of foam board gives our knights plenty of room to work with.
A double length of foam board gives our knights plenty of room to work with.

The black lines should be parallel and just far enough apart to let the robots sit between them with a little room to spare on either side of the optical sensors. The wider apart your lines, the more wobble the robots will have in their path.

Let the Games Begin!

Set one robot jouster up on each end of your jousting track. Switch them on and let them charge at each other. Each time a lance or bump switch is triggered, you will have to reset that robot with the reset button on the controller board.

Will you feel the thrill of victory or the agony of defeat? Perhaps you’ll just learn something about robotics and have fun doing it!
Will you feel the thrill of victory or the agony of defeat? Perhaps you’ll just learn something about robotics and have fun doing it!

I’ll be honest, these robots are not expert jousters. They miss each other quite often. Or they crash and get hung up without either registering a hit (win) or triggering the bump switch (lose). Still, it’s pretty fun to watch them try!

Making expert jousters is not really the point. What did you learn from this project? How would you improve it? What other projects based on the Robotics Starter Kit can you come up with? It’s up to you to adapt the basic design from here.

Robotics is fun as a hobby, and a constant challenge to your abilities. If you try this project and come up with some improvements, please share your experience in the comments. I can’t wait to see what you come up with!

Project Steps

Build the Line-Following Robot

Begin with the instructions included in the kit to build the line-following robot. If this is your first time building a kit of this caliber, be patient and follow the instructions step-by-step. They’re pretty clear in most places, although I admit I had to back up a couple of times to fix a mistake I made (and I’ve assembled a lot of robots!).

The robot includes a custom controller that connects to an Arduino Uno or compatible board. The controller can drive up to four motors, with nice screw terminals for connecting motor leads. All the Uno pins are broken out on headers so they are easily accessible.

The two optical sensors included in the starter kit use infrared (IR) technology. Each sensor has an IR transmitter and an IR receiver. When IR light from the transmitter reflects off a light-colored surface, it can be detected by the receiver. If the sensor is over a dark-colored surface like a black line or electrical tape, the IR is absorbed and the receiver sees no reflection.

A Few Building Tips

You’ll have some parts left over, including M3 screws and nuts. I believe there are just enough M3 x 6 screws and M3 nuts to complete the project. Don’t worry if you lose any from the kit, you can pick up more at a hardware store like I did (note the silver nut in the first image).

I recommend removing the screws from the battery enclosure. The covers stay on fine without the screw and it makes changing batteries easier.

Most importantly, have fun! Building robots can be challenging, sometimes even frustrating. But if you make up your mind to enjoy the process you’ll get a lot more from the experience.

Test the Line-Following Robot

I know you are anxious to get jousting, but before you proceed you really have to test your line-following robot and make sure it is working properly. Download the support files as directed on page 18 of the starter kit user guide.

If you don’t already have the Arduino Integrated Development Environment (IDE) set up and working with your Uno or compatible board, go to http://arduino.cc to download the software and install it.

Use the paper with the black circular path included in the starter kit to test your robot’s line-following capabilities. Should you need to troubleshoot any issues, I found some helpful comments posted on RadioShack’s blog about the kit at http://shack.net/MakeItRobotics.

Gather Additional Parts

For each jousting robot, you’re going to need some of the extra parts from the starter kit.

  • (3) M3 x 6 screws
  • (1) M3 x 10 screw
  • (4) M3 nuts
  • (1) Right-angle bracket
  • (2) 9-hole flat bars
  • (1) 7-hole right-angle bar

Each robot will also require some additional parts from Radio Shack.

  • (1) SPST momentary button
  • (1) SPST momentary lever switch
  • (1) Mini solderless breadboard
  • (1) 8-Ohm mini speaker
  • 22 AWG solid core hookup wire
  • (2) 10k Ohm resistors
  • (1) 100 Ohm resistor
  • About 6 inches (15.2 cm) of 3/16 inch (4.8 mm) heat-shrink tubing
  • About 6 inches (15.2 cm) of 1/2 inch (12.7 mm) heat-shrink tubing

Finally, each robot will require some additional parts and materials, many of which you might already have in your workshop.

  • (1) 5/16 inch wooden dowel, 16 inches long
  • (3) Mini zip ties, about 100 mm long by 2.5 mm wide
  • (1) Cardboard tube (from paper towel or toilet paper roll)
  • (1) Sheet of white 8 1/2 x 11 paper
  • Some double-sided foam tape

Build the Lance

Cut one red and one black piece of 22 AWG solid core wire, each about 24 inches long. Strip 1/2 inch from each end of the wires, and solder one end of each wire to the SMT leads on opposite corners of the momentary button.

Use a dab of hot glue to secure the button to the end of the dowel. Secure the wires to the dowel with additional dabs of hot glue in several places along the length of the dowel.

Cut an inch of heat-shrink tubing. Use it to secure the button to the end of the dowel. You can optionally use a second piece of heat-shrink tubing to secure the wires along the length of the dowel. The finished lance should look like the third picture.

Build the Bump Switch

The bump switch will eventually be mounted to the rear of the robot chassis. The cardboard tube will be placed in front of the bump switch. Thus when the cardboard tube is hit with the opposing robot’s lance, it will cause the bump switch to be triggered, thus signaling a defeat!

Cut one red and one black piece of 22 AWG sold core wire, each 6 inches long. Strip 1/2 inch from each end of the wires, and solder one end of each to the C (common) and NO (normally open) terminals of the momentary lever switch.

Cut two pieces of 3/16 inch heat-shrink tubing, each 1 inch long. Place them over the ends of the soldered switch terminals, and use a lighter or other heat source to shrink the tubing.

The completed switch should look like the third picture.

Mount the Switch

Take the 7-hole right-angle bar (leftover from the kit) and use a mini zip tie to mount the switch as shown in the first picture. The switch should be mounted so that the hinged side of the switch lever is closest to the metal bar.

Once you have pulled the zip tie tight, trim the extra length off. The second picture shows the mounted switch from the other side.

To mount the switch assembly to the robot, you are going to need some parts leftover from the starter kit. For each robot you need:

  • (1) 9-hole flat bar
  • (1) M3 x 6 screw
  • (1) M3 x 10 screw
  • (2) M3 nuts (only one is pictured, but you’ll need two)

Mount the Switch Assembly

Use the M3 x 10 screw and one M3 nut to attach the switch assembly and the 9-hole flat bar to the rear of the robot as shown in the first picture. The flat bar should rest upright when you are done (see image three).

Use the M3 x 6 screw and one M3 nut to attach the other side of the switch assembly to the robot (image two).

When you are done the mounted switch and upright 9-hole flat bar should look like the third picture. Note the position of the lever switch. That will be important later when we add our knight.

Attach the Front Bracket

Next you will need some more parts from the starter kit. For each robot you need:

  • (1) M3 x 6 screw
  • (1) M3 nut
  • (1) Right-angle bracket

It may be easiest to turn the robot on its side to install this bracket, but refer to the third picture to understand where to place the bracket.

You should end up with the bracket looking like the third picture. Note the position of the holes carefully and be sure you have it right.

Attach Front Upright

Next for each robot you will need the following parts from the starter kit:

  • (1) 9-hole flat bar
  • (1) M3 x 6 screw
  • (1) M3 nut

Use the M3 screw and nut to attach the 9-hole flat bar as shown in the second picture. The flat bar should be upright when you are done.

Now gather your assembled lance and two mini zip ties.

Attach the Lance

Use one of the mini zip ties to attach the rear of the lance to the rear upright through the large hole that is second from the top of the 9-hole flat bar (see first image).

Use a second zip tie to attach the lance to the front upright. Note that the lance is placed to the right (exterior) of both the front and rear uprights.

When you are done your robot should look like the third picture.

Install the Speaker

Next, each robot requires an 8-ohm mini speaker.

Installation is ridiculously simple. Just place the speaker inside the rear of the robot. The magnet of the speaker will adhere to the flat metal plate inside.

Now your robot should look like the third picture. Leave your speaker wires hanging out the back, as shown.

Attach the Breadboard and Connect the Resistors

To attach the mini breadboard to the back of the robot, use two strips of double-sided foam sticky tape. There is already sticky tape on the bottom of the breadboard, but I recommend you use some additional tape instead. If you ever want to remove the breadboard from the robot, the tape that is directly attached the breadboard tends to get messed up, and it is also used to hold the metal contacts inside in place. So by using additional foam sticky tape you are less likely to destroy your breadboard’s contacts.

Cut away a bit of the waxy paper backing at the top and bottom of the breadboard (see first image), so you’re essentially sticking tape to tape.

Carefully apply the breadboard to the rear of the robot, with the top and bottom of the breadboard attached to the horizontal rails of the robot. In the second picture I have already pre-installed the resistors for the circuit. We’ll get to that in a moment.

Next you will begin adding components and connecting wires. Refer to the circuit schematic and breadboard layout diagrams in the project introduction above to see where to place the resistors. The two resistors on the left side are 10k ohms (brown-black-orange), and the one resistor on the right is 100 ohms (brown-black-brown).

Connect Wires for the Speaker, Lance Button, and Bump Switch

Refer to the circuit schematic and breadboard layout in the project introduction to place these wires. Start by connecting the red and black wires from the speaker. The black wire goes in the bottom-left row of the breadboard, where the two 10k ohm resistors are (see first image). The speaker’s red wire connects to the same row as the lower end of the 100 ohms resistor on the right side of the breadboard.

Next connect the red and black wires from the lance button (see image two). The red wire goes on the right side of the breadboard in the bottom row. This will eventually be connected to 5V from the robot’s control board. The black wire goes in the same row as the middle resistor (10k ohm), in the 11th row up from the bottom of the breadboard.

Finally, connect the red and black wires from the bump switch. The red wire goes in the 5V row on the right side of the breadboard in the bottom row. The black wire goes in the same row as the left 10k ohm resistor, in the 8th row up from the bottom of the breadboard (see image three).

Check your progress by referring to the project introduction under the heading “Breadboard Build”. Your breadboard should look like the first picture shown there.

Connect Wires for the Robot Control Board

Now it is time to connect wires to the robot control board. We are going to start with power and ground connections. Cut and strip one red and one black wire, each 9 inches long. Connect the red wire to 5V and the black wire to GND pin on the control board (on the right side of the robot). Route the wires back towards the breadboard at the rear as shown in the first picture.

Next cut and strip three wires (black, green and red), each 9 inches long. You are going to connect them to the digital pins on the left side of the robot. Connect the black wire to Pin 4. Connect the green wire to Pin 5. Connect the red wire to Pin 6. Route all three wires back towards the breadboard at the rear as shown in the second picture.

Time to connect all these wires to the breadboard. Refer to the third picture. Start with the 5V (red) and GND (black) wires from the right side of the robot. The red wire goes in the bottom-right 5V row of the breadboard. The black wire goes in the bottom-left row, along with the black speaker wire and two 10k ohm resistors you connected earlier. Now connect the three wires from the left side of the robot. The black wire (Pin 4) connects at the left side of the breadboard, in the 11th row up from the bottom. The green wire (Pin 5) connects at the left side of the breadboard, in the 8th row up from the bottom. The red wire (Pin 6) connects at the right side of the breadboard, in the 11th row up from the bottom.

Check your progress by referring to the project introduction under the heading “Breadboard Build”. Your breadboard should look like the second picture shown there.

Upload Jousting Code

Time to program your robot! You can download the jousting sketch from GitHub. Refer to the project introduction under the heading “Understanding the Jousting Sketch” for more details on how this code operates.

The jousting.ino sketch also calls for including a pitches.h file, which determines the pitch values of the notes in the victory and fail tunes. You can read more about the tone() function and how to easily create this file by following these instructions.

Remember to follow the directions for programming the robot that came with the starter kit. You need to remove the two jumpers on the controller J2 header before you attach your robot to your computer for programming.

After you have successfully compiled and uploaded the jousting sketch to the robot, disconnect the USB cable from the robot, and replace the two jumpers on the J2 header on the control board.

Decorate the Knight (Optional, but Recommended for Maximum Fun)

Who wants to joust with a boring cardboard tube? Decorate your knight and give him or her some personality.

Take a sheet of 8 1/2 x 11 inch white paper, and measure the height of the cardboard tube against the 8 1/2 inch side of the paper. It should be about half the height of the paper. cut the paper to the height of the tube.

Wrap the cut paper around the tube, and mark where the paper just barely overlaps. Cut the excess length of the paper off. It should be about half the 11 inch side of the paper.

In the first image you see a close up of Sir Smirksalot, Knight of the Red Crosshairs.

Draw your knight and decorate it however you like. Note how much of your knight will be visible when you place it in the robot.

Use a glue stick to apply the paper onto the tube.

In the second image you see Sir Grumpypants, Knight of the Black Mood.

Also provided are several Makey the robot knights, readymade for you to print them out and attach to a cardboard tube. Download the PDF here, or customize your own ‘bot knight however you want.

Install the Knight

Place a cardboard toilet paper tube knight in the back of the robot. There are optional instructions for decorating your knight at the end of the project if you need them.

Place the tube over the speaker.

Be sure to position the knight in front of the bump switch

When you press back on the knight, it should trigger the bump switch.

Once your knights are installed, refer to the project description under the “Jousting” heading to test out and play with your robots.

Conclusion

There are a bunch of other add-on kits for the Robotic Starter Kit, including a bulldozer bot, robot arm, and even a catapult! There are sensor kits available, and also a remote control, among other availalable additions. What other robot mods can you imagine? Share your thoughts, hacks, and clever robot mods in the comments below!