Hands-on Activity Using Waits, Loops and Switches

Quick Look

Grade Level: 7 (6-8)

Time Required: 45 minutes

Expendable Cost/Group: US $0.00

This activity uses non-expendable (reusable) LEGO robots and computers; see the Materials List for details.

Group Size: 2

Activity Dependency:

Subject Areas: Computer Science, Science and Technology

NGSS Performance Expectations:

NGSS Three Dimensional Triangle
MS-ETS1-1
MS-ETS1-4

Summary

Students are given a difficult challenge that requires they integrate what they have learned so far in the unit about wait blocks, loops and switches. They incorporate these tools into their programming of the LEGO® MINDSTORMS® robots to perform different tasks depending on input from two touch sensors. This activity helps students understand how similar logic is implemented for other every day device operations via computer programs. A PowerPoint® presentation, pre/post quizzes and worksheet are provided.
This engineering curriculum aligns to Next Generation Science Standards (NGSS).

A photograph of an assembled LEGO MINDSTORMS EV3 robot.
Programs involving loops, switches and wait blocks enable more efficient control of LEGO robots.

Engineering Connection

Programming tools similar to those that students build into their skill sets from this activity are incorporated into the programming that runs all sorts of devices we use every day. Many of these programs are designed to "wait" until a user does something, such as credit card readers waiting until a card is swiped. In addition, depending on what happens (new sensor input) the program behaves a certain way. For example, if the device was unable to read the card, it might display a message to try again. And once the task is completed with one card, the program "goes back" and gets ready to accept another card swipe. The card reader program is continuously in this loop and designed to respond to various sensory input.

Learning Objectives

After this activity, students should be able to:

  • Explain what loops and switches are.
  • Identify programming situations in which loops and switches should be utilized.
  • Write programs that utilize loops and switches.

Educational Standards

Each TeachEngineering lesson or activity is correlated to one or more K-12 science, technology, engineering or math (STEM) educational standards.

All 100,000+ K-12 STEM standards covered in TeachEngineering are collected, maintained and packaged by the Achievement Standards Network (ASN), a project of D2L (www.achievementstandards.org).

In the ASN, standards are hierarchically structured: first by source; e.g., by state; within source by type; e.g., science or mathematics; within type by subtype, then by grade, etc.

NGSS Performance Expectation

MS-ETS1-1. Define the criteria and constraints of a design problem with sufficient precision to ensure a successful solution, taking into account relevant scientific principles and potential impacts on people and the natural environment that may limit possible solutions. (Grades 6 - 8)

Do you agree with this alignment?

Click to view other curriculum aligned to this Performance Expectation
This activity focuses on the following Three Dimensional Learning aspects of NGSS:
Science & Engineering Practices Disciplinary Core Ideas Crosscutting Concepts
Define a design problem that can be solved through the development of an object, tool, process or system and includes multiple criteria and constraints, including scientific knowledge that may limit possible solutions.

Alignment agreement:

The more precisely a design task's criteria and constraints can be defined, the more likely it is that the designed solution will be successful. Specification of constraints includes consideration of scientific principles and other relevant knowledge that is likely to limit possible solutions.

Alignment agreement:

All human activity draws on natural resources and has both short and long-term consequences, positive as well as negative, for the health of people and the natural environment.

Alignment agreement:

The uses of technologies and any limitations on their use are driven by individual or societal needs, desires, and values; by the findings of scientific research; and by differences in such factors as climate, natural resources, and economic conditions.

Alignment agreement:

NGSS Performance Expectation

MS-ETS1-4. Develop a model to generate data for iterative testing and modification of a proposed object, tool, or process such that an optimal design can be achieved. (Grades 6 - 8)

Do you agree with this alignment?

Click to view other curriculum aligned to this Performance Expectation
This activity focuses on the following Three Dimensional Learning aspects of NGSS:
Science & Engineering Practices Disciplinary Core Ideas Crosscutting Concepts
Develop a model to generate data to test ideas about designed systems, including those representing inputs and outputs.

Alignment agreement:

Models of all kinds are important for testing solutions.

Alignment agreement:

