Lesson: How Do You Make a Program Wait?

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

Two photographs: A young girl in baseball clothing and cap waits in the outfield with a baseball mitt. A girl sitting cross-legged with a laptop and both hands raised in victory.
Students are introduced to how sensors may be used in programming.
Copyright © (left, right) 2004 Microsoft Corporation, One Microsoft Way, Redmond, WA 98052-6399 USA. All rights reserved; http://office.microsoft.com/en-us/images/results.aspx?qu=computer&ex=1#ai:MP900448599|


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. They start with an examination of algorithms and move to an understanding of conditional commands (until, then), which require the use of wait blocks. 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 with unlimited duration. To help with comprehension and prepare them for the associated activity programming challenges, volunteer students act out a maze demo and student groups conclude by programming LEGO robots to navigate a simple maze using wait block programming. A PowerPoint® presentation, a worksheet and pre/post quizzes are provided.
This engineering curriculum meets Next Generation Science Standards (NGSS).

Engineering Connection

Programming is a vital skill for most engineers as well as many other professional jobs. Almost all useful programs must be able to perform operations without knowing all of the values of operands in advance. For instance, in a program that plays chess against a human player, the computer does not know where its opponent is going to move in advance, but is programmed to be able to respond to a variety of situations. Similarly, a LEGO robot does not know exactly how far away an obstacle is, but it can be programmed to bypass the obstacle when it is sensed.

Pre-Req Knowledge

Completion of the first lesson in this unit (What is a Program?) so that students are ready to create their own EV3 programs.

Learning Objectives

After this lesson, students should be able to:

  • Program a LEGO MINDSTORMS EV3 robot using sensors.
  • Explain why it might be advantageous to program a LEGO robot without having to know exact distances it must move.

More Curriculum Like This

What Is a Program?

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

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.

What Is a Motor and How Does a Rotation Sensor Work?

Students learn about electric motors and rotational sensors. They learn that motors convert electrical energy to mechanical energy and typically include rotational sensors to enable distance measuring. Students create a basic program using the LEGO® MINDSTORMS® interface to control a motor to move a...

What Is a Computer Program?

Through four lesson and four activities, students are introduced to the logic behind programming. Starting with very basic commands, they develop programming skills while they create and test programs using LEGO® MINDSTORMS® robots. The unit is designed to be motivational for student learning, so th...

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.

  • Generate and compare multiple possible solutions to a problem based on how well each is likely to meet the criteria and constraints of the problem. (Grades 3 - 5) Details... View more aligned curriculum... Do you agree with this alignment?
  • Plan and carry out fair tests in which variables are controlled and failure points are considered to identify aspects of a model or prototype that can be improved. (Grades 3 - 5) Details... View more aligned curriculum... Do you agree with this alignment?
  • Evaluate competing design solutions using a systematic process to determine how well they meet the criteria and constraints of the problem. (Grades 6 - 8) Details... View more aligned curriculum... Do you agree with this alignment?
  • Analyze data from tests to determine similarities and differences among several design solutions to identify the best characteristics of each that can be combined into a new solution to better meet the criteria for success. (Grades 6 - 8) Details... View more aligned curriculum... Do you agree with this alignment?
  • Various relationships exist between technology and other fields of study. (Grades 3 - 5) Details... View more aligned curriculum... Do you agree with this alignment?
  • The design process is a purposeful method of planning practical solutions to problems. (Grades 3 - 5) Details... View more aligned curriculum... Do you agree with this alignment?
  • Test and evaluate the solutions for the design problem. (Grades 3 - 5) Details... View more aligned curriculum... Do you agree with this alignment?
  • The processing of information through the use of technology can be used to help humans make decisions and solve problems. (Grades 3 - 5) Details... View more aligned curriculum... Do you agree with this alignment?
  • New products and systems can be developed to solve problems or to help do things that could not be done without the help of technology. (Grades 6 - 8) Details... View more aligned curriculum... Do you agree with this alignment?
  • Specify criteria and constraints for the design. (Grades 6 - 8) Details... View more aligned curriculum... Do you agree with this alignment?
  • Describe how new technologies have helped scientists make better observations and measurements for investigations (e.g., telescopes, electronic balances, electronic microscopes, x-ray technology, computers, ultrasounds, computer probes such as thermometers) (Grade 5) Details... View more aligned curriculum... Do you agree with this alignment?
Suggest an alignment not listed above


