Basic Programming


Name of Activity Basic Programming
Author Ali Boreiko
Keywords touch sensor, ultrasonic sensor, sound sensor, light sensor, simple programming, introduction to NXT, introduction to Mindstorms, introduction to programming
Subject NXTs
Grade Level 4, 5, 6, 7, 8
Time 1 Hour Total
Brief Description Students complete a simple series of programming challenges to familiarize themselves with Mindstorms programming.
Lesson Objectives: For students to become more competent programmers
Materials Needed: computers with Mindstorms, whiteboard/chalkboard, a list of simple challenges OPTIONAL: pre-built cars
Preparation and Set Up: 1. Decide what functions of the NXT will be most useful for your class. Do you want them to know how do use a particular sensor? How to steer the robot? How to make the NXT make noises? Then, create a list of ~8 challenges that target these areas of Mindstorm programming (see our example under “References”). Create the challenges so that harder challenges only require the students to change 1 or 2 parts of their program. That way they will see the direct connection between the change they made and the robot’s actions. They will also feel accomplished if they are able to complete more challenges.

2. You may have the students pre-build a car, but the activity can also be done by programming other things (e.g. an NXT arm)

  1. Ask each group to put the necessary sensor/equipment onto their robot.
  2. As a class, program the first challenge. As kids complete the challenge, have them come up to the board and demonstrate the challenge to either STOMPer. Once the students have accomplished and demonstrated the challenge, write their name on the board next to the challenge.
  3. Once kids have finished the first challenge, they may go on to harder challenges–but they must complete them in order!
  4. As kids complete the challenges, check off the challenges under their names. This way, you recognize kids who stay focused on the tasks.
Extensions: This activity can be adapted for various skill levels by simply making the challenges more difficult or adding more difficult ones at the end of the list
Previous Activity (if applicable) Introductory building
References Our list of touch sensor challenges
Umbrella Unit/Curriculum (if applicable) Introduciton to Mindstorms, Introduction to NXT Robotics

Same End, Two Ways of Getting There


Name of Activity Same End, Two Ways of Getting There.
Author Matt’s mini group
Keywords NXT, Ultrasonic sensor, light sensor, understanding how they work
Subject NXTs
Grade Level 4, 5
Time 2 Hours Total
Brief Description Understanding how sensors really work and use different sensors to accomplish the same goal.
Lesson Objectives: To understand how the ultrasonic sensor works. Use two sensors to accomplish same goal.
Materials Needed: Already built NXT car, bouncy ball to demonstrate ultrasonic sensor, flashlight maybe to demonstrate how the light sensor senses both reflected and ambient light and the difference between the two.
Preparation and Set Up: Already built car and a thorough understanding of how the sensors truly work.
Necessary Background Understand how the sensors are able to accurately sense whatever it is they sense.
Procedure In order to understand how untrasonic sensors work, children can throw a bouncy ball against a wall from different distances and see how it takes longer to come back to them when they are farther and less time when they are closer.  In order to understand how the light sensor works, they should pull up the real time reading of the light sensor on the brick and hold it up to different lightings and see how the reading changes and test how it is different when sensing reflection as opposed to ambient light and use these readings to set the threshold to put in the program.  A flashlight can also be held up to a piece of paper at different distances and see how the intensity changes.  The challenge will then be to have a car go back and forth between two walls using the ultrasonic sensor on one side and the light sensor on the other side.
Extensions: Use a different sensor as well to accomplish the same goal if a group is far ahead.
Previous Activity (if applicable) Basic programming knowledge and basic sensor usage.
Umbrella Unit/Curriculum (if applicable) NXT

NXT Trolly





Name of Activity NXT Trolly
Author Jay Clark
Keywords NXTs, cars, car, trolly, trollies, light sensor, loop, proximity sensor, sound sensor, threshold, switch
Subject NXTs
Grade Level 4, 5, 6, 7, 8, 9+
Time 2 Hours Total
Brief Description Students program their NXT cars to be trollies. The activity has three tasks.