The iterative process of testing the most promising solutions and modifying what is proposed on the basis of the test results leads to greater refinement and ultimately to an optimal solution.

Alignment agreement:

  • Students will develop an understanding of the attributes of design. (Grades K - 12) More Details

    View aligned curriculum

    Do you agree with this alignment?

  • Students will develop an understanding of engineering design. (Grades K - 12) More Details

    View aligned curriculum

    Do you agree with this alignment?

  • Students will develop abilities to apply the design process. (Grades K - 12) More Details

    View aligned curriculum

    Do you agree with this alignment?

  • Develop innovative products and systems that solve problems and extend capabilities based on individual or collective needs and wants. (Grades 6 - 8) More Details

    View aligned curriculum

    Do you agree with this alignment?

  • Refine design solutions to address criteria and constraints. (Grades 6 - 8) More Details

    View aligned curriculum

    Do you agree with this alignment?

Suggest an alignment not listed above

Materials List

Each group needs:

To share with the entire class:

Alternative: LEGO MINDSTORMS NXT Set:

Note: This activity can also be conducted with the older (and no longer sold) LEGO MINDSTORMS NXT set instead of EV3; see below for those supplies:

  • LEGO MINDSTORMS NXT robot, such as the NXT Base Set 
  • LEGO MINDSTORMS Education NXT Software 2.1
  • computer, loaded with NXT 2.1 software

Worksheets and Attachments

Visit [www.teachengineering.org/activities/view/umo_computerprogram_lesson03_activity1] to print or download.

Pre-Req Knowledge

Completion of the How Do You Make a Program Wait? lesson and its associated activity.

Introduction/Motivation

Suppose you need to program a robot to carry a load back and forth between two points 100 times. It would be very tedious to write the same set of blocks 100 times in your program. A loop allows you to easily make your program repeat a set of steps until a condition is satisfied.

People react differently to different stimuli. For example, in order to be comfortable outside, we dress in a particular way depending on the weather. If it is hot, we wear t-shirts and shorts, if it is a little colder maybe jeans and a sweater. And when it is snowing, we put on heavy coats, boots and gloves. Similarly, we can design programs to respond differently, depending on whether different conditions are satisfied.

Switches enable programs to respond differently based on whether certain conditions are satisfied. For instance, to program a calculator, one could use a switch to direct the calculator to perform the correct operations depending on whether plus (+), minus (-), multiply (x) or divide (/) keys are pressed. Today we will study about how you can incorporate loops and switches into programs.

Procedure

Before the Activity

  • Gather materials and make copies of the Waits, Loops and Switches Pre/Post Quiz, two each per student, and the Waits, Loops and Switches Worksheet, one per student. The quizzes and worksheet are provided as separate attachments, and also embedded in the presentation to make it easier to go through them as a class, if desired.
  • The content previously presented in the Loops and Switches Presentation in the associated lesson, How Do You Make Loops and Switches?, is essential for students to understand and remember in order to complete this activity. Thus, it is recommended that a copy of this presentation be provided for each group as a reference.
  • Assemble the LEGO MINDSTORMS EV3 bevel bots for each group, following the instructions in the manual.
  • In advance, perform the entire activity so as to be familiar with all details, especially the programming solution on slides 5-8.
  • Present the activity challenge to students using the 11-slide Using Waits, Loops and Switches Presentation, a PowerPoint file. Set up a computer/projector to show the presentation to the class.
  • Arrange for enough computers so you have one for each student group. Make sure each computer has the LEGO software loaded.