(Be ready to show students the 23-slide How Do You Make a Program Wait? Presentation, a Microsoft® PowerPoint® file, to teach the lesson. In advance, make copies of the How Do You Make a Program Wait? Pre/Post Quiz, provided as attachments and slides, and the Algorithm Worksheet. Student groups also need LEGO robot components, as described in the Background section. For Day 1, have handy a blindfold and a simple maze route near a wall in the classroom, made from tape on the floor; refer to slide 12 description. For Day 2, prepare a simple maze using wooden blocks or cardboard boxes; refer to slide 8 diagram.)

If you want your LEGO robot to move based on input it receives from you in the form of a clap of hands, how would you think about programming it? (Let students think about this for a moment.) Well, you would have to have logic such as "keep the robot moving forward until it hears a clap sound." This means that the robot is WAITING to hear the sound. We call statements like this "conditional" statements. How would you implement that in a program? That is what we will study in today's lesson.

(Continue by showing the presentation and delivering the content in the Lesson Background section.)

Lesson Background and Concepts for Teachers

The second lesson in this unit provides a general introduction to programming using conditional commands as well as a detailed walkthrough for writing such programs using the LEGO MINDSTORMS EV3 software. Present the lesson using the content provided in the slide presentation, as described below.

During the lesson, each group needs the following materials:

  • LEGO MINDSTORMS robot, such as the LEGO EV3 kit (buildable and programmable robot), available for $349.99 at https://shop.lego.com/en-US/LEGO-MINDSTORMS-EV3-31313; follow the taskbot building instructions in the core set manual; the sensor is included in the core set
  • LEGO MINDSTORMS Education EV3 software 1.2.1
  • computer, loaded with EV3 1.2.1 software

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:

  • computer loaded with the NXT 2.1 software

What Are Conditional Commands?

As any programmer progresses, his/her objective is to write good programs. A good program not only performs reliably, but is almost always recognized by being both easier for the programmer to write and for the audience to understand.

The programs students wrote in the first activity of this unit (Navigating a Maze) are extremely reliant upon approximating or measuring distances between objects and then estimating or calculating how many rotations it would take the robot to move that far.

Instead of this approach, it is both less tedious and more useful to control the robot by using information the robot receives from its sensors. For instance, suppose you want the robot to move forward but come to a stop as soon as it reaches a wall. It is fairly tedious to measure the distance from the robot to the wall, estimate how many rotations this is, and tell the robot to go exactly that many rotations forward. Further, you must hope that you start the robot at exactly the same position each time or your program will not accomplish the given task correctly.

The alternate way is to tell the robot to move forward until its touch sensor hits a wall and then stop. This approach is not only easier (with practice) for the programmer, but it also does a better job accomplishing the task because no matter what location the robot starts, it will stop exactly when it reaches the wall.

We say that this program uses a conditional command because the distance the robot moves forward is dependent on the condition of the touch sensor. If the touch sensor has not been pressed, the robot keeps moving forward. However, once the touch sensor has been pressed, the robot stops.

Day 1: Algorithms to Conditional Commands Presentation Outline (Slides 1-13)

  1. Administer the pre-quiz by handing out paper copies; the quiz is also on slide 2. The answers are provided for the teacher on slide 3 for discussion after students have completed the quiz.
  2. Talk about the lesson objectives, as provided on slide 4: To learn to use conditional commands. This involves investigating why it is helpful to use conditional commands in programming, and how to use wait blocks to program LEGO robots to respond to the presence of stimuli.
  3. Give each student a worksheet. Then present them with information on algorithms and conditional commands.
  4. (slides 5-7) Review what an algorithm is and why algorithms are important for programming. Using worksheet questions 1 and 2, have students perform the operation of "addition" shown on slide 5 and then write out the addition algorithm in generic, detailed steps (slide 6) so they understand the concept of algorithm. Then make sure students understand that the best algorithms are flexible and non-specific, so they can be used to solve many similar problems (slide 7).
  5. (slides 8-9) Explain that navigating a maze using the method of "calculating" distances (as students did in the first activity in this unit) can be problematic if the robot does not start exactly where it is supposed to start or if any calculation mistakes were made. Have students discuss this briefly and point out the limitations of programming by using movement blocks with fixed numbers of rotations.
  6. Have students answer worksheet question 3 to verify that they understand the issues involved if such a strategy is used, that is, if the robot is commanded to move based on exact distances. After they have completed question 3, have students share with the class all the issues they thought of and make sure everyone understands the potential problems. Then ask: How could we get around this?
  7. (slides 10-11) Introduce students to a new type of "conditional commands" that can help solve the problems identified in worksheet question 3: conditional statements using "until." Example: Play at recess until you hear the bell ring; then go back to class. See if students can apply this approach to a robot in a maze by asking them complete worksheet question 4. Ask them to write down in words an algorithm to have a robot move until it encounters a wall, when it is to stop. Check whether students have recorded the steps correctly: move forward continuously; stop if you sense a wall (maybe using a touch sensor). Emphasize that we want the algorithm to include simple and clear instructions that are also complete.
  8. To reinforce the concept of conditional commands and how they are easier to use than specific commands, conduct a simple maze demonstration using two student volunteers, as described on slide 12. Use tape on the floor to outline a simple track. Blindfold one student to serve as the "robot," and have the other student give the navigation commands, first using specific commands and then adding "until" into the instructions.
  9. (slide 13) As a class, discuss how the use of the conditional command made a difference, and then review all concepts covered during Day 1 on algorithms and conditional commands.

