Maker Challenge Do the Robot!
Programming a RedBot to Dance

Quick Look

Grade Level: Middle school

Time Required: 2 hours (wild guess!)

Subject Areas: Science and Technology

A photograph shows a two-wheeled robot with a two-level red plastic platform covered in oblong holes, on which a circuit board, wires and four batteries are attached to the top level.
Can you program a SparkFun RedBot to dance?
Copyright © 2014 SparkFun Education CC BY-SA 4.0

Maker Challenge Recap

Students utilize the engineering design process as they program the drive motors of a SparkFun RedBot with a multistep control sequence—a “dance.” Doing this is a great introduction to robotics and improves overall technical literacy by helping students understand that we use programs to control the motion and function of robots, and without the correct programming, robots do not operate as intended and are unable to complete simple tasks that we count on them to perform. Students are given the basic code and then time to experiment, alter and evolve it on their own. As time permits, students may also want to construct and decorate frames and chassis for their robots using found/recycled materials such as cardboard boxes.

Maker Materials & Supplies

Worksheets and Attachments

Visit [] to print or download.


Get the inside scoop on all things TeachEngineering such as new site features, curriculum updates, video releases, and more by signing up for our newsletter!
PS: We do not share personal information or emails with anyone.


We use robots for so many purposes! From assembling cars in a factory to performing the most difficult medical procedures, robots impact our lives every day. How do robots work? How do we give them instructions? And, what makes them “listen” to us?

Engineers are often the people behind-the-scenes who control the function and movements of robots. They do this by generating codes, or writing sets of instructions, that tell the robot’s system what to do. These codes direct the electrical signals that control the robot’s hardware.

Understanding programming enables engineers to control robots and machines, which makes them useful tools to help people perform difficult and tedious tasks. If you had the ability to control a robot using code, what would you tell it to do? Today, you will use the Arduino IDE program to control a real robot, and program it to dance!


Maker Time

Have students take out their RedBot kits, batteries and jumper wires. Have students begin by connecting the external battery pack to the mainboard. Then attach the motors to the mainboard as shown in Figure 1 These steps—and more—are outlined in the SparkFun RedBot Assembly Guide.

A photograph shows a SparkFun RedBot mainboard with notations at the three locations to connect the left motor, right motor and battery pack.
Figure 1. The RedBot circuit diagram.
Copyright © 2014 SparkFun Education CC BY-NC-SA 3.0; added notations 2017 Aaron Lamplugh, ITL Program, College of Engineering, University of Colorado Boulder
Once motors are connected, use a standard USB cable to connect the mainboard to a computer with the Arduino IDE software installed.

See Figure 2 for the base code used in this maker challenge. When run, this code causes the RedBot motors to spin for two seconds. Copy this code into an Arduino IDE sketch and save it.

A screen capture shows 14 lines of code with the commented title: RedBot Test Code. This is the basic code for controlling the RedBot drive motors.
Figure 2. The RedBot motor base code.
Copyright © 2014 SparkFun Education CC BY-SA 4.0

Understanding the Code

The provided base code (see Figure 2) consists of just a few lines. Explanation by line:

  • Line 2: (#include <RedBot.h>)—Calls a reference library RedBot.h, which contains prewritten code commands for the RedBot.
  • Line 4: (RedBotMotors motors;)—Declares the RedBot object known as motors, which enables us to control the motors.
  • Line 8: (;)—Issues the commands that drive the motors. The value 255 in the function is the drive power. This value may range from -255 to 255. Switching from a positive to negative integer causes the motor to spin in the opposite direction.
  • Line 9: (delay(2000);)—Specifies the length of time that the drive command runs. The unit is milliseconds, so the length of time specified in the code is two seconds (2000 ms/1000 ms * s-1).
  • Line 10: (motors.brake();)—Tells the motors to brake abruptly after the drive command is completed.
  • Lines 6 and 12: (void setup() and void loop())—Begin and end the program loop.


Once the RedBots are linked to computers, have students execute the code. If the motors are oriented as shown in Figure 3, then the right motor spins clockwise and the left motor spins counter-clockwise.

A diagram shows the motor setup and spin direction that matches the provided base code (Figure 2).
Figure 3. A schematic of the motor setup.
Copyright © 2014 SparkFun Education CC BY-SA 4.0

If the RedBot does not work as expected, check the following:

  • Check the code for syntax errors. Pay careful attention to punctuation, spelling, spacing and capitalization!
  • Check that the POWER is set to ON.
  • Make sure that the XBEE_HW_SERIAL switch is in the down position pointed toward XBEE SW SERIAL; this is for advanced wireless control that we use later.
  • Verify that the motors are plugged into the correct ports.
  • Check that the MOTOR switch is set to RUN.

Chassis Design and Construction

Have students design and build their own chassis. Encourage creativity in their designs. While the robot chassis can be made from a number of materials, it works well if it follows the general form shown in Figure 4.

A rectangular diagram shows the RedBot motors on the top and bottom of the left side with an arrow indicating the forward direction (pointing left). On the right center of the rectangle, a circle is labeled “skid caster.”
Figure 4. A basic template to make a RedBot chassis.
Copyright © 2014 SparkFun Education CC BY-SA 4.0

Possible materials are cardboard, cereal boxes and plastic containers. Fasteners to attach the hardware to the chassis might include tape, zip ties and hot glue. Make sure students are careful while attaching hardware so as not to damage components and render them unusable.

Experimentation and Dance Off

Now that students understand how the code works, have them experiment with the code to make the RedBot “dance.” They can do this by:

  • Changing the drive power (try positive AND negative values)
  • Changing the delay time
  • Copying and pasting lines 8-10 inside of the loop, and then changing the drive power and delay time to create a series of movements—making a more complex “dance”
  • Controlling each motor separately using the following code with varying drive power values



Journaling for Documentation and Reflection

Suggest that students keep track of their code changes and results in a notebook or journal, which is a good engineering and research practice to cultivate. Provide some example starter sentences to assist students in documenting their code development. Examples:

  • The slowest speed setting for my motors is…
  • When I set this speed, we observed that…
  • Next, we tried changing… because we thought...
  • When we used a negative number for the speed setting...

Careful note taking pays off later when students refer to their notes to help them create faster and more precise code generation.

(Optional) Videos

It is fun, entertaining and more engaging if students make quick video clips of their dancing robots and then set them to music as a way to record their accomplishments and show them to others later.

Wrap Up

Have students reflect on their projects, either verbally as a class or in writing with their groups. If students recorded their robot dances, have them show their videos to the rest of the class. Reflection questions:

  • What sort of design process did you employ?
  • What worked well, and what did not?
  • What challenges did you face?
  • Did you complete and test your robot, and did the robot function as intended?
  • How might your code be applied to completing other tasks, other than dancing?
  • What other types of robots would you be interested in programming?


© 2017 by Regents of the University of Colorado; original © 2014 SparkFun Education


Brian Huang; Aaron Lamplugh

Supporting Program

SparkFun Education


This maker challenge was adapted from SparkFun’s “Get’n Going - Recycled STEM Robots” activity at

Last modified: July 27, 2020

Free K-12 standards-aligned STEM curriculum for educators everywhere.
Find more at