(1) Using a light sensor, the trolly must follow the black tape loop that runs through the “town”

(2) Using a proximity sensor, the trolly must detect stations and stop for boarding.

(3) Using a sound sensor, the trolly must stop for townspeople whistling for the trolly.

Lesson Objectives: Programming with conditional loops and switches.
Determining and implementing multiple sensor thresholds.
Materials Needed: Pre-built NXT car and complete NXT kit.
Computers with Mindstorms NXT software.
Black tape for trolly track.
Boxes/Books/etc for trolly stations.
Extra LEGO people.
Preparation and Set Up: Set up a the trolly track with black tape in the classroom.
Place the trolly stations either all inside or all outside of the loop. (This is so the proximity sensor can be pointed to the right or left).
Necessary Background In order to follow a line, students will have to program their cars to repeatedly jump off and back on the line. In fact, they aren’t following the black line, but rather the line formed by the edge of the black tape and white floor. Students programs should consist of four blocks:
- Turn Right.
- Wait for Darker.
- Turn Left.
- Wait for Lighter.

Students will need to use a conditional loop or a switch to stop following the line at the station. A conditional loop will keep performing the line following functions until the distance threshold is breached. It will then move on to the next bit of code. A switch will make a decision about the program flow based on a sensor value.

Threshold – The sensor value that when breached, will trigger a wait for block or a conditional loop. (Some students have had a better time understanding it as a “benchmark”)

Switch – A program structure that makes a decision about which line of code to run next based on some criterion (time, sensor value, logic etc)

Procedure Introduction 10 minutes Review loops with the students and why they are useful in programs.

  • Loops allow us to repeat a set of commands that would otherwise be tedious to program over and over.

Sometimes loops should go on forever. Ask the students for examples they’ve done where loops go on forever. In more sophisticated programs, they should not. Ask if they can think of a situation in which you don’t want a program to go on forever. A conditional loop is a great way to end a loop exactly when you want it to end and move on to another task. Our brains use conditional loops all the time!

  •  When crossing the street, we look both ways. If its not safe, we do it again. We keep doing it until its safe, and then we cross the street.

Activity – 40 minutes If students haven’t done a line follower before, introduce the concepts using the line follower activity on the activities database. For the second task, students will have to use a conditional loop to look for the stations. After the loop, they should stop the car for 5 seconds. It’s important to note that you must drive past the station before you start looking for a new station. Therefore, there should be a loop with a counter on it, or another conditional loop to follow the line past the station before looking for the next one. For the third task, the students will have to use switches. First look at one of the sensors, say the sound sensor. If it detects a whistle, stop for five seconds, if not, look at the proximity sensor. If it detects a station, stop for five seconds. If not, continue following the line. Clean up/ Wrap up – 10 minutes

  • What was easiest? What was hardest?
  •  What would you have done differently?
  •  What were some good ideas you saw that other groups came up with?
Reference 1
Reference 2

NXT Segway





Name of Activity NXT Segway
Author Jay Clark
Keywords NXT, balance, wheels, sensors, wiring, math blocks, proportional controllers, light sensor
Subject NXTs
Grade Level 9+
Time 3 Hours Total
Brief Description Students build and program an NXT to balance on only two wheels using two light sensors.
Lesson Objectives: Master the use of wiring and math blocks
Master Building with NXT pieces
Introduce the concept of proportional controllers
Materials Needed: NXT kit plus one additional light sensor for each group.
Computers with LEGO Mindstorms installed.
Preparation and Set Up: Make sure this activity is done in an evenly lit room with a consistently-colored floor. Otherwise, it will not work.
Distribute extra light sensors to each group.
Necessary Background An NXT segway works by separating two light sensors about the center of gravity of the robot. If the robot loses its balance and starts to lean one way, one light sensor will receive more reflected light than the other. The differnce in these values can be scaled and then used to control the motors.

Generally, the following tips allow for the easiest construction of an NXT Segway:

