Grade Level: Middle school
Time Required: 2 hours (wild guess!)
Subject Areas: Science and Technology
Maker Challenge RecapStudents 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
- 1 SparkFun RedBot kit, per student or per group; available for $85 at https://www.sparkfun.com/products/13166
- jumper wires
- 4 AA batteries
- computer with Arduino IDE installed; refer to Arduino software installation instructions at https://learn.sparkfun.com/tutorials/installing-arduino-ide?_ga=1.103985152.1473012636.1478227346
- assorted found/recycled materials for chassis construction, such as cardboard, cereal boxes and plastic containers
- tape, hot glue and/or zip ties, for chassis construction and hardware attachment
- (optional) ability to make short video clips of dancing robots, such as a smartphone
- (optional) paper and pencils, to answer reflection questions
More Curriculum Like This
Using a few blindfolds and a simple taped floor maze exercise, students come to understand that computers rely completely upon instructions given in programs and thus programs must be comprehensive and thorough. Students create and test basic programs, first using just the LEGO intelligent brick, an...
Students learn how to program using loops and switches. Using the LEGO® MINDSTORMS® robots, sensors and software, student pairs perform three mini programming activities using loops and switches individually, and then combined.
Building on the programming basics learned so far in the unit, students next learn how to program using sensors rather than by specifying exact durations. Working with the LEGO® MINDSTORMS® EV3 robots and software, they learn about wait blocks and how to use them in conjunction with move blocks set ...
Students gain experience with the software/system design process, closely related to the engineering design process, to solve a problem. The lesson culminates in a hands-on experience with the design process as students simulate the remote control of a rover.
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!
- Encourage students to each come up with a design plan before beginning robot assembly—especially if they plan to construct their own chassis. This might include a labeled drawing of the proposed design.
- How Stuff Works provides a good introduction to robotics at its “How Robots Work” page at http://science.howstuffworks.com/robot.htm.
- Suggest that students watch the (4:39 minute) “How It’s Made Robotic Arms” video at https://www.youtube.com/watch?v=rf2zkWSaUY8.
- Refer to the RedBot Assembly Guide for how to assemble the RedBot kit hardware; see https://learn.sparkfun.com/tutorials/redbot-assembly-guide.
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.
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.
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: (motors.drive(255);)—Issues the commands that drive the motors. The value 255 in the motors.drive() 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.
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.
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.
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.
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?
Copyright© 2017 by Regents of the University of Colorado; original © 2014 SparkFun Education
ContributorsBrian Huang; Aaron Lamplugh
Supporting ProgramSparkFun Education
This maker challenge was adapted from SparkFun’s “Get’n Going - Recycled STEM Robots” activity at https://cdn.sparkfun.com/assets/a/5/c/1/c/01RobotDance-GetnGoingISTE.pdf.
Last modified: March 23, 2020