Basic Programming

ACTIVITY HEADER

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)

Procedure
  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

NXT Trolly

ACTIVITY HEADER

 

 

 

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.

Vocabulary:
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 http://sites.tufts.edu/stompactivitydatabase/files/formidable/a1.jpg
Reference 2 http://sites.tufts.edu/stompactivitydatabase/files/formidable/b5.png

Freeze Dance

ACTIVITY HEADER

 

 

 

Name of Activity Freeze Dance
Author Jay Clark
Keywords program, NXT, robot, dance, conditional, loop, conditional loop, sound sensor
Subject NXTs
Grade Level 4, 5, 6, 7, 8, 9+
Time 1 Hour Total
Brief Description Students program their NXT robots to dance! But wait! Using conditional loop structures, they must program their robot to stop dancing when the music stops, and start again when the music is turned back on.
Lesson Objectives: Learning about the conditional loop
Building for non-car NXT movement
Determining and implementing sensor thresholds
Materials Needed: NXT kit including a sound sensor
A source and means of amplifying music
Computers with NXT Mindstorms software
Preparation and Set Up: Clear a space in the classroom to serve as the dance floor, and mark it off with black tape (for the extensions). Set up your music system and find a volume that will register a readable sound level in the NXT.
Necessary Background A loop is a helpful programming structure that allows you to repeat a set of commands. But sometimes, you don’t want to loop forever. A conditional loop will repeat the enclosed actions until some other criterion is met. A loop can be set to run for a certain amount of cycles of the loop, for a certain amount of time, until a logic condition is met, or until a sensor threshold is broken. This activity uses the last criterion in conjunction with the sound sensor to stop the robot from dancing.

Freeze dance is a game the children play in which they must dance when the music is on, but freeze when the music is turned off. If they don’t stop, or cannot hold the position they were in when the music stopped, they are eliminated.

Vocabulary:
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”)

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. (Simple tasks like line following, wall following). 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.

Remind the kids or introduce them to freeze dance, and introduce the Activity. Activity 40 minutes Students should construct robots for about 15 minutes and program for at least 25 minutes. After 40 minutes is done. Put all the robots on the dance floor and start and stop the music. Clean up 5 minutes Wrap up 5 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?
Extensions: Don’t bore us with those same old dance moves! Have the students’ robot switch up the dance moves after each pause.Programmatically, this involves an additional stop and a wait for sound block plus an additional looped dance sequence.

Allow students who finish quickly to explore the dance floor! have their robots move and groove while moving about the dance floor. Using their light sensor, they should detect that they’re about to leave the floor, and they should dance in a different direction. Programmatically, this would involve placing the dancing section of code in a switch or another conditional loop.

Don’t bump into other dancers! Using an ultrasonic distance sensor, detect fellow dancers and steer clear! Programmatically, this would involve placing the dancing section of code in a switch or another loop condition.

Modifications: Much of the programming could also be done with switches. Push for conditional loops if you want that to be the focus of the lesson.
Reference 1 http://sites.tufts.edu/stompactivitydatabase/files/formidable/b3.png
Reference 2 http://sites.tufts.edu/stompactivitydatabase/files/formidable/c.jpg

Rat Race

ACTIVITY HEADER

 

 

 

Name of Activity Rat Race
Author STOMP
Keywords NXT, 1 Hour Total, vehicle, car, obstacle, obstacle course, contrasting colors, sound, sound sensor, constraints
Subject NXTs
Grade Level 4, 5, 6, 7, 8, 9+
Time 1 Hour Total
Brief Description Students will program their NXT vehicles through an obstacle course. The instructor
should be creative in making an obstacle course. The obstacle course can include a
contrasting colored floor, narrow passages that force students to design a compact car,
sounds that require students to use sound sensor, and walls that cars need to avoid.
Lesson Objectives: To learn about programming in NXT.
Materials Needed: NXT kits.
Computers running LEGO MINDSTORMS.
Obstacle course, be creative in inventing a fun obstacle course for students to program and design their car to get through.
Preparation and Set Up: Set up an obstacle course, it can be very simple to complex depending of the level and experience of the students.
Necessary Background Vocabulary:
Constraints.
Procedure
  1. Introduce the activity and show the students the pre-built obstacle course so that they know what their car has to do.
  2. Have students build their cars using touch and light sensors. Remind students that their car must somehow break through the rope barrier at the end of the course.
  3. When students have finished building, have them program their cars to travel through the course.
    1. The cars must start at the start line.
    2. When the cars hit the black line, their cars should turn right.
    3. When the cars hit the wall, the cars should turn left.
    4. At the finish line, the cars must break through the tape.
  4. When students have finished programming allow them to test their cars, reprogram/rebuild if necessary and retest their cars.
Reference 1 http://sites.tufts.edu/stompactivitydatabase/files/formidable/ratrace.doc

Switch to our mobile site