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.
Breadboard
To help you check your progress along the way, the project steps refer back to these pictures of the breadboard build.
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!
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.
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.
In the set-up section of the sketch, I added code to define the lance and shield pins as input.
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!
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.
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.
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.
Here’s the code for the victory music:
If the shield bump switch is triggered, you have lost. Rest in peace. Better luck next time.
Here’s the code for the defeat tune:
Jousting
Set up the Jousting Lane
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.
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.
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!