The robot’s center of gravity should be such that the robot’s balancing point allows for the two light sensors to be evenly spaced off the ground.
The further the light sensors are from the robot, the more sensitive the response.
Weight should be added way above the pivot point (the wheels). Think about balancing a broom vs. balancing a watermelon.

Vocabulary: Proportional Controller – Control in which the amount of corrective action is proportional to the amount of error

Procedure Introduce students to the concept of proportional control. examples:

  • slowing down based on distance from stop sign
  • changing dial in shower based on error from desired temperature.

Introduce proportional control in the human brain in the form of keeping balance.

  • If you lean forward a little bit, your brain applies pressure to your toes to try to push your center of gravity back.
  • If you move to far forward, your brain will step forward.
  • If you are leaning way far forward, your brain will call for a very quick, large step.

The reaction is proportional to the error.   Introduce the segway activity. Now that we know how to balance an object that we know is leaning one way or another, we need to determine how we can figure out if the NXT is leaning. Ask students for suggestions. Encourage all ideas, but in the end, tell them that we’re going to use light sensors because they have the most consistent response and resolution. Activity If we mount the light sensors so they are the exact same distance off the ground when the robot is balanced, we can be sure that the light sensors will have the same reading. If the robot starts leaning, there will be a difference in the light sensor readings. We can use that difference to control the motors to balance the robot.Notes Students will have to experimentally determine their constant of proportionality. Because the power input of the move block converts negative numbers into positive numbers, there needs to be a comparison block to set the move block’s direction.

Reference 1
Reference 2

Find the Hidden Letter





Name of Activity Find the Hidden Letter
Author STOMP
Keywords 1 Hour Total, NXT, datalogging, hidden letter, alphabet, light sensor, data, 4-6, 7-9
Subject NXTs
Grade Level 4, 5, 6, 7, 8, 9+
Time 1 Hour Total
Brief Description Students will use the NXT/RCX datalogging feature to identify a hidden
letter of the alphabet using light sensor data.
Lesson Objectives: To program an NXT/RCX vehicle to collect data.
To analyze data and come up with a solution.
Materials Needed: NXT/RCX kits.
MINDSTORMS 2.0 with datalogging
capabilities orROBOLAB investigator.
Large print out of a letter of the alphabet.
Should cover a 8 1/2 by 11 sized paper.
Preparation and Set Up: Set up the hidden letter on the floor or on a table, but make sure that it cannot be seen.
Have pre-built NXT/RCX vehicles or allow students to construct their own.
Set up computer with MINDSTORMS 2.0 or ROBOLAB Investigator.
Necessary Background Datalogging is used to collect data from the sensors on the NXT vehicle.
This data an then be uploaded on to a computer an analyzed.
The light sensor will be used in this activity to collect information
about the color changes of the hidden letter.
  1. Attach a light sensor to your NXT/RCX car so that it is pointed at the floor. Wire this to port 1.
  2. Open the datalogging feature in MINDSTORMS 2.0, or open Investigator 2 in ROBOLAB.
  3. Program your vehicle to collect light data as it drives (see picture attached). You may need to adjust the power level depending on how fast your car drives over the hidden letter.
  4. Have the car drive across the letter at least 5 times in different places.
    1. This can be done by having your car drive across the letter one way three times, each time moving the car down a few inches, then doing the same thing but in a different orientation.
  5. Upload your data by clicking on the upload button of MINDSTORMS datalogging or in ROBOLAB investigator.
  6. Examine the data for peaks and valleys indicating light or dark areas. From these graphs have students try to decipher what letter the car drove over.
  7. Allow student to continue testing and then to guess what the hidden letter is.
  8. You may want to have a few hidden letters so that students can try this activity several times.
Extensions: Limit the number of times you allow a car to drive over a letter.

Add a second light sensor to collect more data.

Reference 1

Light Symphony