Day 2: Programming with Wait Blocks (Slides 14-17)

  • Before class starts, set up a simple LEGO robot maze using cardboard boxes or wooden blocks that is approximately 2-feet long with a turn to the left, refer to the slide 8 diagram.
  • (slide 14) Introduce a programming task that is best completed by using conditional commands to program the robot. Help students use the conditional commands and break the task down into simple steps: 1) move forward, 2) wait until the touch sensor is pressed, 3) stop.
  • Slides 14-18 provide a walkthrough for programming the robot to complete the task. Slide 16 is particularly important because it introduces the wait block and explains its features. Sum up the new information by reviewing how to use wait blocks (slide 19).
  • (slide 20) Have students pick up where they left off on the worksheet from Day 1, with questions 5 and 6. Direct students to write down conditional commands for the robot to navigate the maze diagram on the worksheet, and the EV3 program blocks to implement the algorithm. Give students some time to write their answers on their worksheets and then discuss as a class. Solutions are provided for the teacher on the Algorithm Worksheet Answer Key.
  • Give students pairs time to implement their programs using the LEGO MINDSTORMS EV3 software, download them to EV3 taskbots with attached touch sensors, and test/revise their programs.
  • Inform students that in the next class they will develop similar but more complex EV3 programs and test them on robots.
  • Administer the post-quiz by handing out paper copies; the quiz is also on slide 21. The answers are provided on slide 22. This concludes the lesson. Slide 23 contains vocabulary terms and definitions. Next, conduct the associated activity.


algorithm: A clear and specific procedure for solving a problem in a finite number of steps.

conditional command: A command in which the completion of an action depends on a condition being satisfied. (For example, if I see a stop sign [condition], I stop [action].)

stimulus: Something that rouses or incites to activity. For the purposes of the lesson, it is an action that can be perceived by the robot that causes it to move on to the next part of the program.

Associated Activities

  • Wait Program! - Students test their understanding of wait blocks in two programming challenges that use LEGO robot with sound and touch sensors. One task is to program a robot to keep moving forward and turn only when it hears the sound of a clap. The other programming task is more challenging and requires the robot to change speed several times depending on how many times the touch sensor is pressed. Students iterate their programs to successful solutions.



Pre-Lesson Assessment

Pre-Quiz: Before starting the lesson, administer the three-question How Do You Make a Program Wait? Pre/Post Quiz by handing out paper copies (also on slide 2). Students' answers reveal their base understanding of algorithms, stimulus and logic behind using sensors in programming a robot. Answers are provided on the How Do You Make a Program Wait? Pre/Post Quiz Answer Key (and slide 3). Administer the same quiz at lesson end.

Post-Introduction Assessment

Worksheet: Have students complete the Algorithm Worksheet over the two-session lesson, coordinated with the slide presentation. This helps students follow the content, and verifies their understanding as you go. The teacher should know the solution well (provided in the Algorithm Worksheets Answer Key) and ask pertinent questions to guide students.

Lesson Summary Assessment

Post-Quiz: At lesson end, administer the How Do You Make a Program Wait? Pre/Post Quiz again by handing out paper copies (also on slide 21). Compare students' answers to their pre-quiz answers to determine how well they understood the concepts taught in this lesson. Answers are provided on the How Do You Make a Program Wait? Pre/Post Quiz Answer Key (and slide 22).


Riaz Helfer, Pranit Samarth, Satish S. Nair


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

Supporting Program

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


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: November 17, 2017