With the Students

  1. Administer the pre-quiz by handing out paper copies (also on slide 2). The answers are provided for the teacher on slide 3.
  2. (slide 4) Introduce students to the activity challenge in which they combine wait blocks, loops and switches to perform a task. After attaching two touch sensors (1 and 4), program the LEGO robots to perform the following:
    • Stay at rest and display "Ready" on the screen
    • Move forward and display "forward" whenever touch sensor 4 is pressed.
    • Move backward and display "reverse" whenever touch sensor 1 is pressed.
    • Stay at rest and display "stop" when no buttons are pressed.
  1. Divide the class into student pairs and distribute the worksheets.
  2. Expect each student pair to come up with a LEGO MINDSTORMS EV3 program design to meet the activity challenge by completing the worksheet, including providing the settings for each block in the program.
  3. Once students have designed their programs, guided by the worksheet, direct them to create the program using the LEGO MINDSTORMS EV3 software.
  4. Oversee students as they download and test their programs using LEGO bevel bots with touch sensors installed. If a program does not work correctly, have students troubleshoot to isolate the problem to determine which block needs adjustment or which block setting might be incorrect. Encourage students to talk with their group partners to figure out and fix any problems. Each time the group alters its program, have them download the revised program and test it; by doing this, they are experiencing first-hand the iteration process that is typical in the design process.
  5. Once all groups have made their programs work as intended (or the time allotted for developing programs is over), review the programming solution (on slides 5-8) with the class. Have students share and discuss their observations, experiences and difficulties in creating successful programs.
  6. Administer the post-quiz by handing out paper copies (also on slide 9). Answers are on slide 10. Vocabulary are provided on slide 11.

Vocabulary/Definitions

brainstorming: Thinking of ideas as a group.

iteration: Doing something again, especially with the intent to make improvements.

loop: A command or "operator" that repeats a set of commands.

switch: In programming, a switch is an object that gives different commands depending on which state it is in

Assessment

Pre-Activity Assessment

Pre-Quiz: Administer the three-question Waits, Loops and Switches Pre/Post Quiz (also on slide 2) to assess what students retained about loops and switches from the associated lesson. Answers are provided on the Waits, Loops and Switches Pre/Post-Quiz Answer Key (and slide 3). Administer the same quiz at lesson end.

Activity-Embedded Assessment

Worksheet & Iterations: Make sure that students first complete the Waits, Loops and Switches Worksheet and have a good idea of what they want to program before using the LEGO software to create and test their programs. Like engineers, it is rare for students to create programs perfectly on the first attempt, so expect them to take some time and repeated efforts to make them work as intended. The teacher should, however, know the solution well (provided in the slides) and ask pertinent questions to guide students to successful solutions. Review students' worksheet answers to gauge their comprehension of the concepts covered.

Post-Activity Assessment

Post-Quiz: At activity end, administer the Waits, Loops and Switches Pre/Post Quiz again by handing out paper copies (also on slide 9). Expect students to be able to provide more in-depth responses to the questions on the post-quiz after completing the activity. Compare students' answers to their pre-quiz answers to assess their comprehension of the activity content. Answers are provided on the Waits, Loops and Switches Pre/Post-Quiz Answer Key (and slide 10).

Investigating Questions

  • In your own words, explain what you did at every step of the engineering design process as you created programming solutions to meet the challenge. (The steps are: 1-state the problem, 2-generate ideas [brainstorming], 3-select the best solution, 4-create a prototype solution or item, 5-test and evaluate to see if it works, 6-present results as a successful solution.)
  • In your own words, tell me what is meant by "brainstorming" and "iteration"?
  • What are some examples of everyday devices that likely use programming similar to the wait blocks, loops and switches you have used with the LEGO robots?

Subscribe

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.

More Curriculum Like This

Upper Elementary Lesson
How Do You Make Loops and Switches?

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.

Upper Elementary Lesson
How Do You Make a Program Wait?

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 ...

Upper Elementary Activity
Wait Program!

After completing the associated lesson, students test their understanding in two programming tasks that utilize LEGO® MINDSTORMS® NXT robots and sound/touch sensors. They create programs that make the robots change speed several times when a touch sensor is pressed.

References

NXT User's Guide. Accessed Jul 17, 2013 http://goo.gl/wuhSUA

Copyright

© 2014 by Regents of the University of Colorado; original © 2013 Curators of the University of Missouri

Contributors

Riaz Helfer, Pranit Samarth, Satish S. Nair

Supporting Program

GK-12 Program, Computational Neurobiology Center, College of Engineering, University of Missouri

Acknowledgements

This curriculum was developed under National Science Foundation GK-12 grant no. DGE 0440524. However, these contents do not necessarily represent the policies of the National Science Foundation, and you should not assume endorsement by the federal government.

Last modified: October 16, 2020

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