Name of Activity Light Symphony
Author STOMP
Keywords light sensor, NXT, tone, ambient light, loops, math blocks, sound, inputs, outputs, Engineering Design Process
Subject NXTs
Grade Level 4, 5, 6, 7, 8, 9+
Time 1 Hour Total
Brief Description In this activity, students will wire a light sensor to their NXT bricks. Light sensor data
will be collected and used in a program that plays a tone based on the ambient light
in the room.
Lesson Objectives: - To learn to program using the light sensor, loops, math blocks, and sound.
Materials Needed: - NXT brick.
- Light sensor.
- Computers running MINDSTORMS NXT software.
Preparation and Set Up: Set up computers with MINDSTORMS NXT Software.
Arrange students into groups of two.
Distribute necessary materials.
Necessary Background Vocabulary:
engineering design process
  1. Have students wire a light sensor to their NXT brick. They may or may not want to attach the light sensor to the brick.
  2. Have students program their NXT bricks
    1. The program should collect light sensor data
    2. The program should take this data and multiply it by a number (It may be good to start with about 10, but students can use trial and error until they find a multiple that creates the music box that they want)
    3. This new number should determine the tone of the note that the NXT brick plays.
    4. Students should add a wait for time block so that their note will play for that amount of before the program loops and the brick plays a new note.
  3. To test this program either have students turn their light sensors towards and away from a light source to produce different tones, or change the light levels in the room.
  4. Students may have to modify their program and change the multiple in their math block, or change the amount of time between notes. Allow students to test and retest multiple times.
Extensions: Get students to match the pitch of another NXT brick.
Modifications: - This same activity could be done using the proximity sensor attached to a car.
- Students could program their NXT brick to play a tone depending on how close their car was to an object. This could be related to a safety device that would warn you if your car was going to bump into a wall.
Reference 1
Reference 2
Reference 3

Light at the Beginning of the Tunnel





Name of Activity Light at the Beginning of the Tunnel
Author STOMP
Keywords NXT, car, light sensor, tunnel, drive, reverse, ambient light
Subject NXTs
Grade Level 4, 5, 6
Time 1 Hour Total
Brief Description In this activity, students will build or be provided with a pre-built NXT car with a light
sensor attached. Students will program their NXT car to drive into a tunnel and then
reverse out of the tunnel when the ambient light gets too dark. The car will stop when
the ambient light increases and the car is out of the tunnel.
Lesson Objectives: - To program light sensors according to the ambient light in the surrounding environment.
Materials Needed: - NXT Car.
- Light sensor.
- Tunnel.
- Computer running LEGO NXT software.
Preparation and Set Up: Set up computers running LEGO MINDSTORMS NXT Software.
Build a tunnel that is large enough for an NXT car to drive into.
Arrange students in pairs.
Distribute necessary materials.
Necessary Background This activity can be introduced as designing a safety feature for your car so that it does not drive into an unsafe, dark area.
  1. Have students build or provide a pre-built NXT car with a light sensor attached to the front of the car.
  2. Use MINDSTORMS NXT to program the NXT car.
    1. Check the ambient light value inside and outside the tunnel. To do this:
      1. Turn on the NXT and place it where you want to take your reading.
      2. Use the key pad to scroll over until you find the “View” option.
      3. Select the “View” option using the orange center button.
      4. Scroll over until you find “ambient light”and select “ambient light” using the orange center button.
      5. Scroll over to select the port that the light sensor is wired to. A percentage value should appear on your screen.
    2. Program your car to drive until it read a darker value a little bit above the reading that you got in the tunnel.
    3. Program your car to drive backwards until it reads a light value that is a little less than the ambient light value in the room.
    4. Test the cars. If the car does not respond as you wish, try changing the value that the light sensor is searching for.
Extensions or Modifications: Have students program their car to stay in the tunnel, this can be related to an animal who cannot leave its home in broad daylight without being eaten.
Reference 1
Reference 2
Reference 3

Solar System – ROVing Away





Name of Activity Solar System – ROVing Away
Author STOMP
Keywords Solar System, ROV, planet, beam, bricks, plates, axles, Solar Energy, Light Sensor
Subject and Grade Level NXT, K, 1, 2, 3
Time 1 Hour Total
Lesson Objectives: - Program a NXT ROV to travel from Earth to an assigned planet.
- Use this activity to learn about the solar system.
Materials Needed: - One pre-built NXT car for each pair of students.
- ‘Solar System’ that can be laid out on the floor, which shows all nine planets including earth. These can be marked off with tape, construction paper circles, etc.
- ‘ROVing Away’ activity worksheet.
- Planet fact cards set at each planet.
- Postcards from Pluto, by Loreen Leedy.
Preparation and Set Up: - Create ‘Solar System’ and planet facts.
- Lay out ‘Solar System’ and planet facts.
- Distribute NXT cars.
- Distribute activity worksheets.
- Break students into groups of 2.
- The teacher should do some research on each planet so that students can discuss the solar system after the activity. Wikipedia should have sufficient information on the solar system for this activity:
  1. (optional) Read Postcards from Pluto by Loreen Leedy to the class. This will serve as review and set up for the lesson.
  2. Divide students into groups and assign each group a planet (there may be repeats).
  3. Tell students to make an educated guess as to how long they think their trip might take from Earth to their assigned planet. Have students program their car to run for this amount of time and then stop.
  4. Tell students that since the planets are different distances from Earth, the time that each group programs into their NXT should be different.
  5. Tell students to reenter new times until their car stops exactly at the designated planet.
  6. Come together as a class and discuss the difficulties and successes that each group had.
  7. Have each student read their planet fact card to the class to facilitate discussion on the solar system.
Extensions or Modifications: - Use a light sensor to program the car when to stop.
- Program the NXT car to turn around and return to Earth.
- Program the NXT to turn and stop when it is facing the sun. The sun can be represented as a flashlight and the device used to make the NXT stop is the light sensor.
Sample Image 1
Sample Image 2
Sample Image 3

Line Follower






Name of Activity Line Follower
Author STOMP
Keywords car, light sensor, line, follow, loops, loop, ports
Subject and Grade Level NXTs, 4, 5, 6, 7, 8, 9+
Time 1 Hour Total
Lesson Objectives: - To learn to program using light sensors
- To learn to program using loops
- To practice building with an NXT kit
Materials Needed: - NXT Kit
- Solid colored floor or mat
- Tape that contrasts floor or mat
- Planning and Final Design Worksheets
- Computers running MINDSTORMS NXT-G Software
Preparation and Set Up: - Set up a line for students car to follow
- Set up computers running NXT software
- Photocopy worksheets
- Arrange students in groups of two
- Distribute necessary materials
  1. Have students plan out their design and program on paper before distributing materials. Help students think about the program by asking the following questions: How can the light sensor help you detect the line? What should happen when the car senses the line? What about when the light sensor detects the floor again? What is a loop? How will a loop be helpful in your program?
  2. Have students build cars using NXT-G kits, or provide a pre-built car to each group.
    1. The light sensor should be pointed at the ground.
    2. Make sure the car can easily turn by attaching a skid plate or attaching a swivel wheel to the front of the car.
    3. Attach the light sensor to the front of the car.
  3. Have students program their cars.
    1. The car should follow a line using a light sensor.
    2. Program one motor to turn until the light sensor detects the line.
    3. Use the “Wait for” block to use the light sensor data.
    4. When the light sensor detects the line, have the first motor stop and the other motor turn until the light sensor detects the floor, at which point the second motor will stop.
    5. Insert a loop around the program so that the car continually follows the line.
  4. Allow students to test their design on a tapeline on the floor.
  5. Tell students that they may redesign their car as this is an important step in the Engineering Design Process.
  6. When students have completed their cars have them fill out their final design sheets.
  7. Gather students together as a class and let each group share their car. Discuss the activity as a class.
Extensions or Modifications: - Create a theme for the project such as “rounding the bases” so that the students cars have to do more than just follow a line.
- Have a challenge at the end of the line. For example, at the end of the line there is a box that the NXT car must pick up. Students must design a robotic arm to lift the box.
Sample Image 1
Sample Image 2
Sample Image 3
Sample Image 4
Sample Image 5

Switch to our mobile site